function argument restrictions for templated struct

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 7 08:51:28 PDT 2015


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;
}


More information about the Digitalmars-d-learn mailing list