diff options
| author | Eugen Wissner <belka@caraus.de> | 2018-10-08 17:51:59 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2018-10-08 17:51:59 +0200 |
| commit | 6d016806857bc5d4c129c9c0862088d930c107a2 (patch) | |
| tree | f91941a88f7634061a69af31c136a7e02a89de92 /source | |
| parent | 4f9927a8c3e9375e796008a534726483dfb17e2b (diff) | |
| download | tanya-6d016806857bc5d4c129c9c0862088d930c107a2.tar.gz | |
conv.emplace: Fix emplacing structs w/o this()
Diffstat (limited to 'source')
| -rw-r--r-- | source/tanya/container/array.d | 2 | ||||
| -rw-r--r-- | source/tanya/conv.d | 21 |
2 files changed, 20 insertions, 3 deletions
diff --git a/source/tanya/container/array.d b/source/tanya/container/array.d index 2501fad..f8c1032 100644 --- a/source/tanya/container/array.d +++ b/source/tanya/container/array.d @@ -1587,7 +1587,7 @@ struct Array(T) @nogc nothrow pure @safe unittest { - struct SWithDtor + static struct SWithDtor { ~this() @nogc nothrow pure @safe { diff --git a/source/tanya/conv.d b/source/tanya/conv.d index 8eeb250..57580ff 100644 --- a/source/tanya/conv.d +++ b/source/tanya/conv.d @@ -190,13 +190,17 @@ do static assert(is(typeof({ static T t; })), "Default constructor is disabled"); } + else static if (is(typeof(result.__ctor(args)))) + { + result.__ctor(args); + } else static if (is(typeof(T(args)))) { *result = T(args); } - else static if (is(typeof(result.__ctor(args)))) + else static if (is(typeof(*result = args))) // Args.length == 1, assignment { - result.__ctor(args); + *result = args; } else { @@ -245,6 +249,19 @@ do static assert(is(typeof(emplace!F((void[]).init)))); } +// Can emplace structs without a constructor +@nogc nothrow pure @safe unittest +{ + static struct SWithDtor + { + ~this() @nogc nothrow pure @safe + { + } + } + static assert(is(typeof(emplace!SWithDtor(null, SWithDtor())))); + static assert(is(typeof(emplace!SWithDtor(null)))); +} + /** * Thrown if a type conversion fails. */ |
