How to check for instantiation of specific template?
simendsjo
simendsjo at gmail.com
Thu Oct 10 13:07:46 PDT 2013
On Thursday, 10 October 2013 at 17:24:37 UTC, H. S. Teoh wrote:
> I have a template used for storing compile-time values:
>
> template Def(int x, string y) {
> alias impl = TypeTuple!(x,y);
> }
>
> How do I define a template isDef that, given some template
> alias A,
> evaluates to true if A is some instantiation of Def?
>
> template isDef(alias A) {
> enum A = ... /* what to put here? */
> }
>
> The intent is to be able to write signature constraints like
> this:
>
> auto myFunc(alias def)(...)
> if (isDef!def)
> {
> ...
> }
>
> ...
> // Pass an instantiation of Def to myFunc
> auto x = myFunc!(Def!(1, "abc"))(args);
>
> I tried using std.traits.isInstanceOf but apparently it expects
> the
> second argument to be an actual type, which doesn't work in
> this case
> because Def is a typetuple of compile-time values, not an
> actual type.
>
>
> T
I've used this horrible hack to solve this. Not very generic as
you can see:
else static if(T.stringof.length > 13 && T.stringof[0..13] ==
"TupleWrapper!")
More information about the Digitalmars-d-learn
mailing list