constraint on variadic template

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 7 09:32:14 PST 2016


On Wednesday, 7 December 2016 at 17:05:11 UTC, H. S. Teoh wrote:
> Try this:
>
> 	import std.meta : allSatisfy;
>
> 	enum hasRun(T) = __traits(hasMember, T, "run");
>
> 	mixin template S(T...)
> 	    if (allSatisfy!(hasRun, T))
> 	{
> 	    void run()
> 	    {
> 		foreach(s; T)
> 		{
> 		    static assert(__traits(hasMember, s, "run"));
> 		}
> 	    }
> 	}

This is strange... I expect this to work... but it does not...

meta.d(762,27): Error: template instance F!(rFS) does not match 
template declaration hasRun(T)
meta.d(767,13): Error: template instance 
std.meta.allSatisfy!(hasRun, rFS) error instantiating
test176.d(70,27): instantiated from here: allSatisfy!(hasRun, 
rFS, rAS)


More information about the Digitalmars-d-learn mailing list