Pass type directly to a template function?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Feb 7 21:59:08 PST 2017


On 02/07/2017 01:17 AM, Chris Katko wrote:

> void function3(T)(T) //hypothetical, specify the datatype in the
> argument list
>     {
>     T data;
>     }

Related:

   https://dlang.org/library/object/type_info.html

and

   https://dlang.org/library/object/object.factory.html

This compiles but I'm not sure how to use it effectively:

import std.stdio;

auto function3(TypeInfo ti)
{
     return ti.initializer();
}

void main()
{
     writeln(function3(typeid(float)));
     writeln(function3(typeid(double)));
}

Ali



More information about the Digitalmars-d-learn mailing list