Bond
 
Loading...
Searching...
No Matches
bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type > Class Template Reference

Type used for fields with default values of nothing. More...

Inheritance diagram for bond::maybe< T, typename boost::enable_if< detail::has_allocator< T > >::type >:
bond::detail::maybe_common< T > bond::detail::allocator_holder< T::allocator_type >

Public Types

using allocator_type = typename T::allocator_type
 The type of the allocator in use. More...
 
using value_type = T
 The type of the value that may be inside the maybe. More...
 

Public Member Functions

 maybe (const maybe &)=default
 Copy a maybe. More...
 
 maybe (maybe &&)=default
 Move a maybe. More...
 
 maybe (const maybe &that, const allocator_type &alloc)
 Allocator-extended copy constructor. Uses alloc as the new allocator, makes a copy of that. More...
 
 maybe (maybe &&that, const allocator_type &alloc)
 Allocator-extended move constructor. Uses alloc as the new allocator, makes moved from that. More...
 
 maybe (const allocator_type &alloc)
 Construct a maybe that holds nothing, but remember the allocator so that it can be used to construct a T if needed. More...
 
 maybe (const T &value)
 Create a maybe that holds a copy of value. More...
 
 maybe (T &&value)
 Create a maybe that holds a value by moving from value. More...
 
maybe & operator= (const T &value)
 Assign by copying value. More...
 
maybe & operator= (T &&value)
 Move-assign from value. More...
 
T & set_value ()
 Set to non-empty, if needed. More...
 
void swap (maybe &that)
 Swap this object with that. More...
 
allocator_type get_allocator () const BOND_NOEXCEPT
 Get the allocator that this maybe uses. More...
 
bool is_nothing () const BOND_NOEXCEPT
 Check if this object contains nothing. More...
 
 operator bool () const BOND_NOEXCEPT
 Check if this object contains a value. More...
 
void set_nothing () BOND_NOEXCEPT
 Set to nothing. More...
 
template<typename... Args>
T & emplace (Args &&... args)
 Construct a value in place. More...
 
T & value ()
 Get a reference to the value. More...
 
const T & value () const
 Get a constant reference to the value. More...
 
T & value (const std::nothrow_t &) BOND_NOEXCEPT
 Get a reference to the value. More...
 
const T & value (const std::nothrow_t &) const BOND_NOEXCEPT
 Get a constant reference to the value. More...
 

Friends

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...
 

Detailed Description

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

Member Typedef Documentation

◆ 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

template<typename T >
using bond::detail::maybe_common< T >::value_type = T
inherited

The type of the value that may be inside the maybe.

Constructor & Destructor Documentation

◆ 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

Copy a maybe.

◆ 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

Member Function Documentation

◆ emplace()

template<typename T >
template<typename... Args>
T & bond::detail::maybe_common< T >::emplace ( Args &&...  args)
inherited

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()

template<typename T >
bool bond::detail::maybe_common< T >::is_nothing ( ) const
inherited

Check if this object contains nothing.

Returns
true if this holds nothing; otherwise false.

◆ operator bool()

template<typename T >
bond::detail::maybe_common< T >::operator bool ( ) const
explicitinherited

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)

Assign by copying 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()

template<typename T >
void bond::detail::maybe_common< T >::set_nothing ( )
inherited

Set to 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]

template<typename T >
T & bond::detail::maybe_common< T >::value ( )
inherited

Get a reference to the value.

Exceptions
CoreExceptionif the object contains nothing

◆ value() [2/4]

template<typename T >
const T & bond::detail::maybe_common< T >::value ( ) const
inherited

Get a constant reference to the value.

Exceptions
CoreExceptionif the object contains nothing

◆ value() [3/4]

template<typename T >
T & bond::detail::maybe_common< T >::value ( const std::nothrow_t &  )
inherited

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]

template<typename T >
const T & bond::detail::maybe_common< T >::value ( const std::nothrow_t &  ) const
inherited

Get a constant reference to the value.

Will never throw, but has undefined behavior if the object contains nothing.

Since
8.0.0

Friends And Related Function Documentation

◆ 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 inequality.

See operator==(const maybe_common&,const maybe_common&) for details about how maybes holding nothing are handled.

◆ 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.