Re: overiding mutable methods in immutable classes

2014-11-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/21/14 7:24 PM, Eric wrote: immutable class X { private int x; this(int x) { this.x = x; } ... override size_t toHash(); // error: can't override mutable method } Since toHash() cannot be overridden in an immutable class, is there a work-around? Kind of, but I don't thi

Re: overiding mutable methods in immutable classes

2014-11-21 Thread Eric via Digitalmars-d-learn
But think about if enforced immutability is really what you want. You don't need to mark the fields immutable to be able to construct immutable Xs. A `pure` constructor is handy, as it can construct both mutable and immutable objects. class X { private int x; this(int x) pure { this.

Re: overiding mutable methods in immutable classes

2014-11-21 Thread anonymous via Digitalmars-d-learn
On Saturday, 22 November 2014 at 00:24:39 UTC, Eric wrote: immutable class X { private int x; this(int x) { this.x = x; } ... override size_t toHash(); // error: can't override mutable method } Since toHash() cannot be overridden in an immutable class, is there a work-around? I

overiding mutable methods in immutable classes

2014-11-21 Thread Eric via Digitalmars-d-learn
immutable class X { private int x; this(int x) { this.x = x; } ... override size_t toHash(); // error: can't override mutable method } Since toHash() cannot be overridden in an immutable class, is there a work-around? In other words, immutable X x1 = new immutable X(5); immutab

Re: how to compare the type of a subclass

2014-11-21 Thread Eric via Digitalmars-d-learn
On Friday, 21 November 2014 at 22:52:54 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Fri, Nov 21, 2014 at 10:30:51PM +, Eric via Digitalmars-d-learn wrote: On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote: >On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote: [...] >>I

Re: how to compare the type of a subclass

2014-11-21 Thread anonymous via Digitalmars-d-learn
On Friday, 21 November 2014 at 22:30:52 UTC, Eric wrote: On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote: On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote: [...] class X { } class Y : X { } Y y = new Y; X x = y; [...] I have't quite mastered the whole is/typeof/typeid t

Re: how to compare the type of a subclass

2014-11-21 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Nov 21, 2014 at 10:30:51PM +, Eric via Digitalmars-d-learn wrote: > On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote: > >On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote: [...] > >>Is there a way I can check the type of x without doing > >>a string comparison? > >> >

Re: how to compare the type of a subclass

2014-11-21 Thread Eric via Digitalmars-d-learn
On Friday, 21 November 2014 at 22:25:32 UTC, anonymous wrote: On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote: Suppose I have: module test; class X { } class Y : X { } Y y = new Y; X x = y; assert(is(typeof(x) == test.Y); // this assertion will fail assert(typeid(x).toString() == "t

Re: how to compare the type of a subclass

2014-11-21 Thread anonymous via Digitalmars-d-learn
On Friday, 21 November 2014 at 22:15:37 UTC, Eric wrote: Suppose I have: module test; class X { } class Y : X { } Y y = new Y; X x = y; assert(is(typeof(x) == test.Y); // this assertion will fail assert(typeid(x).toString() == "test.Y"); // this assertion will pass Is there a way I can ch

how to compare the type of a subclass

2014-11-21 Thread Eric via Digitalmars-d-learn
Suppose I have: module test; class X { } class Y : X { } Y y = new Y; X x = y; assert(is(typeof(x) == test.Y); // this assertion will fail assert(typeid(x).toString() == "test.Y"); // this assertion will pass Is there a way I can check the type of x without doing a string comparison? -Eri

Re: write multiple lines without "\n" with writeln

2014-11-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 21 November 2014 at 17:43:27 UTC, Ary Borenszweig wrote: What's concatenation by juxtaposition? When "foo" "bar" turns into "foobar". The two string literals are right next to each other, no operator or anything else in between, so they are combined.

Re: write multiple lines without "\n" with writeln

2014-11-21 Thread Ary Borenszweig via Digitalmars-d-learn
On 11/21/14, 2:46 PM, Adam D. Ruppe wrote: On Friday, 21 November 2014 at 17:43:27 UTC, Ary Borenszweig wrote: What's concatenation by juxtaposition? When "foo" "bar" turns into "foobar". The two string literals are right next to each other, no operator or anything else in between, so they are

Re: write multiple lines without "\n" with writeln

2014-11-21 Thread Ary Borenszweig via Digitalmars-d-learn
On 11/21/14, 1:59 PM, "Marc Schütz" " wrote: On Friday, 21 November 2014 at 15:00:31 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 20 Nov 2014 14:23:23 -0300 Ary Borenszweig via Digitalmars-d-learn wrote: This way you avoid silly typing mistakes while at the same time you allow splitting

Re: write multiple lines without "\n" with writeln

2014-11-21 Thread via Digitalmars-d-learn
On Friday, 21 November 2014 at 15:00:31 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 20 Nov 2014 14:23:23 -0300 Ary Borenszweig via Digitalmars-d-learn wrote: This way you avoid silly typing mistakes while at the same time you allow splitting a string across several lines without having

Re: Question about Vectors

2014-11-21 Thread Marco Leise via Digitalmars-d-learn
Am Thu, 20 Nov 2014 20:17:31 + schrieb "Charles" : > So I was reading the documentation page: > http://dlang.org/simd.html and noticed what appears to be a typo: > > int4 v; > (cast(int*)&v)[3] = 2; // set 3rd element of the 4 int vector > (cast(int[4])v)[3] = 2; // set 3rd element of the

Re: write multiple lines without "\n" with writeln

2014-11-21 Thread ketmar via Digitalmars-d-learn
On Thu, 20 Nov 2014 14:23:23 -0300 Ary Borenszweig via Digitalmars-d-learn wrote: > This way you avoid silly typing mistakes while at the same time you > allow splitting a string across several lines without having to > concatenate them at runtime. i bet that current D frontend is able to conca

Re: Operator Overloading in an Abstract Base Class

2014-11-21 Thread Nordlöw
On Thursday, 20 November 2014 at 22:35:51 UTC, IgorStepanov wrote: class Patt { // It is better then your static if. // Compiler will raise better error message for incorrect operator. Seq opBinary(string op)(Patt rhs) if (op == "~") { return opCatImpl(rhs); } p

Re: Dub / Derelict confusion

2014-11-21 Thread Paul via Digitalmars-d-learn
On Friday, 21 November 2014 at 01:22:34 UTC, Mike Parker wrote: On 11/21/2014 5:57 AM, Paul wrote: This is a tad off topic now but I'm struggling to get a window on screen as SDL_CreateWindow is failing, here's what I've got: try{ DerelictSDL2.load(); }catch(Exception e){ writeln("F