Re: Can't understand templates

2014-11-29 Thread Ali Çehreli via Digitalmars-d-learn
On 11/28/2014 10:26 PM, Sly wrote: I still don't understand how to read this signature: Point!T getResponse(T: Point!T)(string question) The following is what makes sense to me. Sorry for going step by step but I think it helped me understand your question. (See item 3 below.) 1) Point!T

Re: Why does hello world not compile in safe?

2014-11-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, November 29, 2014 07:24:55 Freddy via Digitalmars-d-learn wrote: import std.stdio; @safe: void main() { writeln(Edit source/app.d to start your project.); } source/app.d(5): Error: safe function 'D main' cannot call system function

Re: Can't understand templates

2014-11-29 Thread Sly via Digitalmars-d-learn
Ah, now I see. In C++ we would also need to supply template parameters, but we'd put them before return type (templatetypename T getResponsePointT); in D we put them before the colon. Now I'm trying to write a specialization for Pair. It seems that this is the way to do it: Pair!(A, B)

Re: Still not D standard yet ?

2014-11-29 Thread Ledd via Digitalmars-d-learn
On Saturday, 29 November 2014 at 02:43:14 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Saturday, November 29, 2014 01:30:55 Ledd via Digitalmars-d-learn wrote: On Friday, 28 November 2014 at 12:35:28 UTC, Kagamin wrote: What is missing? an ISO standard ? Someday, maybe, but most

Re: Can't understand templates

2014-11-29 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/2014 12:41 AM, Sly wrote: Ah, now I see. In C++ we would also need to supply template parameters, but we'd put them before return type (templatetypename T getResponsePointT); in D we put them before the colon. Now I'm trying to write a specialization for Pair. It seems that this is the

What am I missing? Pure constructor behaves differently when assigning string member

2014-11-29 Thread jostly via Digitalmars-d-learn
I can't find a way to use a pure constructor to create both mutable and immutable instances of the same class, when one of the fields I assign is a string. This works fine: class A { int value; this(int value_) pure

Re: Still not D standard yet ?

2014-11-29 Thread bachmeier via Digitalmars-d-learn
On Saturday, 29 November 2014 at 09:03:13 UTC, Ledd wrote: Do you really think that a system language, or just a language that aims to be popular, can possibly discard the idea of getting into an international standard ? I still can't recall any major language that doesn't have a standard,

Re: Can't understand templates

