Menu
Home
Create new Paste
Log in
Code
Theme: cobalt
Theme: eclipse
Theme: elegant
Theme: monokai
Theme: neat
Theme: night
Theme: rubyblue
struct S { double d = 0.0; // part of default initializer int i; // part of default initializer this(int i = 0) { this.i = i; } // ctor with (ignored) defarg @property static S init() // hjacked .init property { S s; s.d = double.min; s.i = -6; return s; } } struct Z { double d; void opCall() { } } void main() { S s1; // default initalization assert(s1.d is 0.0 && s1.i is 0); S s2 = S(); // .init hjack doesn't affect this too // ctor with default argument is ignored assert(s2.d is 0.0 && s2.i is 0); S s3 = S(2); // by ctor assert(s3.d is 0.0 && s3.i is 2); S s4 = void; assert(!__traits(compiles, s4 = S(0.0, 1))); // struct literal is impossible if any ctor exists S s5 = S.init; assert(s5.d is double.min && s5.i is -6); Z z1 = void; assert(!__traits(compiles, z1 = Z())); assert(!__traits(compiles, z1 = Z(0.0))); }
Result:
Success
/
Return code: 0
/
Compilation time:
0.092
seconds
/
Run time:
0.001
seconds
Username
Message
Add comment
Paste info
Author:
Guest
Views:
86
Private:
no
Expires:
Never
Uploaded:
17.09.12 20:35
Votes
:
0
Tweet
Compilation
Compiler:
DMD 2.060
Pointer size:
m64
Actions
Download
Fork
Raw
×
Confirm
Are you sure you want to delete this paste?
There's no way back!
×
Confirm
Reason