1 #ifndef SAFE_ANY_VARNUMBER_H 2 #define SAFE_ANY_VARNUMBER_H 10 #include <type_traits> 26 typename std::enable_if<std::is_integral<T>::value || std::is_enum<T>::value>
::type*;
30 typename std::enable_if<!std::is_integral<T>::value && !std::is_enum<T>::value>::type*;
33 using EnableString =
typename std::enable_if<std::is_same<T, std::string>::value>::type*;
39 using EnableEnum =
typename std::enable_if<std::is_enum<T>::value>::type*;
43 typename std::enable_if<!std::is_arithmetic<T>::value && !std::is_enum<T>::value &&
44 !std::is_same<T, std::string>::value>::type*;
106 return _any.
type() ==
typeid(int64_t) ||
118 template <
typename T>
123 throw std::runtime_error(
"Any::cast failed because it is empty");
131 auto res = convert<T>();
134 throw std::runtime_error( res.error() );
140 const std::type_info&
type() const noexcept
161 template <
typename DST>
170 else if (
type ==
typeid(int64_t))
174 else if (
type ==
typeid(uint64_t))
178 else if (
type ==
typeid(
double))
183 return nonstd::make_unexpected( errorMsg<DST>() );
186 template <
typename DST>
189 using SafeAny::details::convertNumber;
194 if (
type ==
typeid(int64_t))
198 else if (
type ==
typeid(uint64_t))
202 else if (
type ==
typeid(
double))
207 return nonstd::make_unexpected( errorMsg<DST>() );
212 template <
typename DST>
215 using SafeAny::details::convertNumber;
219 if (
type ==
typeid(int64_t))
222 return static_cast<DST
>(out);
224 else if (
type ==
typeid(uint64_t))
227 return static_cast<DST
>(out);
230 return nonstd::make_unexpected( errorMsg<DST>() );
233 template <
typename DST>
236 return nonstd::make_unexpected( errorMsg<DST>() );
239 template <
typename T>
242 return StrCat(
"[Any::convert]: no known safe conversion between [",
249 #endif // VARNUMBER_H
bool empty() const noexcept
Returns true if *this has no contained object, otherwise false.
const std::type_info & type() const noexcept
Any(const SafeAny::SimpleString &str)
typename std::enable_if< std::is_enum< T >::value >::type * EnableEnum
Any(const T &value, EnableNonIntegral< T >=0)
ValueType any_cast(const any &operand)
Performs *any_cast<add_const_t<remove_reference_t<ValueType>>>(&operand), or throws bad_any_cast on f...
nonstd::expected< DST, std::string > convert(EnableEnum< DST >=0) const
std::string demangle(char const *name)
const std::type_info & castedType() const noexcept
Any & operator=(const Any &other)
bool empty() const noexcept
Any(const uint64_t &value)
nonstd::expected< DST, std::string > convert(EnableUnknownType< DST >=0) const
typename std::enable_if< std::is_integral< T >::value||std::is_enum< T >::value >::type * EnableIntegral
typename std::enable_if< std::is_same< T, std::string >::value >::type * EnableString
const std::type_info * _original_type
nonstd::expected< DST, std::string > convert(EnableArithmetic< DST >=0) const
const std::type_info & type() const noexcept
If *this has a contained object of type T, typeid(T); otherwise typeid(void).
Any(const T &value, EnableIntegral< T >=0)
nonstd::expected< DST, std::string > convert(EnableString< DST >=0) const
std::basic_string< CharT, Traits > to_string(basic_string_view< CharT, Traits > v)
typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_enum< T >::value &&!std::is_same< T, std::string >::value >::type * EnableUnknownType
std::string errorMsg() const
typename std::enable_if<!std::is_integral< T >::value &&!std::is_enum< T >::value >::type * EnableNonIntegral
Any(const std::string &str)
typename std::enable_if< std::is_arithmetic< T >::value >::type * EnableArithmetic