Re: check instance of nested variadic template
When i have time i will test it with ldc and see if the result is the same, then it will probably be a front-end bug and i will report it as an issue.
Re: check instance of nested variadic template
On Friday, 4 November 2016 at 17:37:10 UTC, Basile B. wrote: Hello, I'm not sure that's exactly what you want but check this: template A(As...) { template B(Bs...) { } } alias BI = A!(1,2).B!(3,4,5); import std.traits; template NestedTemplateArgsOf(alias T) { alias NestedTemplateArgsOf = TemplateArgsOf!(__traits(parent, T)); } alias Bs = TemplateArgsOf!BI; alias As = NestedTemplateArgsOf!BI; static if (is(typeof(BI) == typeof(A!As.B!Bs))) { pragma(msg, "for the win"); } The missing key was NestedTemplateArgsOf. With it you can solve the problem. Well, kind of. But i think i can make it with what i got from your example, so thanks. Another thing that I encountered and while messing with your code is that __traits( parent, T ) does not work as expected when you have structs instead of template. I think because something like struct A(As...) {} is downgraded to template A(As...) { struct A {} } when i use __traits( parent, A!(1,2) ) i get in return A!(1,2), looping around the same symbol. When you compile this struct A(As...) {} import std.conv; pragma( msg, "The parent symbol is the same? " ~ to!string( __traits( isSame, A!(1,2), __traits( parent, A!(1,2) ) ) ) ); void main() {} you get a really interesting result: The parent symbol is the same? true Gianni Pisetta
check instance of nested variadic template
Hi all, I am having issues finding a solution for this, i want to check if an alias is an istance of a variadic template nested in another variadic template. Here is an example: template A(As...) { template B(Bs...) { } } alias BI = A!(1,2).B!(3,4,5); Now i want to test if BI is an istance of A.B, but i can't do something like this: static if ( is( BI == A!As.B!Bs, As..., Bs... ) ) { // Do Something } there is some sort of workaround? Thanks, Gianni
Re: test if the alias of a template is a literal
On Friday, 28 October 2016 at 03:33:33 UTC, Basile B. wrote: Hello, I think the correct isStringLiteral would be: import std.meta; template isStringLiteral(alias V) { enum isCompileTime = is(typeof((){enum a = V;})); enum isString = is(typeof(V) == string); enum isStringLiteral = isCompileTime && isString; } It works, Thanks. Also, i don't think in my case there is the need for a variant for types( aka isStringLiteral(V) without alias) because it's an error to pass a type to Optimize in first place. But for a general purpouse library, maybe a template isLiteral(alias V) that only checks if it is a literal without the type checking, would have more sense to have also isLiteral(V) for types that returns always false. Gianni Pisetta
Re: test if the alias of a template is a literal
On Thursday, 27 October 2016 at 14:34:38 UTC, TheFlyingFiddle wrote: On Thursday, 27 October 2016 at 14:04:23 UTC, Gianni Pisetta wrote: Hi all, but at the moment isStringLiteral will return true even with variables of type string. So i searched for a metod to check if an alias is a literal value, but found nothing. Anyone have any clue on how can be done? Thanks, Gianni Pisetta Not really understanding your problem. Could you include an example use that is problematic? Yea, sorry I missed that. A really stupid example would be string var; alias Sequence = Optimize!( "The", " ", "value", " ", "of", " ", "var is ", var ); static assert( is( Sequence == AliasSeq!( "The value of var is ", var ) ) ); writeln( Sequence ); given that you include the code snippet in the first post. Thanks, Gianni
test if the alias of a template is a literal
Hi all, I have an AliasSeq composed of literal strings, variables and delegates. I want to build a template Optimize that will return an AliasSeq that have all adjacent literals concatenated into one. So i writed something like this: template isStringLiteral(alias V) { enum bool isStringLiteral = ( is( typeof( V ) == string ) ); } template Optimize(Os...) { static if ( Os.length < 2 ) alias Optimize = Os; else { alias Optimized = Optimize!(Os[1..$]); static if ( isStringLiteral!(Os[0]) && isStringLiteral!(Optimized[0]) ) { enum string First = Os[0] ~ Optimized[0]; alias Rest = Optimized[1..$]; } else { alias First = AliasSeq!(Os[0]); alias Rest = Optimized; } alias Optimize = AliasSeq!(First, Rest); } } but at the moment isStringLiteral will return true even with variables of type string. So i searched for a metod to check if an alias is a literal value, but found nothing. Anyone have any clue on how can be done? Thanks, Gianni Pisetta