Is there Typeof template ?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 28 11:25:02 PDT 2016


On Friday, October 28, 2016 11:19:46 Ali Çehreli via Digitalmars-d-learn 
wrote:
> 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; /* ... */

I don't know if Typeof is actually needed for what the OP is trying to do,
but if you wanted to apply typeof using something like std.meta.staticMap,
then you'd need something like Typeof.

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list