dmd/compiler/test/compilable/imports/test21098_phobos.d
Martin Kinkelin ed17b3e95d
Fix #21098 (#21132)
By reverting #10718 - it seems superfluous nowadays?
2025-04-02 07:42:03 +08:00

77 lines
1.2 KiB
D

struct Nullable(T)
{
static struct DontCallDestructorT
{
T payload;
}
DontCallDestructorT _value;
string toString() const
{
Appender!string app;
formatValueImpl(app, _value);
return null;
}
}
struct Appender(A)
{
InPlaceAppender!A impl;
}
struct InPlaceAppender(T)
{
static void toStringImpl(const T[] data)
{
string app;
formatValue(app, data);
}
}
void formatValueImpl(Writer, T)(Writer, const(T)) {}
void formatValueImpl(Writer, T)(Writer w, T obj)
if (is(T == U[], U))
{
formatValue(w, obj[0]);
}
enum HasToStringResult
{
none,
bla
}
template hasToString(T)
{
static if (is(typeof(
(T val) {
val.toString(s);
})))
enum hasToString = HasToStringResult.bla;
else
enum hasToString = HasToStringResult.none;
}
void formatValueImpl(Writer, T)(ref Writer w, T val)
if (is(T == struct) || is(T == union))
{
static if (hasToString!T)
int dummy;
formatElement(w, val.tupleof);
}
void formatElement(Writer, T)(Writer w, T val)
{
formatValueImpl(w, val);
}
void formatValue(Writer, T)(Writer w, T val)
{
formatValueImpl(w, val);
}