What's the use of 'typeof','typeid','__traits','is' ?
David T. Oxygen
TKC847567 at outlook.com
Mon Aug 25 04:00:37 UTC 2025
On Sunday, 24 August 2025 at 14:40:36 UTC, Steven Schveighoffer
wrote:
> ```d
> // solution 1: (preferred)
> if(auto r = cast(MyInt)result){
> writeln(r);
> }else if(auto r = cast(MyFloat)result){
> writeln(r);
> }
>
> // solution 2:
> if(typeid(result) is typeid(MyInt)){
> writeln(cast(MyInt)result);
> }else{
> writeln(cast(MyFloat)result);
> }
> ```
--
Thank you. I've tried solution1. It can work well.
More information about the Digitalmars-d-learn
mailing list