Index: base/optional.h |
diff --git a/base/optional.h b/base/optional.h |
index 3adda97c0217ee5c05d8c07a0fbaab062714d03a..8cbbfe776d4a4f08bf6e78109f383237888cd5ca 100644 |
--- a/base/optional.h |
+++ b/base/optional.h |
@@ -34,7 +34,14 @@ namespace internal { |
template <typename T, bool = base::is_trivially_destructible<T>::value> |
struct OptionalStorage { |
- OptionalStorage() {} |
+ constexpr OptionalStorage() {} |
+ constexpr explicit OptionalStorage(const T& value) |
+ : is_null_(false), value_(value) {} |
+ constexpr explicit OptionalStorage(T&& value) |
+ : is_null_(false), value_(std::move(value)) {} |
+ template <class... Args> |
+ constexpr explicit OptionalStorage(base::in_place_t, Args&&... args) |
+ : is_null_(false), value_(std::forward<Args>(args)...) {} |
// When T is not trivially destructible we must call its |
danakj
2016/10/21 23:12:08
nit: whitespace above this to separate it since we
alshabalin
2016/10/22 07:47:52
Done.
|
// destructor before deallocating its memory. |
~OptionalStorage() { |
@@ -54,7 +61,14 @@ struct OptionalStorage { |
template <typename T> |
struct OptionalStorage<T, true> { |
- OptionalStorage() {} |
+ constexpr OptionalStorage() {} |
+ constexpr explicit OptionalStorage(const T& value) |
+ : is_null_(false), value_(value) {} |
+ constexpr explicit OptionalStorage(T&& value) |
+ : is_null_(false), value_(std::move(value)) {} |
+ template <class... Args> |
+ constexpr explicit OptionalStorage(base::in_place_t, Args&&... args) |
+ : is_null_(false), value_(std::forward<Args>(args)...) {} |
// When T is trivially destructible (i.e. its destructor does nothing) there |
danakj
2016/10/21 23:12:08
same
alshabalin
2016/10/22 07:47:51
Done.
|
// is no need to call it. Explicitly defaulting the destructor means it's not |
// user-provided. Those two together make this destructor trivial. |
@@ -91,7 +105,7 @@ class Optional { |
using value_type = T; |
constexpr Optional() = default; |
- Optional(base::nullopt_t) : Optional() {} |
+ constexpr Optional(base::nullopt_t) : Optional() {} |
Optional(const Optional& other) { |
if (!other.storage_.is_null_) |
@@ -103,14 +117,13 @@ class Optional { |
Init(std::move(other.value())); |
} |
- Optional(const T& value) { Init(value); } |
+ constexpr Optional(const T& value) : storage_(value) {} |
- Optional(T&& value) { Init(std::move(value)); } |
+ constexpr Optional(T&& value) : storage_(std::move(value)) {} |
template <class... Args> |
- explicit Optional(base::in_place_t, Args&&... args) { |
- emplace(std::forward<Args>(args)...); |
- } |
+ constexpr explicit Optional(base::in_place_t, Args&&... args) |
+ : storage_(base::in_place, std::forward<Args>(args)...) {} |
~Optional() = default; |