2014-11-29 Thread Sly via Digitalmars-d-learn
On Saturday, 29 November 2014 at 09:11:51 UTC, Ali Çehreli wrote: Point!T getResponse(P : Point!T, T)(string question) { // ... } This doesn't work because now this definition has 2 parameters P and T. I have to specify both like this: auto pt = getResponse!(Point!int, int)(point);

Re: What am I missing? Pure constructor behaves differently when assigning string member

2014-11-29 Thread jostly via Digitalmars-d-learn
On Saturday, 29 November 2014 at 09:41:00 UTC, jostly wrote: I can't find a way to use a pure constructor to create both mutable and immutable instances of the same class, when one of the fields I assign is a string. After poking around a bit, I believe it is caused by issue #10012

Re: What am I missing? Pure constructor behaves differently when assigning string member

2014-11-29 Thread anonymous via Digitalmars-d-learn
On Saturday, 29 November 2014 at 09:41:00 UTC, jostly wrote: I can't find a way to use a pure constructor to create both mutable and immutable instances of the same class, when one of the fields I assign is a string. [...] The question is: am I missing something that would make it possible to

Re: Casting in Safe D

2014-11-29 Thread Nordlöw
On Friday, 28 November 2014 at 22:54:42 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Wednesday, November 26, 2014 16:27:53 David Held via Digitalmars-d-learn wrote: On 11/23/2014 3:12 PM, anonymous wrote: [...] And even pointer dereferencing is @safe. Invalid ones will fail

Re: Why the DMD Backend?

2014-11-29 Thread Joakim via Digitalmars-d-learn
On Friday, 28 November 2014 at 19:59:40 UTC, Xinok wrote: Given that we have GDC with the GCC backend and LDC with the LLVM backend, what are the benefits of keeping the DMD compiler backend? It seems to me that GCC and LLVM are far more developed and better supported by their respective

Re: Can't understand templates

2014-11-29 Thread Meta via Digitalmars-d-learn
On Saturday, 29 November 2014 at 11:07:34 UTC, Sly wrote: On Saturday, 29 November 2014 at 09:11:51 UTC, Ali Çehreli wrote: Point!T getResponse(P : Point!T, T)(string question) { // ... } This doesn't work because now this definition has 2 parameters P and T. I have to specify both like

Re: Still not D standard yet ?

2014-11-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, November 29, 2014 10:35:32 bachmeier via Digitalmars-d-learn wrote: On Saturday, 29 November 2014 at 09:03:13 UTC, Ledd wrote: Do you really think that a system language, or just a language that aims to be popular, can possibly discard the idea of getting into an international

Re: Can't understand templates

2014-11-29 Thread Sly via Digitalmars-d-learn
You miss another definition which introduces a conflict: T getResponse(T)(string question) {...} On Saturday, 29 November 2014 at 17:20:42 UTC, Meta wrote: On Saturday, 29 November 2014 at 11:07:34 UTC, Sly wrote: On Saturday, 29 November 2014 at 09:11:51 UTC, Ali Çehreli wrote: Point!T

Re: Still not D standard yet ?

2014-11-29 Thread via Digitalmars-d-learn
On Saturday, 29 November 2014 at 17:48:31 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Saturday, November 29, 2014 10:35:32 bachmeier via Digitalmars-d-learn wrote: C was standardized in 1989. C++ was standardized in 1998. I'm unaware of ISO (or any other) standardization for Go,

Re: Still not D standard yet ?

2014-11-29 Thread ketmar via Digitalmars-d-learn
On Sat, 29 Nov 2014 10:35:32 + bachmeier via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Saturday, 29 November 2014 at 09:03:13 UTC, Ledd wrote: Do you really think that a system language, or just a language that aims to be popular, can possibly discard the idea

Re: Why the DMD Backend?

2014-11-29 Thread ketmar via Digitalmars-d-learn
On Sat, 29 Nov 2014 15:37:32 + Joakim via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: build time for the whole DMD compiler with standard library, using G++: 100 seconds. yea, no kidding. gdc: i don't even want to think about that, way t long. ldc: not that

Re: Can't understand templates

2014-11-29 Thread Meta via Digitalmars-d-learn
On Saturday, 29 November 2014 at 18:19:40 UTC, Sly wrote: You miss another definition which introduces a conflict: T getResponse(T)(string question) {...} In that case, you're better off with a pair of declarations: struct Point(T) { T x; T y; } T getResponse(T)(string

Re: Can't understand templates

2014-11-29 Thread Sly via Digitalmars-d-learn
This is clearly an incorrect way because it requires editing the original definition every time a new class is introduced. On Saturday, 29 November 2014 at 19:10:34 UTC, Meta wrote: On Saturday, 29 November 2014 at 18:19:40 UTC, Sly wrote: You miss another definition which introduces a

How to initialise array of ubytes?

2014-11-29 Thread Paul via Digitalmars-d-learn
I'm trying to do this: ubyte[MAPSIZE][MAPSIZE] map = 1; but it doesn't work and I can't seem to cast the value to a ubyte (which looks rather ugly and out of place in D anyway). Is there a way to do this other than using a couple of loops? Cheers Paul

Re: Can't understand templates

2014-11-29 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/2014 10:19 AM, Sly wrote: You miss another definition which introduces a conflict: T getResponse(T)(string question) {...} The following works with dmd git head: import std.stdio; T getResponse(T)(string question) { writef(%s (%s): , question, T.stringof); T response;

Re: How to initialise array of ubytes?

2014-11-29 Thread bearophile via Digitalmars-d-learn
Paul: I'm trying to do this: ubyte[MAPSIZE][MAPSIZE] map = 1; but it doesn't work and I can't seem to cast the value to a ubyte (which looks rather ugly and out of place in D anyway). Is there a way to do this other than using a couple of loops? This works: enum MAPSIZE = 3; void main()

Re: How to initialise array of ubytes?

2014-11-29 Thread Daniel Kozak via Digitalmars-d-learn
Dne Sat, 29 Nov 2014 21:10:41 +0100 Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsal(a): I'm trying to do this: ubyte[MAPSIZE][MAPSIZE] map = 1; but it doesn't work and I can't seem to cast the value to a ubyte (which looks rather ugly and out of place in D anyway).

Re: How to initialise array of ubytes?

2014-11-29 Thread ketmar via Digitalmars-d-learn
On Sat, 29 Nov 2014 21:28:36 +0100 Daniel Kozak via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Dne Sat, 29 Nov 2014 21:10:41 +0100 Paul via Digitalmars-d-learn digitalmars-d-learn@puremagic.com napsal(a): I'm trying to do this: ubyte[MAPSIZE][MAPSIZE] map = 1;

Re: How to initialise array of ubytes?

2014-11-29 Thread bearophile via Digitalmars-d-learn
Daniel Kozak: http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361 Do you also know why the simplest syntax doesn't work? Can't it be implemented and added to the D language? Bye, bearophile

Re: How to initialise array of ubytes?

2014-11-29 Thread Paul via Digitalmars-d-learn
On Saturday, 29 November 2014 at 20:22:40 UTC, bearophile wrote: This works: enum MAPSIZE = 3; void main() { ubyte[MAPSIZE][MAPSIZE] map2 = 1; } This doesn't work: enum MAPSIZE = 3; ubyte[MAPSIZE][MAPSIZE] map1 = ubyte(1); void main() {} Why isn't this working? I'm afraid I don't

Re: Array toHash()

2014-11-29 Thread David Held via Digitalmars-d-learn
On 11/26/2014 4:40 PM, Ali Çehreli wrote: [...] override size_t toHash() @trusted pure const nothrow { auto func = assumePure((typeid(importantStuff).getHash)); return func(importantStuff); } Very helpful, thanks! Am I right in assuming that there is some

Re: Can't understand templates

2014-11-29 Thread Sly via Digitalmars-d-learn
OK. I'm using gdc 4.8.2 and this doesn't compile, so it's probably an old version. Checked on ideone and it works with dmd-2.042. Thanks a lot for your help! On Saturday, 29 November 2014 at 20:16:24 UTC, Ali Çehreli wrote: On 11/29/2014 10:19 AM, Sly wrote: You miss another definition which

Re: How to initialise array of ubytes?

2014-11-29 Thread Daniel Kozak via Digitalmars-d-learn
On Saturday, 29 November 2014 at 20:45:34 UTC, bearophile wrote: Daniel Kozak: http://stackoverflow.com/questions/24600796/d-set-default-value-for-a-struct-member-which-is-a-multidimensional-static-arr/24754361#24754361 Do you also know why the simplest syntax doesn't work? Can't it be

Do functions and/or function pointers have scope (or lifetimes)

2014-11-29 Thread WhatMeWorry via Digitalmars-d-learn
I'm assuming the answer is yes. If so, that implies that I could execute a function pointer that doesn't point to anything meaningful. Conversely, functionality could exist that I can't get access to because my function pointer is unavailable? If these are dangers, is there a technique or

Re: Do functions and/or function pointers have scope (or lifetimes)

2014-11-29 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Nov 29, 2014 at 10:59:21PM +, WhatMeWorry via Digitalmars-d-learn wrote: I'm assuming the answer is yes. If so, that implies that I could execute a function pointer that doesn't point to anything meaningful. Conversely, functionality could exist that I can't get access to

Re: Array toHash()

2014-11-29 Thread Ali Çehreli via Digitalmars-d-learn
On 11/29/2014 12:45 PM, David Held wrote: On 11/26/2014 4:40 PM, Ali Çehreli wrote: [...] override size_t toHash() @trusted pure const nothrow { auto func = assumePure((typeid(importantStuff).getHash)); return func(importantStuff); } Am I right in

Re: Why the DMD Backend?

2014-11-29 Thread Ary Borenszweig via Digitalmars-d-learn
On 11/29/14, 3:48 PM, ketmar via Digitalmars-d-learn wrote: On Sat, 29 Nov 2014 15:37:32 + Joakim via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: build time for the whole DMD compiler with standard library, using G++: 100 seconds. yea, no kidding. gdc: i don't even want

Re: Why the DMD Backend?

2014-11-29 Thread ketmar via Digitalmars-d-learn
On Sat, 29 Nov 2014 22:57:52 -0300 Ary Borenszweig via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: besides, i don't want to use anything llvm-related. Why not? let's say that there is some ideological reasons. signature.asc Description: PGP signature

Re: Array toHash()

2014-11-29 Thread David Held via Digitalmars-d-learn
On 11/29/2014 3:59 PM, Ali Çehreli wrote: [...] typeid() is a runtime function. I think it will be costly every time toHash is called. The function pointer can be initialized once. // I've deduced the type from an error message. ;) static const ulong delegate(const(void*)) const pure