Fix bad usage of std::move

Issue #16 describes the problem and solution perfectly.

Updated tests to cover this.

Fixes #16
This commit is contained in:
Ben Clayton
2020-01-24 15:03:29 +00:00
committed by Ben Clayton
parent 3e6cfd6c2f
commit 9a9d46f6b6
2 changed files with 37 additions and 30 deletions

View File

@@ -17,7 +17,7 @@
#include <assert.h>
#include <type_traits>
#include <utility> // std::move
#include <utility> // std::move, std::forward
namespace dap {
@@ -104,7 +104,7 @@ optional<T>::optional(optional<U>&& other) : set(other.has_value()) {
template <typename T>
template <typename U /*= T*/, typename>
optional<T>::optional(U&& value) : val(std::move(value)), set(true) {}
optional<T>::optional(U&& value) : val(std::forward<U>(value)), set(true) {}
template <typename T>
T& optional<T>::value() {
@@ -153,7 +153,7 @@ optional<T>& optional<T>::operator=(optional&& other) noexcept {
template <typename T>
template <typename U /* = T */, typename>
optional<T>& optional<T>::operator=(U&& value) {
val = std::move(value);
val = std::forward<U>(value);
set = true;
return *this;
}