diff --git a/README.md b/README.md index 90d3000..87418ef 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ tl::optional get_cute_cat (const image& img) { } ``` -Full documentation available at [optional.tartanllama.xyz](https://optional.tartanllama.xyz) +Full documentation available at [tl.tartanllama.xyz](https://tl.tartanllama.xyz) The interface is the same as `std::optional`, but the following member functions are also defined. Explicit types are for clarity. diff --git a/tl/optional.hpp b/tl/optional.hpp index 28691bf..b3aaa15 100644 --- a/tl/optional.hpp +++ b/tl/optional.hpp @@ -1,7 +1,7 @@ /// // optional - An implementation of std::optional with extensions -// Written in 2017 by Simon Brand (@TartanLlama) +// Written in 2017 by Simon Brand (tartanllama@gmail.com, @TartanLlama) // // To the extent possible under law, the author(s) have dedicated all // copyright and related and neighboring rights to this software to the @@ -16,7 +16,7 @@ #define TL_OPTIONAL_HPP #define TL_OPTIONAL_VERSION_MAJOR 0 -#define TL_OPTIONAL_VERSION_MINOR 2 +#define TL_OPTIONAL_VERSION_MINOR 5 #include #include @@ -66,8 +66,8 @@ namespace tl { namespace detail { template struct is_trivially_copy_constructible : std::is_trivially_copy_constructible{}; - template #ifdef _GLIBCXX_VECTOR + template struct is_trivially_copy_constructible> : std::is_trivially_copy_constructible{}; #endif @@ -1190,7 +1190,9 @@ public: class U, detail::enable_from_other * = nullptr, detail::enable_if_t::value> * = nullptr> optional(const optional &rhs) { - this->construct(*rhs); + if (rhs.has_value()) { + this->construct(*rhs); + } } /// \exclude @@ -1198,7 +1200,9 @@ public: detail::enable_if_t::value> * = nullptr> explicit optional(const optional &rhs) { - this->construct(*rhs); + if (rhs.has_value()) { + this->construct(*rhs); + } } /// Converting move constructor. @@ -1207,7 +1211,9 @@ public: class U, detail::enable_from_other * = nullptr, detail::enable_if_t::value> * = nullptr> optional(optional &&rhs) { - this->construct(std::move(*rhs)); + if (rhs.has_value()) { + this->construct(std::move(*rhs)); + } } /// \exclude @@ -1215,7 +1221,9 @@ public: class U, detail::enable_from_other * = nullptr, detail::enable_if_t::value> * = nullptr> explicit optional(optional &&rhs) { - this->construct(std::move(*rhs)); + if (rhs.has_value()) { + this->construct(std::move(*rhs)); + } } /// Destroys the stored value if there is one. @@ -2252,6 +2260,7 @@ public: *this = nullopt; this->construct(std::forward(args)...); + return value(); } /// Swaps this optional with the other.