Magic type return

2012-07-17 Thread Andrea Fontana
class Known { void* data; // external data by c api int type; // 0 for int, 1 for string, etc. .. } How can I implement a method like this? Known known; // <-- suppose known.type == 1; string s = known.value(); // <-- automatic I just know how to do this: string s = know.

Re: Magic type return

2012-07-17 Thread Tobias Pankrath
On Tuesday, 17 July 2012 at 13:56:29 UTC, Andrea Fontana wrote: class Known { void* data; // external data by c api int type; // 0 for int, 1 for string, etc. .. } How can I implement a method like this? Known known; // <-- suppose known.type == 1; string s = known.value()

Re: Magic type return

2012-07-17 Thread bearophile
Andrea Fontana: class Known { void* data; // external data by c api int type; // 0 for int, 1 for string, etc. .. } How can I implement a method like this? Known known; // <-- suppose known.type == 1; string s = known.value(); // <-- automatic To do this Known.value() n

Re: Magic type return

2012-07-17 Thread Andrea Fontana
Better than nothing :) Hope in better template deduction... Il giorno mar, 17/07/2012 alle 16.22 +0200, Tobias Pankrath ha scritto: > On Tuesday, 17 July 2012 at 13:56:29 UTC, Andrea Fontana wrote: > > class Known > > { > > void* data; // external data by c api > > int type; //

Re: Magic type return

2012-07-17 Thread Mirko Pilger
i'm not completely sure i understand your problem but i think you are looking for something like this: http://pocoproject.org/docs/Poco.DynamicAny.html maybe the c++ source code could be of some inspiration. this should be possible in d, too.

Re: Magic type return

2012-07-18 Thread Philippe Sigaud
> class Known > { > void* data; // external data by c api > int type; // 0 for int, 1 for string, etc. .. > } > > How can I implement a method like this? > > Known known; // <-- suppose known.type == 1; > string s = known.value(); // <-- automatic > > I just know how to do thi

Re: Magic type return

2012-07-18 Thread Andrea Fontana
Yes I did it using Variant and it works fine Il giorno mer, 18/07/2012 alle 16.42 +0200, Philippe Sigaud ha scritto: > > class Known > > { > > void* data; // external data by c api > > int type; // 0 for int, 1 for string, etc. .. > > } > > > > How can I implement a method like

Re: Magic type return

2012-07-18 Thread Regan Heath
On Tue, 17 Jul 2012 15:23:05 +0100, bearophile wrote: Andrea Fontana: class Known { void* data; // external data by c api int type; // 0 for int, 1 for string, etc. .. } How can I implement a method like this? Known known; // <-- suppose known.type == 1; string s = k

Re: Magic type return

2012-07-19 Thread Andrea Fontana
Or template inference based on return type like T hello(T)() { static if (is(T ==)) } string v = hello(); Il giorno mer, 18/07/2012 alle 17.38 +0100, Regan Heath ha scritto: > On Tue, 17 Jul 2012 15:23:05 +0100, bearophile > wrote: > > > Andrea Fontana: > > > >> class Known > >> {