Re: Type polymorphism and type variance

2012-12-04 Thread Ali Çehreli
On 12/04/2012 06:42 PM, js.mdnq wrote: > One thing I've always struggled with in oop is how to deal with > storing generic types. > > A very simple example is, suppose you had to design a way to > store generic types. > > class myGtype(T) { } > > ... > > myGType[] gcollection; // should store vari

Re: MS ODBC encoding issue

2012-12-04 Thread Sam Hu
On Tuesday, 4 December 2012 at 10:05:16 UTC, Nathan M. Swan wrote: I've never used ODBC before, but a quick scan of the MSDN docs suggests that you should use SQL_C_WCHAR instead, maybe using some D wstring functions too. BTW, convert sql.ptr -> std.string.toStringz(sql); this is good pract

Re: MS ODBC encoding issue

2012-12-04 Thread Sam Hu
On Tuesday, 4 December 2012 at 10:05:16 UTC, Nathan M. Swan wrote: I've never used ODBC before, but a quick scan of the MSDN docs suggests that you should use SQL_C_WCHAR instead, maybe using some D wstring functions too. BTW, convert sql.ptr -> std.string.toStringz(sql); this is good pract

Re: Template return values?

2012-12-04 Thread Era Scarecrow
On Tuesday, 4 December 2012 at 17:43:21 UTC, Dmitry Olshansky wrote: Well TDPL claims multiple alias this is allowed so in some distant future it maybe possible for Varaint to alias this to all built-in types. Maybe I remember back when I was originally reading about C++ and overloadin

Type polymorphism and type variance

2012-12-04 Thread js.mdnq
One thing I've always struggled with in oop is how to deal with storing generic types. A very simple example is, suppose you had to design a way to store generic types. class myGtype(T) { } ... myGType[] gcollection; // should store various types such as myGtype!int, myGtype!myobj, etc.., pos

Type polymorphism and type variance

2012-12-04 Thread js.mdnq
One thing I've always struggled with in oop is how to deal with storing generic types. A very simple example is, suppose you had to design a way to store generic types. class myGtype(T) { } ... myGType[] gcollection; // should store various types such as myGtype!int, myGtype!myobj, etc.., pos

Type polymorphism and type variance

2012-12-04 Thread js.mdnq
One thing I've always struggled with in oop is how to deal with storing generic types. A very simple example is, suppose you had to design a way to store generic types. class myGtype(T) { } ... myGType[] gcollection; // should store various types such as myGtype!int, myGtype!myobj, etc..,

Type polymorphism and type variance

2012-12-04 Thread js.mdnq
One thing I've always struggled with in oop is how to deal with storing generic types. A very simple example is, suppose you had to design a way to store generic types. class myGtype(T) { } ... myGType[] gcollection; // should store various types such as myGtype!int, myGtype!myobj, etc.., pos

Re: Template return values?

2012-12-04 Thread Jonathan M Davis
On Tuesday, December 04, 2012 23:28:25 Dmitry Olshansky wrote: > 12/4/2012 10:40 PM, Jonathan M Davis пишет: > > On Tuesday, December 04, 2012 21:43:09 Dmitry Olshansky wrote: > >> Well TDPL claims multiple alias this is allowed so in some distant > >> future it maybe possible for Varaint to alias

Re: How to import modules?

2012-12-04 Thread Mike Parker
On Tuesday, 4 December 2012 at 16:53:33 UTC, js.mdnq wrote: Thanks, I simply imported the modules into the project and I guess visual D added them to be compiled in on the command line. For now this will work fine. Maybe eventually I'll write a utility that will build up a command line to in

Re: Template return values?

2012-12-04 Thread Era Scarecrow
On Tuesday, 4 December 2012 at 17:43:21 UTC, Dmitry Olshansky wrote: Well TDPL claims multiple alias this is allowed so in some distant future it maybe possible for Varaint to alias this to all built-in types. Maybe I remember back when I was originally reading about C++ and overloadin

Re: opEquals for same type

