Dealing with type information loss in Parameters Fields and Return type

Anonymouse via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Apr 17 03:22:00 PDT 2016


On Sunday, 17 April 2016 at 10:12:29 UTC, Nicholas Wilson wrote:
> So currently there is a loss of information when Parameters 
> Fields and Return type.
> i.e. assuming 64 bits
> size_t foo(ptrdiff_t) {};
>
> writeln(ReturnType!foo); // prints ulong
>
> Is there any way to get the types as (tuples of) strings of the 
> the types as they are in the source file?
>
> auto foos = StringReturnType!foo;
> static assert(typeof(foos) == string);
> pramga(msg, foos); // available at CT, prints size_t

Correct me if I'm wrong but size_t is just an alias of ulong 
(assuming 64 bits), so they're the exact same thing. A rose by 
any other name etc.

> size_t is an alias to one of the unsigned integral basic types, 
> and represents a type that is large enough to represent an 
> offset into all addressible memory.
> ptrdiff_t is an alias to the signed basic type the same size as 
> size_t.


More information about the Digitalmars-d-learn mailing list