Trying to construct a variant with a constant value type (i.e. the value is copied so the const doesn't matter) fails with a compiler error. Example: import std.variant; alias Value = Algebraic!(long, double); void main() { const long foo = 123L; long bar = foo; Value baz = Value(foo); } > rdmd ~/test.d /usr/include/dmd/phobos/std/variant.d(544): Error: static assert "Cannot store a const(long) in a VariantN!(8LU, long, double)" /home/col/test.d(9): instantiated from here: __ctor!(const(long)) Failed: ["dmd", "-v", "-o-", "/home/col/test.d", "-I/home/col"] The same issue occurs if `foo` is immutable, or a double or boolean. However, it does work with structs or slices: import std.variant; struct MyStruct { int a, b; } alias Value = Algebraic!(MyStruct, string); void main() { const MyStruct foo = MyStruct(1, 2); MyStruct bar = foo; Value baz = Value(foo); const string foo2 = "asdf"; string bar2 = foo2; Value baz2 = Value(foo2); }
@apz28 created dlang/phobos pull request #7427 "Fix Issue 15615" fixing this issue: - Fix Issue 15615 https://github.com/dlang/phobos/pull/7427
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10156 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB