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
Re: Proposal: Database Engine for D
On Monday, 4 January 2016 at 17:36:20 UTC, Piotrek wrote: Thanks! So at least one more soul believing that D can approach the SQL expressiveness in db domain. Cheers Piotrek Some time ago I had the same idea as yours. IMHO, no D to SQL is really needed for this, and the same goes for relational databases. My idea was to initially build a DB as library, using graph databases as starting point, where the metadata is defined only one time in the code. The query methods must allow easy access not only to the data, but also to the relations defined from object to object. As a starting point you must be able to do something like this: // Stores are where the data is saved auto localStore = FileStore!Endian.littleEndian( "some_file_name" ); // Local file // load() and save() on objects of type User uses this store. User.setDefaultStore( localStore ); User user = new User(); user.name = "John"; user.password = sha1( "password" ); // Uses the default store auto localId = user.save(); // Uses the store specified as argument auto otherId = user.save( someOtherStore ); // load the object from the default store User localUser = User.load( localId ); // load the object from the network store User otherUser = User.load( someOtherStore, otherId ); // Ideally users where the last login is older than one year using the networkStore auto oldUsers = User.all( someOtherStore ) .filterUsing!(User.lastLogin, (lastLogin) => lastLogin < ( now - 1.year ) ); // Select the first user that match userName and hashedPassword in the default store, with a challenge-response login auto loginUser = User.all. .filterUsing!(User.name, (name) => name == userName ) .filterUsing!(User.password, (pass) => hmac( pass, key ) == hashedPassword ) .onlyOne(); Gianni Pisetta
Unions and CTFE
Hi all, i'm coding a parametrized crc implementation that can support most of the standards. I want to make it work with CTFE and i stumbled upon a difficulty when using std.bitmanip.nativeToLittleEndian and std.bitmanip.nativeToBigEndian. The code below is the concept used by EndianSwapper and it does not compile because of unions and CTFE. Also as the error message is very obscure, is it intended behaviour or a bug? module testunionctfe; import std.traits; auto f(T)(T data) { union DataBytes { Unqual!T data; ubyte[T.sizeof] bytes; }; DataBytes tmp; tmp.data = data; return tmp.bytes; } void main(){ auto a = f( 0x01020304 ); enum b = f( 0x01020304 ); //testunionctfe.d(18): Error: uninitialized variable 'data' cannot be returned from CTFE assert( a == b ); } If it is intended behaviour, i think i come up with an alternative implementation for these two functions with shifts and masks to be used only in ctfe(union implementation is faster) when the type is uint and ushort(and maybe ulong), that i will prepare in a pull request. Otherwise if it is a bug i will file a bugreport instead.
Re: Unions and CTFE
On Friday, 18 December 2015 at 17:21:39 UTC, Jimmy Cao wrote: On Friday, 18 December 2015 at 14:30:25 UTC, Gianni Pisetta wrote: Hi all, i'm coding a parametrized crc implementation that can support most of the standards. I want to make it work with CTFE and i stumbled upon a difficulty when using std.bitmanip.nativeToLittleEndian and std.bitmanip.nativeToBigEndian. The code below is the concept used by EndianSwapper and it does not compile because of unions and CTFE. Also as the error message is very obscure, is it intended behaviour or a bug? I think it's intended behavior. According to http://dlang.org/changelog/2.065.0.html#ctfe-overlapped-field "Bit image reinterpretation by using two overlapped union fields is not allowed during CTFE." Yeah, i supposed it. But the error message was misleading, because 'data' is initialized and 'bytes' is the actual uninitialized part. I guess the error message can be improved. Anyway thanks