Type used for fields with default values of nothing
.
More...
|
bool | operator== (const maybe &lhs, const maybe &rhs) |
| Compares two maybes for value equality. More...
|
|
bool | operator!= (const maybe &lhs, const maybe &rhs) |
| Compares two maybes for value inequality. More...
|
|
template<typename T>
class bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >
Type used for fields with default values of nothing
.
This specialization is used for instances of T with allocators.
See the User's Manual for more details about default values of nothing
.
- See also
- For details of maybe's comparison operators, see
◆ allocator_type
template<typename T >
using bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::allocator_type = typename T::allocator_type |
The type of the allocator in use.
◆ value_type
The type of the value that may be inside the maybe.
◆ maybe() [1/7]
template<typename T >
bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::maybe |
( |
const maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > & |
| ) |
|
|
default |
◆ maybe() [2/7]
template<typename T >
bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::maybe |
( |
maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > && |
| ) |
|
|
default |
Move a maybe.
- Note
- Unlike
std::optional
, a moved-from maybe holds nothing (compared to a moved-from T).
◆ maybe() [3/7]
template<typename T >
bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::maybe |
( |
const maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > & |
that, |
|
|
const allocator_type & |
alloc |
|
) |
| |
Allocator-extended copy constructor. Uses alloc as the new allocator, makes a copy of that
.
◆ maybe() [4/7]
template<typename T >
bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::maybe |
( |
maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > && |
that, |
|
|
const allocator_type & |
alloc |
|
) |
| |
Allocator-extended move constructor. Uses alloc as the new allocator, makes moved from that
.
- Note
- Unlike
std::optional
, a moved-from maybe holds nothing (compared to a moved-from T).
◆ maybe() [5/7]
template<typename T >
bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::maybe |
( |
const allocator_type & |
alloc | ) |
|
|
explicit |
Construct a maybe that holds nothing, but remember the allocator so that it can be used to construct a T if needed.
- Since
- 8.0.0
◆ maybe() [6/7]
template<typename T >
bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::maybe |
( |
const T & |
value | ) |
|
|
explicit |
Create a maybe that holds a copy of value
.
◆ maybe() [7/7]
template<typename T >
bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::maybe |
( |
T && |
value | ) |
|
Create a maybe that holds a value by moving from value
.
- Since
- 8.0.0
◆ emplace()
template<typename T >
template<typename... Args>
Construct a value in place.
- Since
- 8.0.0
◆ get_allocator()
template<typename T >
allocator_type bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::get_allocator |
( |
| ) |
const |
Get the allocator that this maybe uses.
- Since
- 8.0.0
◆ is_nothing()
Check if this object contains nothing.
- Returns
- true if this holds nothing; otherwise false.
◆ operator bool()
Check if this object contains a value.
- Returns
- true if this object holds a value; otherwise false.
- Since
- 8.0.0
◆ operator=() [1/2]
template<typename T >
maybe & bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::operator= |
( |
const T & |
value | ) |
|
◆ operator=() [2/2]
template<typename T >
maybe & bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::operator= |
( |
T && |
value | ) |
|
Move-assign from value
.
- Since
- 8.0.0
◆ set_nothing()
◆ set_value()
template<typename T >
T & bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::set_value |
( |
| ) |
|
Set to non-empty, if needed.
If this object contains nothing, construct an instance of T, passing it the saved allocator; otherwise, preserve the existing value.
- Returns
- A reference to the value.
◆ swap()
template<typename T >
void bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >::swap |
( |
maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > & |
that | ) |
|
Swap this object with that
.
◆ value() [1/4]
Get a reference to the value.
- Exceptions
-
◆ value() [2/4]
Get a constant reference to the value.
- Exceptions
-
◆ value() [3/4]
Get a reference to the value.
Will never throw, but has undefined behavior if the object contains nothing.
- Since
- 8.0.0
◆ value() [4/4]
Get a constant reference to the value.
Will never throw, but has undefined behavior if the object contains nothing.
- Since
- 8.0.0
◆ operator!=
template<typename T >
bool operator!= |
( |
const maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > & |
lhs, |
|
|
const maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > & |
rhs |
|
) |
| |
|
friend |
◆ operator==
template<typename T >
bool operator== |
( |
const maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > & |
lhs, |
|
|
const maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > & |
rhs |
|
) |
| |
|
friend |
Compares two maybes for value equality.
- Returns
- true if both maybes hold nothing; returns false if one maybe holds nothing and the other holds a values; otherwise, calls operator== with the two values.