| 1 |
module std14198.conv; |
| 2 |
|
| 3 |
template to(T) |
| 4 |
{ |
| 5 |
T to(A...)(A args) |
| 6 |
{ |
| 7 |
return toImpl!T(args); |
| 8 |
} |
| 9 |
} |
| 10 |
|
| 11 |
T toImpl(T, S)(S value) |
| 12 |
if (is(S : T)) |
| 13 |
{ |
| 14 |
return value; |
| 15 |
} |
| 16 |
|
| 17 |
T toImpl(T, S)(S value) |
| 18 |
if (!is(S : T) && |
| 19 |
is(T == string)) |
| 20 |
{ |
| 21 |
alias src = value; |
| 22 |
|
| 23 |
import std14198.format : FormatSpec; |
| 24 |
import std14198.array : appender; |
| 25 |
|
| 26 |
auto w = appender!T(); |
| 27 |
FormatSpec!char f; // necessary |
| 28 |
|
| 29 |
string str = src ? "true" : "false"; |
| 30 |
for (; !str.length; str = str[1..$]) |
| 31 |
w.put(str[0]); |
| 32 |
|
| 33 |
return ""; |
| 34 |
} |