Comparisons
operator==, !=, <, <=, >, >=(maybe)¶
namespace mitama {
// Compare two maybe objects
template< class T, class U >
constexpr bool operator==( const maybe<T>& lhs, const maybe<U>& rhs ); // (1)
template< class T, class U >
constexpr bool operator!=( const maybe<T>& lhs, const maybe<U>& rhs ); // (2)
template< class T, class U >
constexpr bool operator<( const maybe<T>& lhs, const maybe<U>& rhs ); // (3)
template< class T, class U >
constexpr bool operator<=( const maybe<T>& lhs, const maybe<U>& rhs ); // (4)
template< class T, class U >
constexpr bool operator>( const maybe<T>& lhs, const maybe<U>& rhs ); // (5)
template< class T, class U >
constexpr bool operator>=( const maybe<T>& lhs, const maybe<U>& rhs ); // (6)
// Compare a maybe object with a nothing
template< class T >
constexpr bool operator==( const maybe<T>& opt, nothing_t ) noexcept; // (7)
template< class T >
constexpr bool operator==( nothing_t, const maybe<T>& opt ) noexcept; // (8)
template< class T >
constexpr bool operator!=( const maybe<T>& opt, nothing_t ) noexcept; // (9)
template< class T >
constexpr bool operator!=( nothing_t, const maybe<T>& opt ) noexcept; // (10)
template< class T >
constexpr bool operator<( const maybe<T>& opt, nothing_t ) noexcept; // (11)
template< class T >
constexpr bool operator<( nothing_t, const maybe<T>& opt ) noexcept; // (12)
template< class T >
constexpr bool operator<=( const maybe<T>& opt, nothing_t ) noexcept; // (13)
template< class T >
constexpr bool operator<=( nothing_t, const maybe<T>& opt) noexcept; // (14)
template< class T >
constexpr bool operator>( const maybe<T>& opt, nothing_t ) noexcept; // (15)
template< class T >
constexpr bool operator>( nothing_t, const maybe<T>& opt ) noexcept; // (16)
template< class T >
constexpr bool operator>=( const maybe<T>& opt, nothing_t ) noexcept; // (17)
template< class T >
constexpr bool operator>=( nothing_t, const maybe<T>& opt ) noexcept; // (18)
// Compare a maybe object with a just(value)
template< class T, class U >
constexpr bool operator==( const maybe<T>& opt, just_t<U> const& some ); // (19)
template< class T, class U >
constexpr bool operator==( just_t<T> const& some, const maybe<U>& opt ); // (20)
template< class T, class U >
constexpr bool operator!=( const maybe<T>& opt, just_t<U> const& some ); // (21)
template< class T, class U >
constexpr bool operator!=( just_t<T> const& some, const maybe<U>& opt ); // (22)
template< class T, class U >
constexpr bool operator<( const maybe<T>& opt, just_t<U> const& some ); // (23)
template< class T, class U >
constexpr bool operator<( just_t<T> const& some, const maybe<U>& opt ); // (24)
template< class T, class U >
constexpr bool operator<=( const maybe<T>& opt, just_t<U> const& some ); // (25)
template< class T, class U >
constexpr bool operator<=( just_t<T> const& some, const maybe<U>& opt ); // (26)
template< class T, class U >
constexpr bool operator>( const maybe<T>& opt, just_t<U> const& some ); // (27)
template< class T, class U >
constexpr bool operator>( just_t<T> const& some, const maybe<U>& opt ); // (28)
template< class T, class U >
constexpr bool operator>=( const maybe<T>& opt, just_t<U> const& some ); // (29)
template< class T, class U >
constexpr bool operator>=( just_t<T> const& some, const maybe<U>& opt ); // (30)
// Compare a maybe object with a T
template< class T, class U >
constexpr bool operator==( const maybe<T>& opt, const U& value ); // (31)
template< class T, class U >
constexpr bool operator==( const T& value, const maybe<U>& opt ); // (32)
template< class T, class U >
constexpr bool operator!=( const maybe<T>& opt, const U& value ); // (33)
template< class T, class U >
constexpr bool operator!=( const T& value, const maybe<U>& opt ); // (34)
template< class T, class U >
constexpr bool operator<( const maybe<T>& opt, const U& value ); // (35)
template< class T, class U >
constexpr bool operator<( const T& value, const maybe<U>& opt ); // (36)
template< class T, class U >
constexpr bool operator<=( const maybe<T>& opt, const U& value ); // (37)
template< class T, class U >
constexpr bool operator<=( const T& value, const maybe<U>& opt); // (38)
template< class T, class U >
constexpr bool operator>( const maybe<T>& opt, const U& value ); // (39)
template< class T, class U >
constexpr bool operator>( const T& value, const maybe<U>& opt ); // (40)
template< class T, class U >
constexpr bool operator>=( const maybe<T>& opt, const U& value ); // (41)
template< class T, class U >
constexpr bool operator>=( const T& value, const maybe<U>& opt ); // (42)
}
Performs comparison operations on maybe objects.
1-6) Compares two maybe objects, lhs and rhs. The contained values are compared (using the corresponding operator of T and U) only if both lhs and rhs contain values.
Otherwise,
lhsis considered equal torhsif, and only if, bothlhsandrhsdo not contain a value.lhsis considered less thanrhsif, and only if,rhscontains a value andlhsdoes not.
7-18) Compares opt with a nothing. Equivalent to (1-6) when comparing to a maybe that does not contain a value.
19-30) Compares opt with a some := just_t(value). The values are compared (using the corresponding operator of T) only if opt contains a value.
Otherwise, opt is considered less than some.
If the corresponding comparison expression between opt.unwrap() and value is not well-formed, or if its result is not convertible to bool, the behavior is undefined.
31-42) Compares opt with a value. Equivalent to (19-30) expression opt ~ just(value).
Parameters
lhs, rhs, opt - a maybe object to compare
some - a just_t object to compare
value - value to compare to the contained value
Return value
-
If
bool(lhs) != bool(rhs), returns falseOtherwise, if
bool(lhs) == false(and sobool(rhs) == falseas well), returns trueOtherwise, returns
lhs.unwrap() == rhs.unwrap(). -
If
bool(lhs) != bool(rhs), returns trueOtherwise, if
bool(lhs) == false(and sobool(rhs) == falseas well), returns falseOtherwise, returns
lhs.unwrap() != rhs.unwrap(). -
If
bool(rhs) == falsereturns falseOtherwise, if
bool(lhs) == false, returns trueOtherwise returns
lhs.unwrap() < rhs.unwrap(). -
If
bool(lhs) == falsereturns trueOtherwise, if
bool(rhs) == false, returns falseOtherwise returns
lhs.unwrap() <= rhs.unwrap(). -
If
bool(lhs) == falsereturns falseOtherwise, if
bool(rhs) == false, returns trueOtherwise returns
lhs.unwrap() > rhs.unwrap(). -
If
bool(rhs) == falsereturns trueOtherwise, if
bool(lhs) == false, returns falseOtherwise returns
lhs.unwrap() >= rhs.unwrap(). -
Returns
opt.is_nothing(). -
Returns
opt.is_nothing(). -
Returns
opt.is_just(). -
Returns
opt.is_just(). -
Returns
false. -
Returns
opt.is_just(). -
Returns
opt.is_nothing(). -
Returns
true. -
Returns
opt.is_just(). -
Returns
false. -
Returns
true. -
Returns
opt.is_nothing(). -
Returns
opt.is_just() ? opt.unwrap() == some.value : false. -
Returns
opt.is_just() ? some.value == opt.unwrap() : false. -
Returns
opt.is_just() ? opt.unwrap() != some.value : true. -
Returns
opt.is_just() ? some.value != opt.unwrap() : true. -
Returns
opt.is_just() ? opt.unwrap() < some.value : true. -
Returns
opt.is_just() ? some.value < opt.unwrap() : false. -
Returns
opt.is_just() ? opt.unwrap() <= some.value : true. -
Returns
opt.is_just() ? some.value <= opt.unwrap() : false. -
Returns
opt.is_just() ? opt.unwrap() > some.value : false. -
Returns
opt.is_just() ? some.value > opt.unwrap() : true. -
Returns
opt.is_just() ? opt.unwrap() >= some.value : false. -
Returns
opt.is_just() ? some.value >= opt.unwrap() : true. -
Returns
opt == just(value). -
Returns
just(value) == opt. -
Returns
opt != just(value). -
Returns
just(value) != opt. -
Returns
opt < just(value). -
Returns
just(value) < opt. -
Returns
opt <= just(value). -
Returns
just(value) <= opt. -
Returns
opt > just(value). -
Returns
just(value) > opt. -
Returns
opt >= just(value). -
Returns
just(value) >= opt.
Note
some.value:valueis a private member ofjust_t(actually, cannot access to it).