digitalmars.D - implicit constructors
- Trass3r (14/14) Nov 24 2011 Wasn't there some discussion quite some time ago about introducing an
- Trass3r (18/18) Nov 24 2011 Seems like this is a CTFE-only issue?
- Trass3r (8/24) Nov 24 2011 // A a = 5; // Error: cannot implicitly convert expression (5) of type i...
- Trass3r (1/1) Nov 26 2011 anyone?
- Timon Gehr (21/22) Nov 26 2011 kk.
- Timon Gehr (3/25) Nov 26 2011 A a = 5;
- Timon Gehr (2/30) Nov 26 2011 (Except in function scope, where it does.)
- Timon Gehr (3/35) Nov 26 2011 NVM, I misunderstood the issue (I thought there were never implicit
- Trass3r (1/16) Nov 29 2011 http://d.puremagic.com/issues/show_bug.cgi?id=7019
Wasn't there some discussion quite some time ago about introducing an implicit/ implicit tag similar to C++'s explicit, just the other way around? I know there's alias this, but what if you don't store the value directly? struct A { int store; this(int a) { store = a << 16; ... } } A a = 5;
Nov 24 2011
Seems like this is a CTFE-only issue? import std.stdio; struct A { int store; this(int a) { store = a << 3; //... } } A a = 5; // Error: cannot implicitly convert expression (5) of type int to A void main() { A a = 5; // fine writeln(a.store); // prints 40 }
Nov 24 2011
Seems like this is a CTFE-only issue?No.import std.stdio; struct A { int store; this(int a) { store = a << 3; //... } }// A a = 5; // Error: cannot implicitly convert expression (5) of type int to A void foo(A a) { }void main() { A a = 5; // fine writeln(a.store); // prints 40foo(5); // Error: cannot implicitly convert expression (5) of type int to A}
Nov 24 2011
On 11/27/2011 12:14 AM, Trass3r wrote:anyone?kk. struct A{ struct S{A opAssign(int rhs){return *(cast(A*)&this)=A(rhs);}} union{ struct{ // members int store; } S _x; // dummy struct } this(int a) { store = a << 16; //... } alias _x this; } void main(){ A x; x = 2; assert(x.store == 2 << 16); }
Nov 26 2011
On 11/27/2011 01:54 AM, Timon Gehr wrote:On 11/27/2011 12:14 AM, Trass3r wrote:A a = 5; Does not work though.anyone?kk. struct A{ struct S{A opAssign(int rhs){return *(cast(A*)&this)=A(rhs);}} union{ struct{ // members int store; } S _x; // dummy struct } this(int a) { store = a << 16; //... } alias _x this; } void main(){ A x; x = 2; assert(x.store == 2 << 16); }
Nov 26 2011
On 11/27/2011 01:55 AM, Timon Gehr wrote:On 11/27/2011 01:54 AM, Timon Gehr wrote:(Except in function scope, where it does.)On 11/27/2011 12:14 AM, Trass3r wrote:A a = 5; Does not work though.anyone?kk. struct A{ struct S{A opAssign(int rhs){return *(cast(A*)&this)=A(rhs);}} union{ struct{ // members int store; } S _x; // dummy struct } this(int a) { store = a << 16; //... } alias _x this; } void main(){ A x; x = 2; assert(x.store == 2 << 16); }
Nov 26 2011
On 11/27/2011 01:56 AM, Timon Gehr wrote:On 11/27/2011 01:55 AM, Timon Gehr wrote:NVM, I misunderstood the issue (I thought there were never implicit constructors. If there were not, my program would implement them.)On 11/27/2011 01:54 AM, Timon Gehr wrote:(Except in function scope, where it does.)On 11/27/2011 12:14 AM, Trass3r wrote:A a = 5; Does not work though.anyone?kk. struct A{ struct S{A opAssign(int rhs){return *(cast(A*)&this)=A(rhs);}} union{ struct{ // members int store; } S _x; // dummy struct } this(int a) { store = a << 16; //... } alias _x this; } void main(){ A x; x = 2; assert(x.store == 2 << 16); }
Nov 26 2011
Wasn't there some discussion quite some time ago about introducing an implicit/ implicit tag similar to C++'s explicit, just the other way around? I know there's alias this, but what if you don't store the value directly? struct A { int store; this(int a) { store = a << 16; ... } } A a = 5;http://d.puremagic.com/issues/show_bug.cgi?id=7019
Nov 29 2011