Re: using enums as key in associative array

2011-03-08 Thread Wilfried Kirschenmann
enum deviceType {cpu, gpu} auto execDeviceSuffix = [deviceType.cpu:.cpu, deviceType.gpu:.gpu]; The way to get what you want to work in this case is to use a module constructor. So, you'd do something like this: string[deviceType] execDeviceSuffix; static this() {        

Re: Access 'this' in inline assembly

2011-03-08 Thread bearophile
Brad Roberts: It's not by design. It's a quality of implementation issue that's solvable given some time to work on it. I intend to, eventually, unless someone has gotten to it ahead of me. Good, I am glad to be wrong then. Currently in LDC you have two different ways to tell the compiler

Re: Struct constructor and opCall confussion

2011-03-08 Thread bearophile
Tom: Am I missing something or is this another major bug? A major bug (that is not recognized as major, I think). I don't remember its number in bugzilla, sorry (anyone remembers it?). See also: http://d.puremagic.com/issues/show_bug.cgi?id=4053 Bye, bearophile

Re: dmd gdc in archlinux

2011-03-08 Thread %u
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article On Monday, March 07, 2011 12:10:27 %u wrote: == Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article and add /path/to/unzipped/dmd2/linux/bin to your path. how can i add path ? Put it in the appropriate bashrc file

Re: using enums as key in associative array

2011-03-08 Thread spir
On 03/08/2011 09:26 AM, Wilfried Kirschenmann wrote: enum deviceType {cpu, gpu} auto execDeviceSuffix = [deviceType.cpu:.cpu, deviceType.gpu:.gpu]; The way to get what you want to work in this case is to use a module constructor. So, you'd do something like this: string[deviceType]

Re: using enums as key in associative array

2011-03-08 Thread Jonathan M Davis
On Tuesday 08 March 2011 04:54:45 spir wrote: On 03/08/2011 09:26 AM, Wilfried Kirschenmann wrote: enum deviceType {cpu, gpu} auto execDeviceSuffix = [deviceType.cpu:.cpu, deviceType.gpu:.gpu]; The way to get what you want to work in this case is to use a module constructor. So, you'd

Re: using enums as key in associative array

2011-03-08 Thread spir
On 03/08/2011 03:48 PM, Jonathan M Davis wrote: I really don't understand your problem with module constructors. They're fantastic. I may be wrong, but I think this point of view is a where I can from statement. C's char* are fantastic when you have never used a PL with builtin strings.

Re: Struct constructor and opCall confussion

2011-03-08 Thread Tom
El 08/03/2011 05:32, bearophile escribió: Tom: Am I missing something or is this another major bug? A major bug (that is not recognized as major, I think). I don't remember its number in bugzilla, sorry (anyone remembers it?). See also: http://d.puremagic.com/issues/show_bug.cgi?id=4053

Re: using enums as key in associative array

2011-03-08 Thread Wilfried Kirschenmann
I really don't understand your problem with module constructors. They're fantastic. I may be wrong, but I think this point of view is a where I can from statement. C's char* are fantastic when you have never used a PL with builtin strings. There are languages in which you don't need to list

Re: Struct constructor and opCall confussion

2011-03-08 Thread Steven Schveighoffer
On Tue, 08 Mar 2011 10:52:38 -0500, Tom t...@nospam.com wrote: El 08/03/2011 05:32, bearophile escribió: Tom: Am I missing something or is this another major bug? A major bug (that is not recognized as major, I think). I don't remember its number in bugzilla, sorry (anyone remembers it?).

Re: Struct constructor and opCall confussion

2011-03-08 Thread Tom
El 08/03/2011 13:05, Steven Schveighoffer escribió: On Tue, 08 Mar 2011 10:52:38 -0500, Tom t...@nospam.com wrote: El 08/03/2011 05:32, bearophile escribió: Tom: Am I missing something or is this another major bug? A major bug (that is not recognized as major, I think). I don't remember

std.traits and std.string incompatible ?