2012-12-04 Thread Ali Çehreli
On 12/04/2012 04:12 PM, deed wrote: interface I { // ... bool opEquals(I i); } class C : I { // ... bool opEquals(I i) { return true; } } void main() { I i1 = new C; I i2 = new C; assert(i1 == i2); // Assertion failure assert(i1 != i2); // Passes, although it's the opposite of what I want... }

opEquals

2012-12-04 Thread deed
interface I { bool opEquals(I i); } class C : I { bool opEquals(I i) { return true; } } void main() { I i1 = new C; I i2 = new C; assert(i1 == i2); // Assertino failure assert(i1 != i2); // Passes, although it's the opposite of what I want.. } What's

opEquals for same type

2012-12-04 Thread deed
interface I { // ... bool opEquals(I i); } class C : I { // ... bool opEquals(I i) { return true; } } void main() { I i1 = new C; I i2 = new C; assert(i1 == i2); // Assertion failure assert(i1 != i2); // Passes, although it's the opposite of what

C# implementation of Nullable (May)

2012-12-04 Thread Jesse Phillips
This article goes over a Nullable/Optional/Maybe implementation for C#. http://twistedoakstudios.com/blog/Post1130_when-null-is-not-enough-an-option-type-for-c http://www.reddit.com/r/programming/comments/14930f/when_null_is_not_enough_an_option_type_for_c/ It seems to be similar to that of st

Re: Template return values?

2012-12-04 Thread Era Scarecrow
On Tuesday, 4 December 2012 at 17:43:21 UTC, Dmitry Olshansky wrote: Well TDPL claims multiple alias this is allowed so in some distant future it maybe possible for Varaint to alias this to all built-in types. Maybe I remember back when I was originally reading about C++ and overloadin

Re: Template return values?

2012-12-04 Thread Era Scarecrow
On Tuesday, 4 December 2012 at 17:43:21 UTC, Dmitry Olshansky wrote: Well TDPL claims multiple alias this is allowed so in some distant future it maybe possible for Varaint to alias this to all built-in types. Maybe I remember back when I was originally reading about C++ and overloadin

Re: Template return values?

2012-12-04 Thread Era Scarecrow
On Tuesday, 4 December 2012 at 17:43:21 UTC, Dmitry Olshansky wrote: Well TDPL claims multiple alias this is allowed so in some distant future it maybe possible for Varaint to alias this to all built-in types. Maybe I remember back when i was originally reading about C++ and overloadin

Re: Template return values?

2012-12-04 Thread Dmitry Olshansky
12/4/2012 10:40 PM, Jonathan M Davis пишет: On Tuesday, December 04, 2012 21:43:09 Dmitry Olshansky wrote: Well TDPL claims multiple alias this is allowed so in some distant future it maybe possible for Varaint to alias this to all built-in types. That would be pretty hideous IMHO. There's a r

Re: Template return values?

2012-12-04 Thread Jonathan M Davis
On Tuesday, December 04, 2012 21:43:09 Dmitry Olshansky wrote: > Well TDPL claims multiple alias this is allowed so in some distant > future it maybe possible for Varaint to alias this to all built-in types. That would be pretty hideous IMHO. There's a reason that D eschews implicit conversions i

Re: Template return values?

2012-12-04 Thread Jacob Carlborg
On 2012-12-04 13:59, Era Scarecrow wrote: It also doesn't seem like it would be difficult to add, only 'auto' would cause any real errors (as it's not a known type it can return). It has been suggested before, overriding on the return type. I has more problems that one might think first.

Re: Template return values?

2012-12-04 Thread Dmitry Olshansky
12/4/2012 4:08 PM, Jacob Carlborg пишет: On 2012-12-04 08:48, Era Scarecrow wrote: A thought's been going through my head for a while now. I wonder about template return values. Function signatures are usually the inputs and NOT the return type. However for writing a variant type could be so v

Re: Default template type for class?

2012-12-04 Thread Adam D. Ruppe
BTW you can do: class myclass_custom(T = int) {} alias myclass_custom!int myclass; Then use myclass.whatever and you get int. If you want a custom type then, you'd use the other name (myclass_custom!ubyte for instance)

Re: How to import modules?

2012-12-04 Thread Ali Çehreli
On 12/03/2012 08:31 PM, js.mdnq wrote: I created a .d file having a class with the modules tag at the top and everything public. I put it in a dir and used the -I flag to include the path. When I import the file I get an undefined method. I had written a short chapter about that topic: http:

Re: Default template type for class?

2012-12-04 Thread Adam D. Ruppe
How can I create a default type so that I can call it like myclass.myfunc()? Can't do that. Best you can do is myclass!().myfunc, then it will use the default type (write it is (T = int) bw) but you have to put in the !() to actually use the template. There's a patch for the compiler to chan

Re: How to import modules?

2012-12-04 Thread js.mdnq
On Tuesday, 4 December 2012 at 07:17:15 UTC, Mike Parker wrote: On Tuesday, 4 December 2012 at 04:31:40 UTC, js.mdnq wrote: I created a .d file having a class with the modules tag at the top and everything public. I put it in a dir and used the -I flag to include the path. When I import the fi

Default template type for class?

2012-12-04 Thread js.mdnq
I have a class static class myclass(T) { static void myfunc(); } which I have to call like myclass!Q.myfunc(); How can I create a default type so that I can call it like myclass.myfunc()? I've tried static class myclass(T = int) and (alias T = int), neither worked.

Re: Type aliasing

2012-12-04 Thread js.mdnq
On Tuesday, 4 December 2012 at 16:42:21 UTC, Adam D. Ruppe wrote: On Tuesday, 4 December 2012 at 16:34:50 UTC, js.mdnq wrote: class myclass { int ID; } Try something like this: class myclass { typeof(uniqueID!T.Get()) ID; this() { ID = uniqueID!T.Get(); } } The typeof(expr..

Re: Type aliasing

2012-12-04 Thread Adam D. Ruppe
On Tuesday, 4 December 2012 at 16:34:50 UTC, js.mdnq wrote: class myclass { int ID; } Try something like this: class myclass { typeof(uniqueID!T.Get()) ID; this() { ID = uniqueID!T.Get(); } } The typeof(expr...) can be used anywhere a type can be used.

Type aliasing

2012-12-04 Thread js.mdnq
I have a static class that generates unique ID's. The id's are hardcoded as ints. I would like to make this extensible and allow for other integer numeric values to be(byte, ulong, etc...). I can simply make the static class generic without issues. The problem is the return type of the Get I

Re: Template return values?

2012-12-04 Thread Era Scarecrow
On Tuesday, 4 December 2012 at 12:48:57 UTC, bearophile wrote: Era Scarecrow: So then in theory Variant v; int i = v.getValue; //calls getValue!int() Meant it to be long i, but the idea is the same. I think this is not possible in D. This seems possible: auto i = v.getValue!int; Inde

Re: Template return values?

2012-12-04 Thread bearophile
Era Scarecrow: So then in theory Variant v; int i = v.getValue; //calls getValue!int() I think this is not possible in D. This seems possible: auto i = v.getValue!int; Bye, bearophile

Re: Template return values?

2012-12-04 Thread Jacob Carlborg
On 2012-12-04 08:48, Era Scarecrow wrote: A thought's been going through my head for a while now. I wonder about template return values. Function signatures are usually the inputs and NOT the return type. However for writing a variant type could be so very useful. So unless I've misunderstood,

Re: MS ODBC encoding issue

2012-12-04 Thread Nathan M. Swan
On Tuesday, 4 December 2012 at 07:59:40 UTC, Sam Hu wrote: Greetings! Any help would be much appreicated in advance as I've really struggled for quite long time! I wrote a class wrapper for MS ODBC Access database.When I try to run query on an Access database file,all fields contains Englis

MS ODBC encoding issue

2012-12-04 Thread Sam Hu
Greetings! Any help would be much appreicated in advance as I've really struggled for quite long time! I wrote a class wrapper for MS ODBC Access database.When I try to run query on an Access database file,all fields contains English character are fine with the result,but for those Asian cha