| 1 |
module imports.diag10141b; |
| 2 |
|
| 3 |
template isSomeChar(T) { |
| 4 |
enum isSomeChar = |
| 5 |
is(immutable T == immutable char) || |
| 6 |
is(immutable T == immutable wchar) || |
| 7 |
is(immutable T == immutable dchar); |
| 8 |
} |
| 9 |
|
| 10 |
struct Appender(A : T[], T) |
| 11 |
{ |
| 12 |
private template canPutItem(U) |
| 13 |
{ |
| 14 |
enum bool canPutItem = |
| 15 |
//isImplicitlyConvertible!(U, T) || |
| 16 |
isSomeChar!T && isSomeChar!U; |
| 17 |
} |
| 18 |
private template canPutRange(Range) |
| 19 |
{ |
| 20 |
enum bool canPutRange = |
| 21 |
//isInputRange!Range && |
| 22 |
is(typeof(Appender.init.put("a"d[0]))); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Appends one item to the managed array. |
| 27 |
*/ |
| 28 |
void put(U)(U item) if (canPutItem!U) |
| 29 |
{ |
| 30 |
char[T.sizeof == 1 ? 4 : 2] encoded; |
| 31 |
auto len = 1; |
| 32 |
put(encoded[0 .. len]); // ! |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Appends an entire range to the managed array. |
| 37 |
*/ |
| 38 |
void put(Range)(Range items) if (canPutRange!Range) |
| 39 |
{ |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
void put(R, E)(ref R r, E e) |
| 44 |
{ |
| 45 |
static if (is(typeof(r.put(e)))) |
| 46 |
{ |
| 47 |
r.put(e); |
| 48 |
} |
| 49 |
else |
| 50 |
{ |
| 51 |
static assert(false, |
| 52 |
"Cannot put a "~E.stringof~" into a "~R.stringof); |
| 53 |
} |
| 54 |
} |