From 6d016806857bc5d4c129c9c0862088d930c107a2 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Mon, 8 Oct 2018 17:51:59 +0200 Subject: [PATCH] conv.emplace: Fix emplacing structs w/o this() --- source/tanya/container/array.d | 2 +- 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. */