digitalmars.D.learn - function argument restrictions for templated struct
- Laeeth Isharc (25/25) Sep 07 2015 Hi.
- anonymous (3/10) Sep 07 2015 if (isInstanceOf!(Bar, T))
- Laeeth Isharc (2/12) Sep 07 2015 Thanks !
Hi.
Is there a more elegant way to write the template arg
restrictions for display?
Thanks.
Laeeth
import std.stdio;
import std.traits;
struct Bar(bool test)
{
double a;
static if(test)
double b;
}
void display(T)(T a)
if (__traits(isSame, TemplateOf!(T), Bar))
{
writefln("%s",a);
}
void main(string[] args)
{
auto a=Bar!false(1.0);
auto b=Bar!true(1.0,2.0);
a.display;
b.display;
}
Sep 07 2015
On Monday 07 September 2015 17:51, Laeeth Isharc wrote:Is there a more elegant way to write the template arg restrictions for display?[...]void display(T)(T a) if (__traits(isSame, TemplateOf!(T), Bar)) { writefln("%s",a); }if (isInstanceOf!(Bar, T))
Sep 07 2015
On Monday, 7 September 2015 at 16:27:21 UTC, anonymous wrote:On Monday 07 September 2015 17:51, Laeeth Isharc wrote:Thanks !Is there a more elegant way to write the template arg restrictions for display?[...]void display(T)(T a) if (__traits(isSame, TemplateOf!(T), Bar)) { writefln("%s",a); }if (isInstanceOf!(Bar, T))
Sep 07 2015








"Laeeth Isharc" <laeethnospam nospam.laeeth.com>