foreach of classes

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 9 04:03:54 PDT 2016


On Saturday, 9 April 2016 at 10:56:34 UTC, Lucien wrote:
> On Saturday, 9 April 2016 at 10:28:05 UTC, Basile B. wrote:
>> On Saturday, 9 April 2016 at 10:10:19 UTC, Lucien wrote:
>>> Hello.
>>>
>>> When I do:
>>>
>>> ---------------------
>>> class MyClass{..}
>>> class YourClass{..}
>>> class OurClass{..}
>>>
>>> YourClass yc = new YourClass();
>>>
>>> foreach (auto id; [ typeid(MyClass), typeid(YourClass), 
>>> typeid(OurClass) ])
>>> {
>>>   if (typeid(yc) == id)
>>>   {
>>>     writeln("It works !");
>>>   }
>>> }
>>> ---------------------
>>> The compiler says: basic type expected, not auto
>>> Why can't I have one time the type id of MyClass, then of 
>>> YourClass and of OurClass ?
>>> Is there an alternative ?
>>
>> remove auto and optionally replaces it with TypeInfo_Class.
>
> So simple ?! o.o
>
> Thanks !

FYI the things that you can put there (in place of auto) are 
nothing at all (type is inferred, a type, ref (the foreach 
variable is taken by reference), const/immutable (the variable is 
const or immutable).



More information about the Digitalmars-d-learn mailing list