2011-03-08 Thread Wilfried Kirschenmann
Hi, When running the following file: #!../dmd2/linux/bin/rdmd -unittest import std.string, std.traits; void main(string[] args){ bool test = isNumeric(args[0]); } I get the error : dmd2/linux/bin/../../src/phobos/std/traits.d(2576): Error: template std.traits.isNumeric(T) is not a

Templated struct doesn't need the parameterized type in return type definitions?

2011-03-08 Thread Andrej Mitrovic
import std.stdio; import std.traits; import std.exception; struct CheckedInt(N) if (isIntegral!N) { private N value; ref CheckedInt opUnary(string op)() if (op == ++) { enforce(value != value.max); ++value; return this; } this(N _value) {

Re: Templated struct doesn't need the parameterized type in return type definitions?

2011-03-08 Thread Steven Schveighoffer
On Tue, 08 Mar 2011 12:06:08 -0500, Andrej Mitrovic n...@none.none wrote: import std.stdio; import std.traits; import std.exception; struct CheckedInt(N) if (isIntegral!N) { private N value; ref CheckedInt opUnary(string op)() if (op == ++) { enforce(value != value.max);

Re: std.traits and std.string incompatible ?

2011-03-08 Thread Ali Çehreli
On 03/08/2011 08:24 AM, Wilfried Kirschenmann wrote: Hi, When running the following file: #!../dmd2/linux/bin/rdmd -unittest import std.string, std.traits; void main(string[] args){ bool test = isNumeric(args[0]); } I get the error :

Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
module test; struct MyArray(T) { private T[] data; bool opCast(T)() if (is(T == bool)) { return !data.empty; } } void main() { auto foo = MyArray!(int)(); auto state = foo ? true : false; } test.d(13): Error: undefined identifier module test.empty

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
Nevermind, I'm dumb. It's in std.array, I just need to import it. This needs to be said in TDPL however.

Re: Struct constructor and opCall confussion

2011-03-08 Thread bearophile
Steven Schveighoffe: Those two bugs look almost identical, I think they should be combined... Right, they look similar. I have linked each with the other, so if one gets fixed it's very easy to see if the fix fixes the other too. One bug has 4 votes and one bug 1 vote. Bye, bearophile

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
On 3/8/11, bearophile bearophileh...@lycos.com wrote: empty is not an array method, it's a free function that is used with a funny syntax. Yes but the compiler doesn't know that until std.array is imported. A better error message is that empty isn't a property of that array. It's much easier to

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Jesse Phillips
Andrej Mitrovic Wrote: On 3/8/11, bearophile bearophileh...@lycos.com wrote: empty is not an array method, it's a free function that is used with a funny syntax. Yes but the compiler doesn't know that until std.array is imported. A better error message is that empty isn't a property of

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
On 3/8/11, Jesse Phillips jessekphillip...@gmail.com wrote: What if you are trying to create a method which will act as a property for the array? If you get it wrong you would get the error that an array doesn't have the property and scream, I know that is why I'm building a function for it.

Re: Templated struct doesn't need the parameterized type in return type definitions?

2011-03-08 Thread spir
On 03/08/2011 06:20 PM, Steven Schveighoffer wrote: On Tue, 08 Mar 2011 12:06:08 -0500, Andrej Mitrovic n...@none.none wrote: import std.stdio; import std.traits; import std.exception; struct CheckedInt(N) if (isIntegral!N) { private N value; ref CheckedInt opUnary(string op)() if (op == ++)

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread spir
On 03/08/2011 06:56 PM, Andrej Mitrovic wrote: module test; struct MyArray(T) { private T[] data; bool opCast(T)() if (is(T == bool)) { return !data.empty; } } void main() { auto foo = MyArray!(int)(); auto state = foo ? true : false; } test.d(13):

Re: Templated struct doesn't need the parameterized type in return type definitions?

2011-03-08 Thread David Nadlinger
On 3/8/11 8:20 PM, spir wrote: […] Yet another syntactic special-case for special cases in the language. In this case, there are even 3 ways to write the same thing: […] I don't quite get how you think this would be a syntactic special case. As Steve pointed out, »class Foo(T) {}« is merely

Re: Templated struct doesn't need the parameterized type in return type definitions?

2011-03-08 Thread Steven Schveighoffer
On Tue, 08 Mar 2011 14:20:40 -0500, spir denis.s...@gmail.com wrote: On 03/08/2011 06:20 PM, Steven Schveighoffer wrote: On Tue, 08 Mar 2011 12:06:08 -0500, Andrej Mitrovic n...@none.none wrote: import std.stdio; import std.traits; import std.exception; struct CheckedInt(N) if

Re: Some weird crashes

2011-03-08 Thread simendsjo
On 08.03.2011 01:32, Andrej Mitrovic wrote: Sorry for not seeing this sooner. I think you might have set the wrong calling convention in the translated header file. See my answer on SO. I hope it works for you now. Thanks. Just to get the solution here too: * Use the vs2005 library (to get

Re: Templated struct doesn't need the parameterized type in return

2011-03-08 Thread bearophile
David Nadlinger: and because of this, it would rather be a special case *not* to allow referring to Foo using just that name. Right. On the other hand the current straightforward design leads to some bugs too, the give bad error messages: http://d.puremagic.com/issues/show_bug.cgi?id=3950

Re: std.traits and std.string incompatible ?

2011-03-08 Thread Nick Sabalausky
Ali Çehreli acehr...@yahoo.com wrote in message news:il5pge$nrr$1...@digitalmars.com... On 03/08/2011 08:24 AM, Wilfried Kirschenmann wrote: Hi, When running the following file: #!../dmd2/linux/bin/rdmd -unittest import std.string, std.traits; void main(string[] args){ bool test

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Jesse Phillips
Andrej Mitrovic Wrote: On 3/8/11, Jesse Phillips jessekphillip...@gmail.com wrote: What if you are trying to create a method which will act as a property for the array? If you get it wrong you would get the error that an array doesn't have the property and scream, I know that is why I'm

Dynamic array void initialization

2011-03-08 Thread Tom
import std.stdio; struct S { int i; int j; } int main(string[] args) { S[] ss = void; ss.length = 5; foreach (ref s; ss) s = S(1, 2); return 0; } Is the above code correct? (it doesn't work... it blows away or just give and

Re: Dynamic array void initialization

2011-03-08 Thread Ali Çehreli
On 03/08/2011 01:34 PM, Tom wrote: import std.stdio; struct S { int i; int j; } int main(string[] args) { S[] ss = void; ss.length = 5; foreach (ref s; ss) s = S(1, 2); return 0; } Is the above code correct? (it doesn't work... it blows away or just give and access violation error). I need

Re: Dynamic array void initialization

2011-03-08 Thread Steven Schveighoffer
On Tue, 08 Mar 2011 16:53:08 -0500, Ali Çehreli acehr...@yahoo.com wrote: On 03/08/2011 01:34 PM, Tom wrote: import std.stdio; struct S { int i; int j; } int main(string[] args) { S[] ss = void; ss.length = 5; foreach (ref s; ss) s = S(1, 2); return 0; } Is the above code correct? (it

Re: Dynamic array void initialization

2011-03-08 Thread Ali Çehreli
On 03/08/2011 02:03 PM, Steven Schveighoffer wrote: it's not std.array.reserve, it's object.reserve, always present, no need to import. Thanks. The reserve that I found in array.d is std.array.Appender(T).reserve. Ali

Re: Dynamic array void initialization

2011-03-08 Thread Tom
El 08/03/2011 19:03, Steven Schveighoffer escribió: On Tue, 08 Mar 2011 16:53:08 -0500, Ali Çehreli acehr...@yahoo.com wrote: On 03/08/2011 01:34 PM, Tom wrote: import std.stdio; struct S { int i; int j; } int main(string[] args) { S[] ss = void; ss.length = 5; foreach (ref s; ss) s = S(1,

Re: Dynamic array void initialization

2011-03-08 Thread Steven Schveighoffer
On Tue, 08 Mar 2011 17:48:37 -0500, Tom t...@nospam.com wrote: http://d.puremagic.com/issues/show_bug.cgi?id=5603 This is really sad. This kind of stuff is a must for performance. D is disappointing me too much yet :( There is always c's malloc, or you can try using the GC malloc

Re: Empty field doesn't exist for arrays, right?

2011-03-08 Thread Andrej Mitrovic
Well, maybe one day we'll have a compiler with lots of front-end customization options (or some nice analysis tools). In any case this topic is done here since post #2. :)

Re: Templated struct doesn't need the parameterized type in return type definitions?

2011-03-08 Thread Andrej Mitrovic
On 3/8/11, Steven Schveighoffer schvei...@yahoo.com wrote: See the problem? Yup. Btw, does auto ref still suffer from any bugs that I should know about? I've heard it had issues.

Re: using enums as key in associative array

2011-03-08 Thread Jonathan M Davis
On Tuesday, March 08, 2011 07:40:08 spir wrote: On 03/08/2011 03:48 PM, Jonathan M Davis wrote: I really don't understand your problem with module constructors. They're fantastic. I may be wrong, but I think this point of view is a where I can from statement. C's char* are fantastic when

Re: std.traits and std.string incompatible ?

2011-03-08 Thread Jonathan M Davis
On Tuesday, March 08, 2011 13:24:44 Nick Sabalausky wrote: Ali Çehreli acehr...@yahoo.com wrote in message news:il5pge$nrr$1...@digitalmars.com... On 03/08/2011 08:24 AM, Wilfried Kirschenmann wrote: Hi, When running the following file: #!../dmd2/linux/bin/rdmd -unittest

Re: std.traits and std.string incompatible ?

2011-03-08 Thread Jonathan M Davis
On Tuesday, March 08, 2011 16:11:09 Jonathan M Davis wrote: On Tuesday, March 08, 2011 13:24:44 Nick Sabalausky wrote: Ali Çehreli acehr...@yahoo.com wrote in message news:il5pge$nrr$1...@digitalmars.com... On 03/08/2011 08:24 AM, Wilfried Kirschenmann wrote: Hi, When

Re: Templated struct doesn't need the parameterized type in return type definitions?

2011-03-08 Thread Jonathan M Davis
On Tuesday, March 08, 2011 15:31:37 Andrej Mitrovic wrote: On 3/8/11, Steven Schveighoffer schvei...@yahoo.com wrote: See the problem? Yup. Btw, does auto ref still suffer from any bugs that I should know about? I've heard it had issues. I'm not sure that it works correctly with properties

Re: Dynamic array void initialization

2011-03-08 Thread Kai Meyer
On 03/08/2011 02:34 PM, Tom wrote: import std.stdio; struct S { int i; int j; } int main(string[] args) { S[] ss = void; ss.length = 5; foreach (ref s; ss) s = S(1, 2); return 0; } Is the above code correct? (it doesn't work... it blows away or just give and access violation error). I need

Re: Dynamic array void initialization

2011-03-08 Thread Kai Meyer
On 03/08/2011 05:42 PM, Kai Meyer wrote: On 03/08/2011 02:34 PM, Tom wrote: import std.stdio; struct S { int i; int j; } int main(string[] args) { S[] ss = void; ss.length = 5; foreach (ref s; ss) s = S(1, 2); return 0; } Is the above code correct? (it doesn't work... it blows away or just

Re: Dynamic array void initialization

2011-03-08 Thread Tom
El 08/03/2011 21:42, Kai Meyer escribió: On 03/08/2011 02:34 PM, Tom wrote: import std.stdio; struct S { int i; int j; } int main(string[] args) { S[] ss = void; ss.length = 5; foreach (ref s; ss) s = S(1, 2); return 0; } Is the above code correct? (it doesn't work... it blows away or just

Re: Some weird crashes

2011-03-08 Thread Bekenn
On 3/8/2011 12:57 PM, simendsjo wrote: One more thing.. Function pointers in structs.. Should they use extern(Windows) too? Yes.

Re: Help learning how to interface with c(++)

2011-03-08 Thread Kagamin
Kai Meyer Wrote: gcc -m32 -shared -fPIC Test.cpp -o libTest.so So I monkeyed around a little bit, and found out that if I change extern (C) to extern (C++), the library links correctly and the program runs. That lead me to believe that if I added the -cpp option to htod.exe, it would