Bond
 
Loading...
Searching...
No Matches
bond::maybe< T, typename boost::disable_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::disable_if< detail::has_allocator< T > >::type >:
bond::detail::maybe_common< T >

Public Types

using value_type = T
 The type of the value that may be inside the maybe. More...
 

Public Member Functions

 maybe ()=default
 Create a maybe that holds nothing. More...
 
 maybe (const maybe &)=default
 Copy a maybe. More...
 
 maybe (maybe &&)=default
 Move a maybe. More...
 
 maybe (const T &value)
 Create a maybe that holds a value by copying value. More...
 
 maybe (T &&value)
 Create a maybe that holds a value by moving from value. More...
 
maybeoperator= (const T &value)
 Assign by copying a value. More...
 
maybeoperator= (T &&value)
 Move-assign from a value. More...
 
T & set_value ()
 Set the maybe to hold a value, if needed. More...
 
void swap (maybe &that)
 Swap this object with that. 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::disable_if< detail::has_allocator< T > >::type >

Type used for fields with default values of nothing.

This specialization is used for instance of T without 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

◆ 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/5]

template<typename T >
bond::maybe< T, typename boost::disable_if< detail::has_allocator< T > >::type >::maybe ( )
default

Create a maybe that holds nothing.

◆ maybe() [2/5]

template<typename T >
bond::maybe< T, typename boost::disable_if< detail::has_allocator< T > >::type >::maybe ( const maybe< T, typename boost::disable_if< detail::has_allocator< T > >::type > &  )
default

Copy a maybe.

◆ maybe() [3/5]

template<typename T >
bond::maybe< T, typename boost::disable_if< detail::has_allocator< T > >::type >::maybe ( maybe< T, typename boost::disable_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() [4/5]

template<typename T >
bond::maybe< T, typename boost::disable_if< detail::has_allocator< T > >::type >::maybe ( const T &  value)
explicit

Create a maybe that holds a value by copying value.

◆ maybe() [5/5]

template<typename T >
bond::maybe< T, typename boost::disable_if< detail::has_allocator< T > >::type >::maybe ( T &&  value)
explicit

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

◆ 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::disable_if< detail::has_allocator< T > >::type >::operator= ( const T &  value)

Assign by copying a value.

◆ operator=() [2/2]

template<typename T >
maybe & bond::maybe< T, typename boost::disable_if< detail::has_allocator< T > >::type >::operator= ( T &&  value)

Move-assign from a 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::disable_if< detail::has_allocator< T > >::type >::set_value ( )

Set the maybe to hold a value, if needed.

If this instance contains nothing, construct a default instance of T; otherwise, preserve the existing value.

Returns
A reference to the value.

◆ swap()

template<typename T >
void bond::maybe< T, typename boost::disable_if< detail::has_allocator< T > >::type >::swap ( maybe< T, typename boost::disable_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::disable_if< detail::has_allocator< T > >::type > &  lhs,
const maybe< T, typename boost::disable_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::disable_if< detail::has_allocator< T > >::type > &  lhs,
const maybe< T, typename boost::disable_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.