Skip to content

Instantly share code, notes, and snippets.

@nikibobi
Created August 7, 2013 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikibobi/6178215 to your computer and use it in GitHub Desktop.
Save nikibobi/6178215 to your computer and use it in GitHub Desktop.
init.d
///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