Created
August 7, 2013 20:20
-
-
Save nikibobi/6178215 to your computer and use it in GitHub Desktop.
init.d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///This is only for debug. The same role as Type.init == init!Type | |
@property auto init(Target)() { | |
writeln(Target.init); //used for debug | |
return Target.init; | |
} | |
///Returns Source's .init converted with std.conv.to to Target | |
@property auto init(Source, Target)() { | |
return init!Source.to!Target; | |
} | |
///Sets target to Source's .init value | |
@property void init(Source, Target)(out Target target) { | |
target = init!(Source, Target); | |
} | |
unittest { | |
struct MyInt { | |
alias x this; | |
private int x; | |
} | |
MyInt f; | |
init!bool(f); | |
auto v = init!float; // the same as float.init | |
v.init!bool; | |
writeln(v); | |
auto str = init!(int, string); | |
writeln(str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment