move(): Give compiler an opportunity to optimize

Fix #75.
This commit is contained in:
Eugen Wissner 2019-02-01 06:33:41 +01:00
parent c1535e8752
commit 7af5c30820
2 changed files with 13 additions and 6 deletions

View File

@ -5,7 +5,7 @@
/** /**
* Algorithms that modify its arguments. * Algorithms that modify its arguments.
* *
* Copyright: Eugene Wissner 2017-2018. * Copyright: Eugene Wissner 2017-2019.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
@ -223,9 +223,16 @@ void move(T)(ref T source, ref T target)
/// ditto /// ditto
T move(T)(ref T source) @trusted T move(T)(ref T source) @trusted
{ {
static if (hasElaborateCopyConstructor!T || hasElaborateDestructor!T)
{
T target = void; T target = void;
moveEmplace(source, target); moveEmplace(source, target);
return target; return target;
}
else
{
return source;
}
} }
/// ///

View File

@ -660,7 +660,7 @@ if (isTypeTuple!Specs && NoDuplicates!Specs.length == Specs.length)
} }
/** /**
* Tells whether this $(D_PSYMBOL Variant) was initialized. * Tells whether this $(D_PSYMBOL Variant) is initialized.
* *
* Returns: $(D_KEYWORD true) if this $(D_PSYMBOL Variant) contains a * Returns: $(D_KEYWORD true) if this $(D_PSYMBOL Variant) contains a
* value, $(D_KEYWORD false) otherwise. * value, $(D_KEYWORD false) otherwise.
@ -765,7 +765,7 @@ if (isTypeTuple!Specs && NoDuplicates!Specs.length == Specs.length)
/** /**
* Returns $(D_PSYMBOL TypeInfo) corresponding to the current type. * Returns $(D_PSYMBOL TypeInfo) corresponding to the current type.
* *
* If this $(D_PSYMBOL Variant) isn't initialized, return * If this $(D_PSYMBOL Variant) isn't initialized, returns
* $(D_KEYWORD null). * $(D_KEYWORD null).
* *
* Returns: $(D_PSYMBOL TypeInfo) of the current type. * Returns: $(D_PSYMBOL TypeInfo) of the current type.