Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions std/sumtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ private:
}

Storage storage;
Tag tag;
static if (Types.length > 1)
Tag tag;
else
enum Tag tag = 0;

/* Accesses the value stored in a SumType by its index.
*
Expand Down Expand Up @@ -369,7 +372,8 @@ public:
storage.tupleof[tid] = forward!value;
}

tag = tid;
static if (Types.length > 1)
tag = tid;
}

static if (isCopyable!(const(T)))
Expand All @@ -380,7 +384,8 @@ public:
this(const(T) value) const
{
storage.tupleof[tid] = value;
tag = tid;
static if (Types.length > 1)
tag = tid;
}
}
}
Expand All @@ -397,7 +402,8 @@ public:
this(immutable(T) value) immutable
{
storage.tupleof[tid] = value;
tag = tid;
static if (Types.length > 1)
tag = tid;
}
}
}
Expand All @@ -415,7 +421,8 @@ public:
if (is(Value == DeducedParameterType!(inout(T))))
{
storage.tupleof[tid] = value;
tag = tid;
static if (Types.length > 1)
tag = tid;
}
}
}
Expand Down Expand Up @@ -449,7 +456,8 @@ public:
return newStorage;
});

tag = other.tag;
static if (Types.length > 1)
tag = other.tag;
}
}
else
Expand All @@ -469,7 +477,8 @@ public:
return newStorage;
});

tag = other.tag;
static if (Types.length > 1)
tag = other.tag;
}
}
else
Expand All @@ -493,7 +502,8 @@ public:
return newStorage;
});

tag = other.tag;
static if (Types.length > 1)
tag = other.tag;
}
}
else
Expand All @@ -517,7 +527,8 @@ public:
return newStorage;
});

tag = other.tag;
static if (Types.length > 1)
tag = other.tag;
}
}
else
Expand Down Expand Up @@ -644,7 +655,8 @@ public:
}

storage = newStorage;
tag = tid;
static if (Types.length > 1)
tag = tid;

return this;
}
Expand Down Expand Up @@ -1558,6 +1570,13 @@ version (D_BetterC) {} else
enum result = test();
}

// https://github.com/dlang/phobos/issues/10563
// Do not waste space for tag if sumtype has only single type
@safe unittest
{
static assert(SumType!int.sizeof == int.sizeof);
}

/// True if `T` is an instance of the `SumType` template, otherwise false.
private enum bool isSumTypeInstance(T) = is(T == SumType!Args, Args...);

Expand Down
Loading