Tuple/Typedef question

2015-01-11 Thread Martin via Digitalmars-d-learn
Is there a way to get Tuple (and Typedef) from the std.typecons module to generate a new type that is unique on every instantiation? What I mean is: alias T1 = Tuple!(int, int); alias T2 = Tuple!(int, int); writeln(__traits(isSame, T1, T2)); // prints true When using Typedef, the types are

Re: Tuple/Typedef question

2015-01-11 Thread ketmar via Digitalmars-d-learn
On Sun, 11 Jan 2015 11:41:08 + Martin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is there a way to get Tuple (and Typedef) from the std.typecons module to generate a new type that is unique on every instantiation? What I mean is: alias T1 = Tuple!(int, int); alias

Re: Tuple/Typedef question

2015-01-11 Thread Dicebot via Digitalmars-d-learn
I use this Typedef implementation instead: /// one with non-default initializer template Typedef(T, istring name, T initval) { static assert (name.length, Can't create Typedef with an empty identifier); enum Typedef = (struct ~ name ~ { ~

Re: Tuple/Typedef question

2015-01-11 Thread Martin via Digitalmars-d-learn
On Sunday, 11 January 2015 at 11:52:42 UTC, ketmar via Digitalmars-d-learn wrote: On Sun, 11 Jan 2015 11:41:08 + Martin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Is there a way to get Tuple (and Typedef) from the std.typecons module to generate a new type that is

Re: Tuple/Typedef question

2015-01-11 Thread ketmar via Digitalmars-d-learn
On Sun, 11 Jan 2015 12:00:19 + Martin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: as for `Typedef!` -- you can use it's third arg, cookie: import std.typecons; alias T1 = Tuple!(int, int); alias T2 = Tuple!(int, int); alias T1New = Typedef!(T1,

How to interface with C++ code or dll?

2015-01-11 Thread Suliman via Digitalmars-d-learn
I am trying to understand how to use C++ lib from D. For my App I need http://www.gdal.org I had read about using C++ libs from D, and understood that there is 2 ways: 1. Make binding - convert .H to .d (I still do not fully understand what is it) 2. Use directly C++ lib (.dll) I decided to

Sqlite

2015-01-11 Thread Paul via Digitalmars-d-learn
Can someone please tell me what I'm doing wrong here, the sql INSERT statement fails for some reason. I don't fully understand the callback function yet (I borrowed this from a C tutorial on the subject), maybe that is the source of the problem? import etc.c.sqlite3; import std.stdio;

Re: Build all combinations of strings

2015-01-11 Thread Nordlöw
On Monday, 11 June 2012 at 19:52:38 UTC, bearophile wrote: Using that the code is: import std.string, std.stdio, std.array; void main() { auto words = foo bar doo.split(); auto res = permutations!false(words).map!(p = p.join( ))().array(); writeln(res); } Is doCopy really needed

Re: Build all combinations of strings

2015-01-11 Thread bearophile via Digitalmars-d-learn
Nordlöw: Is doCopy really needed as an argument here? Couldn't this be inferred from the mutability of T instead? doCopy is useful, if it's true all the permutation arrays are distinct and dup-ped, otherwise they are all different. It's true by default, so casual users of that generator

Re: Sqlite

2015-01-11 Thread ketmar via Digitalmars-d-learn
On Sun, 11 Jan 2015 20:00:03 + Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Can someone please tell me what I'm doing wrong here, the sql INSERT statement fails for some reason. I don't fully understand the callback function yet (I borrowed this from a C tutorial

Re: Sqlite

2015-01-11 Thread Paul via Digitalmars-d-learn
On Sunday, 11 January 2015 at 20:20:21 UTC, ketmar via Digitalmars-d-learn wrote: note the single quotes in your code: that is where it all goes wrong. i don't know where you got that quotes from, but this is not a valid SQL syntax for `CREATE TABLE`. ;-) Thank you, I thought it might be

Re: Build all combinations of strings

2015-01-11 Thread Nordlöw
On Sunday, 11 January 2015 at 18:01:09 UTC, bearophile wrote: Nordlöw: Is doCopy really needed as an argument here? Couldn't this be inferred from the mutability of T instead? doCopy is useful, if it's true all the permutation arrays are distinct and dup-ped, otherwise they are all

Re: Build all combinations of strings

2015-01-11 Thread Nordlöw
On Sunday, 11 January 2015 at 18:01:09 UTC, bearophile wrote: Is doCopy really needed as an argument here? Couldn't this be inferred from the mutability of T instead? doCopy is useful, if it's true all the permutation arrays are distinct and dup-ped, otherwise they are all different. It's

Re: Build all combinations of strings

2015-01-11 Thread bearophile via Digitalmars-d-learn
Nordlöw: Couldn't we do a first pass and check that if elements of T are distinct and if so set doCopy to false otherwise true? The algorithm you have seen in Rosettacode doesn't care if and what items of the input sequence are duplicated, it handles them as they are all distinct. And them

Re: Sqlite

2015-01-11 Thread Tobias Pankrath via Digitalmars-d-learn
On Sunday, 11 January 2015 at 20:30:41 UTC, Paul wrote: On Sunday, 11 January 2015 at 20:20:21 UTC, ketmar via Digitalmars-d-learn wrote: note the single quotes in your code: that is where it all goes wrong. i don't know where you got that quotes from, but this is not a valid SQL syntax for

Re: How to interface with C++ code or dll?

2015-01-11 Thread Mike Parker via Digitalmars-d-learn
On Sunday, 11 January 2015 at 12:56:40 UTC, Suliman wrote: I had read about using C++ libs from D, and understood that there is 2 ways: 1. Make binding - convert .H to .d (I still do not fully understand what is it) 2. Use directly C++ lib (.dll) No, there are not two ways. There is one

Re: Sqlite

2015-01-11 Thread Paul via Digitalmars-d-learn
On Sunday, 11 January 2015 at 22:19:28 UTC, Tobias Pankrath wrote: Hint: Put the SQL in a file create_people.sql and import it into your code via the import statement: string sql = import(create_people.sql); // you'll need a correct -J compiler switch That way you can easily test if it's

Re: endsWith - for a string vs an array of strings

2015-01-11 Thread Mengu via Digitalmars-d-learn
On Saturday, 10 January 2015 at 23:32:47 UTC, bearophile wrote: Laeeth Isharc: In D there is a feature that allows a function to accept both an array of items and items, yes - it is funny there is not an overloading that accepts arrays I meant this D feature: void foo(T)(T[] items...) {