|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_UTILS_CONTAINERS_OPTIONAL_H_
2 #define GENESIS_UTILS_CONTAINERS_OPTIONAL_H_
73 #ifndef GENESIS_OPTIONAL_CPLUSPLUS
74 # if defined(_MSVC_LANG ) && !defined(__clang__)
75 # define GENESIS_OPTIONAL_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG )
77 # define GENESIS_OPTIONAL_CPLUSPLUS __cplusplus
82 #if ( GENESIS_OPTIONAL_CPLUSPLUS >= 201703L ) && defined( __has_include )
83 # if __has_include( <optional> )
84 # define GENESIS_OPTIONAL_HAVE_STD_OPTIONAL 1
86 # define GENESIS_OPTIONAL_HAVE_STD_OPTIONAL 0
89 # define GENESIS_OPTIONAL_HAVE_STD_OPTIONAL 0
95 #define GENESIS_OPTIONAL_USES_STD_OPTIONAL GENESIS_OPTIONAL_HAVE_STD_OPTIONAL
101 #if GENESIS_OPTIONAL_USES_STD_OPTIONAL
114 using Optional = std::optional<T>;
115 using BadOptionalAccess = std::bad_optional_access;
118 using std::nullopt_t;
129 #else // GENESIS_OPTIONAL_USES_STD_OPTIONAL
149 const nullopt_t
nullopt(( nullopt_t::init() ));
159 : std::logic_error(
"Bad Optional access" )
177 template<
typename T >
193 : has_value_( false )
197 : has_value_( false )
207 , value_ ( std::move( arg ))
215 value_ = other.
value();
223 if ( other.has_value() ){
224 value_ = std::move( other.value() );
244 value_ = std::move( other );
253 value_ = other.
value();
261 has_value_ = other.has_value();
262 if ( other.has_value() ) {
263 value_ = std::move( other.value() );
305 explicit operator bool()
const
354 template<
typename V >
355 void initialize_( V
const &
value )
373 template<
typename T,
typename U >
376 return bool(x) != bool(y) ? false : bool(x) ==
false ? true : *x == *y;
379 template<
typename T,
typename U >
385 template<
typename T,
typename U >
388 return (!y) ? false : (!x) ?
true : *x < *y;
391 template<
typename T,
typename U >
397 template<
typename T,
typename U >
403 template<
typename T,
typename U >
413 template<
typename T >
419 template<
typename T >
425 template<
typename T >
431 template<
typename T >
437 template<
typename T >
443 template<
typename T >
449 template<
typename T >
455 template<
typename T >
461 template<
typename T >
467 template<
typename T >
473 template<
typename T >
479 template<
typename T >
489 template<
typename T,
typename U >
492 return bool(x) ? *x == v :
false;
495 template<
typename T,
typename U >
498 return bool(x) ? v == *x :
false;
501 template<
typename T,
typename U >
504 return bool(x) ? *x != v :
true;
507 template<
typename T,
typename U >
510 return bool(x) ? v != *x :
true;
513 template<
typename T,
typename U >
516 return bool(x) ? *x < v :
true;
519 template<
typename T,
typename U >
522 return bool(x) ? v < *x :
false;
525 template<
typename T,
typename U >
528 return bool(x) ? *x <= v :
true;
531 template<
typename T,
typename U >
534 return bool(x) ? v <= *x :
false;
537 template<
typename T,
typename U >
540 return bool(x) ? *x > v :
false;
543 template<
typename T,
typename U >
546 return bool(x) ? v > *x :
true;
549 template<
typename T,
typename U >
552 return bool(x) ? *x >= v :
false;
555 template<
typename T,
typename U >
558 return bool(x) ? v >= *x :
true;
565 template<
typename T >
574 template<
typename T >
583 #endif // GENESIS_OPTIONAL_USES_STD_OPTIONAL
585 #endif // include guard
bool operator>(Optional< T > const &x, Optional< U > const &y)
Optional(Optional< U > &&other)
value_type * operator->()
bool operator>=(Optional< T > const &x, Optional< U > const &y)
const nullopt_t nullopt((nullopt_t::init()))
Optional to indicate an empty value.
const value_type & operator*() const
void swap(Color &lhs, Color &rhs)
Simplistic optional: requires T to be default constructible, copyable.
const value_type & value() const
Optional & operator=(Optional< U > &&other)
Optional & operator=(Optional< U > const &other)
bool operator!=(Color const &lhs, Color const &rhs)
value_type value_or(U const &v) const
Optional & operator=(T &&other)
A single variant at a position in a chromosome, along with SampleCounts for a set of samples.
Optional(Optional< U > const &other)
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
const value_type * operator->() const
bool operator<=(Optional< T > const &x, Optional< U > const &y)
Optional access error for empty values.
bool operator<(Optional< T > const &x, Optional< U > const &y)
Optional & operator=(nullopt_t)
bool operator==(Color const &lhs, Color const &rhs)
Optional< T > make_optional(T const &v)
Convenience function to create an Optional.
Optional & operator=(T const &other)
void swap(Optional< T > &x, Optional< T > &y)