Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-24 Thread David T. Oxygen via Digitalmars-d-learn
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); }el

Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-24 Thread David T. Oxygen via Digitalmars-d-learn
On Sunday, 24 August 2025 at 08:25:56 UTC, H. S. Teoh wrote: On Sun, Aug 24, 2025 at 05:20:06AM +, David T. Oxygen via Digitalmars-d-learn wrote: [...] But I still don't know how to use `is` `__traits`. [...] Operations involving types, such as type comparisons, are usually done

Re: foreach vs static foreach on compile time tuples

2025-08-24 Thread David T. Oxygen via Digitalmars-d-learn
On Sunday, 24 August 2025 at 08:35:57 UTC, Per Nordlöw wrote: Which are the pros and cons of foreach vs static foreach on a compile time tuple in D in terms of compiler performance and resource usage? Does static foreach generate more ast duplications? -- Yes, it will make the compile-time lo

Re: What's the use of 'typeof','typeid','__traits','is' ?

2025-08-23 Thread David T. Oxygen via Digitalmars-d-learn
On Sunday, 24 August 2025 at 03:29:30 UTC, Paul Backus wrote: On Sunday, 24 August 2025 at 03:13:38 UTC, David T. Oxygen wrote: Hello every kind and helpful D programmers, I need your help. I've met two problems about getting types. In D, we can use many keywords to get the type of an object,

What's the use of 'typeof','typeid','__traits','is' ?

2025-08-23 Thread David T. Oxygen via Digitalmars-d-learn
Hello every kind and helpful D programmers, I need your help. I've met two problems about getting types. In D, we can use many keywords to get the type of an object, such as `typeof`,`typeid`,`is`. However, I don't know the differences between them well. I also don't know how to use them in D..

Re: Class-Inheritancing Error

2025-07-28 Thread David T. Oxygen via Digitalmars-d-learn
On Monday, 28 July 2025 at 18:02:45 UTC, H. S. Teoh wrote: On Sun, Jul 27, 2025 at 05:02:35PM +, user1234 via Digitalmars-d-learn wrote: [...] Simply because because if OP writes ``` class Person{ string name; this(string name){this.name=name;} } class Someone:Person{ } void main(){

Class-Inheritancing Error

2025-07-27 Thread David T. Oxygen via Digitalmars-d-learn
I wrote a piece of code like this: ```d class Person{ string name; this(string name){this.name=name;} } class Someone:Person{ alias super this; } void main(){ Someone x=new Someone("Bob"); } ``` And then,I got a Error-Message: ``` ab.d(6): Error: variable name expe