digitalmars.D - implicit constructors
- Trass3r <un known.com> Nov 24 2011
- Trass3r <un known.com> Nov 24 2011
- Trass3r <un known.com> Nov 24 2011
- Trass3r <un known.com> Nov 26 2011
- Timon Gehr <timon.gehr gmx.ch> Nov 26 2011
- Timon Gehr <timon.gehr gmx.ch> Nov 26 2011
- Timon Gehr <timon.gehr gmx.ch> Nov 26 2011
- Timon Gehr <timon.gehr gmx.ch> Nov 26 2011
- Trass3r <un known.com> Nov 29 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;
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?
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 40
foo(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: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); }
A a = 5; Does not work though.
Nov 26 2011
On 11/27/2011 01:55 AM, Timon Gehr wrote:On 11/27/2011 01:54 AM, Timon Gehr wrote: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); }
A a = 5; Does not work though.
(Except in function scope, where it does.)
Nov 26 2011
On 11/27/2011 01:56 AM, Timon Gehr wrote:On 11/27/2011 01:55 AM, Timon Gehr wrote:On 11/27/2011 01:54 AM, Timon Gehr wrote: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); }
A a = 5; Does not work though.
(Except in function scope, where it does.)
NVM, I misunderstood the issue (I thought there were never implicit constructors. If there were not, my program would implement them.)
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









Trass3r <un known.com> 