Is there Typeof template ?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 28 11:19:46 PDT 2016


On 10/28/2016 05:48 AM, Temtaime wrote:
> On Friday, 28 October 2016 at 12:44:20 UTC, Adam D. Ruppe wrote:
>> On Friday, 28 October 2016 at 10:52:05 UTC, Temtaime wrote:
>>> Are there something or should I create a PR to phobos?
>>
>> Why would you want that?
>
> I have UDAs with values à la @(`str`, 123) uint k;
>
> And i want to know a type of a value.

How are you using those? typeof works with any value:

void main() {
     @(`str`, 123) uint k;
     foreach (a; __traits(getAttributes, k)) {
         pragma(msg, typeof(a));
     }
}

Prints

string
int

You can use indexes with the loop as well:

     foreach (i, a; /* ... */

Ali



More information about the Digitalmars-d-learn mailing list