18 #ifndef NONSTD_ANY_LITE_HPP 19 #define NONSTD_ANY_LITE_HPP 24 #define any_lite_VERSION "0.0.0" 32 #define any_CPP11_OR_GREATER ( __cplusplus >= 201103L ) 33 #define any_CPP14_OR_GREATER ( __cplusplus >= 201402L ) 34 #define any_CPP17_OR_GREATER ( __cplusplus >= 201700L ) 37 #define any_BETWEEN( v, lo, hi ) ( lo <= v && v < hi ) 39 #if defined(_MSC_VER) && !defined(__clang__) 40 # define any_COMPILER_MSVC_VERSION (_MSC_VER / 100 - 5 - (_MSC_VER < 1900)) 42 # define any_COMPILER_MSVC_VERSION 0 46 # define any_COMPILER_GNUC_VERSION __GNUC__ 48 # define any_COMPILER_GNUC_VERSION 0 53 #if any_CPP11_OR_GREATER || any_COMPILER_MSVC_VERSION >= 10 54 # define any_HAVE_NULLPTR 1 57 #if any_CPP11_OR_GREATER || any_COMPILER_MSVC_VERSION >= 12 58 # define any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG 1 59 # define any_HAVE_INITIALIZER_LIST 1 62 #if any_CPP11_OR_GREATER || any_COMPILER_MSVC_VERSION >= 14 63 # define any_HAVE_CONSTEXPR_11 1 64 # define any_HAVE_NOEXCEPT 1 69 #if any_CPP14_OR_GREATER 70 # define any_HAVE_CONSTEXPR_14 1 77 #if any_COMPILER_GNUC_VERSION 78 # define any_HAVE_TR1_TYPE_TRAITS 1 79 # define any_HAVE_TR1_ADD_CONST 1 80 # define any_HAVE_TR1_REMOVE_REFERENCE 1 83 #if any_CPP11_OR_GREATER || any_COMPILER_MSVC_VERSION >= 9 84 # define any_HAVE_TYPE_TRAITS 1 85 # define any_HAVE_STD_ADD_CONST 1 86 # define any_HAVE_STD_REMOVE_REFERENCE 1 91 #if any_COMPILER_MSVC_VERSION >= 14 92 # undef any_CPP11_OR_GREATER 93 # define any_CPP11_OR_GREATER 1 98 #if any_HAVE_CONSTEXPR_11 99 # define any_constexpr constexpr 101 # define any_constexpr 104 #if any_HAVE_CONSTEXPR_14 105 # define any_constexpr14 constexpr 107 # define any_constexpr14 110 #if any_HAVE_NOEXCEPT 111 # define any_noexcept noexcept 113 # define any_noexcept 117 # define any_nullptr nullptr 119 # define any_nullptr NULL 124 #if ! any_HAVE_NULLPTR 128 #if any_HAVE_INITIALIZER_LIST 129 # include <initializer_list> 132 #if any_HAVE_TYPE_TRAITS 133 # include <type_traits> 134 #elif any_HAVE_TR1_TYPE_TRAITS 135 # include <tr1/type_traits> 142 #if ! nonstd_lite_HAVE_IN_PLACE_TYPES 151 template< std::
size_t I >
164 template< std::
size_t I >
172 #define nonstd_lite_in_place_type_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> ) 173 #define nonstd_lite_in_place_index_t(T) nonstd::in_place_t(&)( nonstd::detail::in_place_index_tag<I> ) 175 #define nonstd_lite_HAVE_IN_PLACE_TYPES 1 179 #endif // nonstd_lite_HAVE_IN_PLACE_TYPES 191 #if any_HAVE_STD_ADD_CONST 193 using std::add_const;
195 #elif any_HAVE_TR1_ADD_CONST 197 using std::tr1::add_const;
203 #endif // any_HAVE_ADD_CONST 205 #if any_HAVE_STD_REMOVE_REFERENCE 207 using std::remove_reference;
209 #elif any_HAVE_TR1_REMOVE_REFERENCE 211 using std::tr1::remove_reference;
218 #endif // any_HAVE_STD_REMOVE_REFERENCE 225 #if any_CPP11_OR_GREATER 228 virtual const char*
what()
const throw()
231 return "any-lite: bad any_cast";
243 : content( rhs.content ? rhs.content->clone() :
any_nullptr )
246 #if any_CPP11_OR_GREATER 249 : content( std::move( rhs.content ) )
259 template<
class T,
class... Args,
typename =
typename std::enable_if< std::is_constructible<T, Args...>::value >
::type >
261 : content(
new holder<T>( T( std::forward<Args>(
args)... ) ) )
264 template<
class T,
class U,
class... Args,
typename =
typename std::enable_if< std::is_constructible<T, std::initializer_list<U>&, Args...>::value >
::type >
266 : content(
new holder<T>( T( il, std::forward<Args>(
args)... ) ) )
271 template<
class ValueType >
272 any( ValueType
const & value )
273 : content( new
holder<ValueType>( value ) )
276 #endif // any_CPP11_OR_GREATER 285 any( rhs ).
swap( *
this );
289 #if any_CPP11_OR_GREATER 293 any( std::move( rhs ) ).swap( *
this );
298 any & operator=( ValueType && rhs )
300 any( std::forward<ValueType>( rhs ) ).swap( *
this );
304 template<
class T,
class... Args >
305 void emplace( Args && ...
args )
307 any( T( std::forward<Args>(
args)... ) ).swap( *
this );
310 template<
class T,
class U,
class... Args,
typename =
typename std::enable_if< std::is_constructible<T, std::initializer_list<U>&, Args...>::value >
::type >
311 void emplace( std::initializer_list<U> il, Args&&...
args )
313 any( T( il, std::forward<Args>(
args)... ) ).swap( *
this );
318 template<
class ValueType >
321 any( rhs ).
swap( *
this );
325 #endif // any_CPP11_OR_GREATER 344 return has_value() ? content->type() :
typeid( void );
351 template<
class ValueType >
357 template<
class ValueType >
371 virtual std::type_info
const &
type()
const = 0;
376 template<
typename ValueType >
384 #if any_CPP11_OR_GREATER 386 : held( std::move(
value ) )
390 virtual std::type_info
const &
type()
const 392 return typeid( ValueType );
397 return new holder( held );
411 #if any_CPP11_OR_GREATER 413 template<
class T,
class ...Args >
416 return any( in_place<T>, std::forward<Args>(
args)...);
419 template<
class T,
class U,
class ...Args >
422 return any( in_place<T>, il, std::forward<Args>(
args)...);
425 #endif // any_CPP11_OR_GREATER 427 #if any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG 428 template< class ValueType, typename = typename std::enable_if< std::is_reference<ValueType>::value || std::is_copy_constructible<ValueType>::value >
::type >
430 template<
class ValueType >
444 #if any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG 445 template< class ValueType, typename = typename std::enable_if< std::is_reference<ValueType>::value || std::is_copy_constructible<ValueType>::value >
::type >
447 template<
class ValueType >
461 #if any_CPP11_OR_GREATER 463 #if any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG 464 template< class ValueType, typename = typename std::enable_if< std::is_reference<ValueType>::value || std::is_copy_constructible<ValueType>::value >
::type >
466 template<
class ValueType >
480 #endif // any_CPP11_OR_GREATER 482 template<
class ValueType >
485 return operand !=
any_nullptr && operand->type() ==
typeid(ValueType) ? operand->to_ptr<ValueType>() :
any_nullptr;
488 template<
class ValueType >
491 return operand !=
any_nullptr && operand->type() ==
typeid(ValueType) ? operand->to_ptr<ValueType>() :
any_nullptr;
496 using namespace any_lite;
500 #endif // NONSTD_ANY_LITE_HPP void swap(any &x, any &y) any_noexcept
any & operator=(ValueType const &rhs)
bool has_value() const any_noexcept
const ValueType * to_ptr() const
ValueType * any_cast(any *operand) any_noexcept
any make_any(Args &&...args)
any(ValueType const &value)
TFSIMD_FORCE_INLINE const tfScalar & y() const
void reset() any_noexcept
virtual placeholder * clone() const
holder(ValueType const &value)
virtual std::type_info const & type() const
virtual const char * what() const
#define nonstd_lite_in_place_type_t(T)
void swap(any &rhs) any_noexcept
TFSIMD_FORCE_INLINE const tfScalar & x() const
any_constexpr any() any_noexcept
any & operator=(any const &rhs)
const std::type_info & type() const any_noexcept
in_place_t in_place(detail::in_place_type_tag< T >=detail::in_place_type_tag< T >())