24 #include "VariantSrc.hpp"
27 #include <type_traits>
46 template<
typename T >
49 using data_t = variantSrc::variant< T, detail::Empty >;
55 explicit Option() : m_data( detail::Empty() )
63 Option( T data ) : m_data( std::move( data ) )
70 operator=(
Option && other )
72 if( other.has_value() )
74 m_data.template emplace< 0 >( std::move( other.get() ) );
78 m_data.template emplace< 1 >( detail::Empty() );
84 operator=(
Option const & other )
86 if( other.has_value() )
88 m_data.template emplace< 0 >( other.get() );
92 m_data.template emplace< 1 >( detail::Empty() );
98 operator==(
Option const & other )
const
102 return !other.has_value();
106 if( !other.has_value() )
112 return get() == other.get();
118 operator!=(
Option const & other )
const
120 return !( *
this == other );
129 return m_data.index() == 0;
135 operator bool()
const
149 return variantSrc::template get< T >( m_data );
161 return variantSrc::template get< T >( m_data );
165 template<
typename T >
166 Option< typename std::decay< T >::type >
167 makeOption( T && val )
169 return Option< typename std::decay< T >::type >(
170 std::forward< T >( val ) );