mirror of
https://github.com/TartanLlama/optional.git
synced 2025-07-29 17:37:13 +02:00
Merge branch 'master' into swappable
This commit is contained in:
@ -41,7 +41,7 @@ tl::optional<image> 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.
|
The interface is the same as `std::optional`, but the following member functions are also defined. Explicit types are for clarity.
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
///
|
///
|
||||||
// optional - An implementation of std::optional with extensions
|
// 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
|
// To the extent possible under law, the author(s) have dedicated all
|
||||||
// copyright and related and neighboring rights to this software to the
|
// copyright and related and neighboring rights to this software to the
|
||||||
@ -16,7 +16,7 @@
|
|||||||
#define TL_OPTIONAL_HPP
|
#define TL_OPTIONAL_HPP
|
||||||
|
|
||||||
#define TL_OPTIONAL_VERSION_MAJOR 0
|
#define TL_OPTIONAL_VERSION_MAJOR 0
|
||||||
#define TL_OPTIONAL_VERSION_MINOR 2
|
#define TL_OPTIONAL_VERSION_MINOR 5
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -66,8 +66,8 @@ namespace tl {
|
|||||||
namespace detail {
|
namespace detail {
|
||||||
template<class T>
|
template<class T>
|
||||||
struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T>{};
|
struct is_trivially_copy_constructible : std::is_trivially_copy_constructible<T>{};
|
||||||
template<class T, class A>
|
|
||||||
#ifdef _GLIBCXX_VECTOR
|
#ifdef _GLIBCXX_VECTOR
|
||||||
|
template<class T, class A>
|
||||||
struct is_trivially_copy_constructible<std::vector<T,A>>
|
struct is_trivially_copy_constructible<std::vector<T,A>>
|
||||||
: std::is_trivially_copy_constructible<T>{};
|
: std::is_trivially_copy_constructible<T>{};
|
||||||
#endif
|
#endif
|
||||||
@ -1190,7 +1190,9 @@ public:
|
|||||||
class U, detail::enable_from_other<T, U, const U &> * = nullptr,
|
class U, detail::enable_from_other<T, U, const U &> * = nullptr,
|
||||||
detail::enable_if_t<std::is_convertible<const U &, T>::value> * = nullptr>
|
detail::enable_if_t<std::is_convertible<const U &, T>::value> * = nullptr>
|
||||||
optional(const optional<U> &rhs) {
|
optional(const optional<U> &rhs) {
|
||||||
this->construct(*rhs);
|
if (rhs.has_value()) {
|
||||||
|
this->construct(*rhs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \exclude
|
/// \exclude
|
||||||
@ -1198,7 +1200,9 @@ public:
|
|||||||
detail::enable_if_t<!std::is_convertible<const U &, T>::value> * =
|
detail::enable_if_t<!std::is_convertible<const U &, T>::value> * =
|
||||||
nullptr>
|
nullptr>
|
||||||
explicit optional(const optional<U> &rhs) {
|
explicit optional(const optional<U> &rhs) {
|
||||||
this->construct(*rhs);
|
if (rhs.has_value()) {
|
||||||
|
this->construct(*rhs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converting move constructor.
|
/// Converting move constructor.
|
||||||
@ -1207,7 +1211,9 @@ public:
|
|||||||
class U, detail::enable_from_other<T, U, U &&> * = nullptr,
|
class U, detail::enable_from_other<T, U, U &&> * = nullptr,
|
||||||
detail::enable_if_t<std::is_convertible<U &&, T>::value> * = nullptr>
|
detail::enable_if_t<std::is_convertible<U &&, T>::value> * = nullptr>
|
||||||
optional(optional<U> &&rhs) {
|
optional(optional<U> &&rhs) {
|
||||||
this->construct(std::move(*rhs));
|
if (rhs.has_value()) {
|
||||||
|
this->construct(std::move(*rhs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \exclude
|
/// \exclude
|
||||||
@ -1215,7 +1221,9 @@ public:
|
|||||||
class U, detail::enable_from_other<T, U, U &&> * = nullptr,
|
class U, detail::enable_from_other<T, U, U &&> * = nullptr,
|
||||||
detail::enable_if_t<!std::is_convertible<U &&, T>::value> * = nullptr>
|
detail::enable_if_t<!std::is_convertible<U &&, T>::value> * = nullptr>
|
||||||
explicit optional(optional<U> &&rhs) {
|
explicit optional(optional<U> &&rhs) {
|
||||||
this->construct(std::move(*rhs));
|
if (rhs.has_value()) {
|
||||||
|
this->construct(std::move(*rhs));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destroys the stored value if there is one.
|
/// Destroys the stored value if there is one.
|
||||||
@ -2252,6 +2260,7 @@ public:
|
|||||||
|
|
||||||
*this = nullopt;
|
*this = nullopt;
|
||||||
this->construct(std::forward<Args>(args)...);
|
this->construct(std::forward<Args>(args)...);
|
||||||
|
return value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Swaps this optional with the other.
|
/// Swaps this optional with the other.
|
||||||
|
Reference in New Issue
Block a user