feat support ulib::any
All checks were successful
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m1s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m42s
linux-x64-gcc / linux-gcc (push) Successful in 1m47s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m59s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m56s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 2m2s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 3m16s

This commit is contained in:
tqcq 2024-01-06 13:56:12 +08:00
parent 1e40424caf
commit bb4d3c68be

View File

@ -15,7 +15,9 @@
#define any_lite_MINOR 4
#define any_lite_PATCH 0
#define any_lite_VERSION any_STRINGIFY(any_lite_MAJOR) "." any_STRINGIFY(any_lite_MINOR) "." any_STRINGIFY(any_lite_PATCH)
#define any_lite_VERSION \
any_STRINGIFY(any_lite_MAJOR) "." any_STRINGIFY( \
any_lite_MINOR) "." any_STRINGIFY(any_lite_PATCH)
#define any_STRINGIFY(x) any_STRINGIFY_(x)
#define any_STRINGIFY_(x) #x
@ -87,7 +89,9 @@
#define any_HAVE_STD_ANY 0
#endif
#define any_USES_STD_ANY ( (any_CONFIG_SELECT_ANY == any_ANY_STD) || ((any_CONFIG_SELECT_ANY == any_ANY_DEFAULT) && any_HAVE_STD_ANY) )
#define any_USES_STD_ANY \
((any_CONFIG_SELECT_ANY == any_ANY_STD) \
|| ((any_CONFIG_SELECT_ANY == any_ANY_DEFAULT) && any_HAVE_STD_ANY))
//
// in_place: code duplicated in any-lite, expected-lite, optional-lite, value-ptr-lite, variant-lite:
@ -105,19 +109,22 @@
namespace nonstd {
using std::in_place;
using std::in_place_type;
using std::in_place_index;
using std::in_place_t;
using std::in_place_type_t;
using std::in_place_index_t;
using std::in_place_t;
using std::in_place_type;
using std::in_place_type_t;
#define nonstd_lite_in_place_t(T) std::in_place_t
#define nonstd_lite_in_place_type_t(T) std::in_place_type_t<T>
#define nonstd_lite_in_place_index_t(K) std::in_place_index_t<K>
#define nonstd_lite_in_place( T) std::in_place_t{}
#define nonstd_lite_in_place_type( T) std::in_place_type_t<T>{}
#define nonstd_lite_in_place_index(K) std::in_place_index_t<K>{}
#define nonstd_lite_in_place(T) \
std::in_place_t {}
#define nonstd_lite_in_place_type(T) \
std::in_place_type_t<T> {}
#define nonstd_lite_in_place_index(K) \
std::in_place_index_t<K> {}
}// namespace nonstd
@ -139,34 +146,41 @@ struct in_place_index_tag {};
struct in_place_t {};
template<class T>
inline in_place_t in_place( detail::in_place_type_tag<T> = detail::in_place_type_tag<T>() )
inline in_place_t
in_place(detail::in_place_type_tag<T> = detail::in_place_type_tag<T>())
{
return in_place_t();
}
template<std::size_t K>
inline in_place_t in_place( detail::in_place_index_tag<K> = detail::in_place_index_tag<K>() )
inline in_place_t
in_place(detail::in_place_index_tag<K> = detail::in_place_index_tag<K>())
{
return in_place_t();
}
template<class T>
inline in_place_t in_place_type( detail::in_place_type_tag<T> = detail::in_place_type_tag<T>() )
inline in_place_t
in_place_type(detail::in_place_type_tag<T> = detail::in_place_type_tag<T>())
{
return in_place_t();
}
template<std::size_t K>
inline in_place_t in_place_index( detail::in_place_index_tag<K> = detail::in_place_index_tag<K>() )
inline in_place_t
in_place_index(detail::in_place_index_tag<K> = detail::in_place_index_tag<K>())
{
return in_place_t();
}
// mimic templated typedef:
#define nonstd_lite_in_place_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> )
#define nonstd_lite_in_place_type_t( T) nonstd::in_place_t(&)( nonstd::detail::in_place_type_tag<T> )
#define nonstd_lite_in_place_index_t(K) nonstd::in_place_t(&)( nonstd::detail::in_place_index_tag<K> )
#define nonstd_lite_in_place_t(T) \
nonstd::in_place_t (&)(nonstd::detail::in_place_type_tag<T>)
#define nonstd_lite_in_place_type_t(T) \
nonstd::in_place_t (&)(nonstd::detail::in_place_type_tag<T>)
#define nonstd_lite_in_place_index_t(K) \
nonstd::in_place_t (&)(nonstd::detail::in_place_index_tag<K>)
#define nonstd_lite_in_place(T) nonstd::in_place_type<T>
#define nonstd_lite_in_place_type(T) nonstd::in_place_type<T>
@ -190,10 +204,10 @@ namespace nonstd {
using std::any;
using std::any_cast;
using std::bad_any_cast;
using std::make_any;
using std::swap;
using std::bad_any_cast;
}
}// namespace nonstd
#else// any_USES_STD_ANY
@ -225,16 +239,19 @@ namespace nonstd {
#define any_COMPILER_MSVC_VERSION 0
#endif
#define any_COMPILER_VERSION( major, minor, patch ) ( 10 * ( 10 * (major) + (minor) ) + (patch) )
#define any_COMPILER_VERSION(major, minor, patch) \
(10 * (10 * (major) + (minor)) + (patch))
#if defined(__clang__)
# define any_COMPILER_CLANG_VERSION any_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__)
#define any_COMPILER_CLANG_VERSION \
any_COMPILER_VERSION(__clang_major__, __clang_minor__, __clang_patchlevel__)
#else
#define any_COMPILER_CLANG_VERSION 0
#endif
#if defined(__GNUC__) && !defined(__clang__)
# define any_COMPILER_GNUC_VERSION any_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
#define any_COMPILER_GNUC_VERSION \
any_COMPILER_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
#else
#define any_COMPILER_GNUC_VERSION 0
#endif
@ -263,8 +280,7 @@ namespace nonstd {
// Presence of C++11 language features:
#define any_HAVE_CONSTEXPR_11 any_CPP11_140
#define any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG \
any_CPP11_120
#define any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG any_CPP11_120
#define any_HAVE_INITIALIZER_LIST any_CPP11_120
#define any_HAVE_NOEXCEPT any_CPP11_140
#define any_HAVE_NULLPTR any_CPP11_100
@ -356,8 +372,7 @@ namespace nonstd {
#define any_REQUIRES_T(...) \
, typename std::enable_if<(__VA_ARGS__), int>::type = 0
#define any_REQUIRES_R(R, ...) \
typename std::enable_if<__VA_ARGS__, R>::type
#define any_REQUIRES_R(R, ...) typename std::enable_if<__VA_ARGS__, R>::type
#define any_REQUIRES_A(...) \
, typename std::enable_if<__VA_ARGS__, void *>::type = nullptr
@ -368,7 +383,8 @@ namespace nonstd {
// any:
//
namespace nonstd { namespace any_lite {
namespace nonstd {
namespace any_lite {
// C++11 emulation:
@ -384,7 +400,10 @@ using std::tr1::add_const;
#else
template< class T > struct add_const { typedef const T type; };
template<class T>
struct add_const {
typedef const T type;
};
#endif// any_HAVE_ADD_CONST
@ -398,8 +417,15 @@ using std::tr1::remove_reference;
#else
template< class T > struct remove_reference { typedef T type; };
template< class T > struct remove_reference<T&> { typedef T type; };
template<class T>
struct remove_reference {
typedef T type;
};
template<class T>
struct remove_reference<T &> {
typedef T type;
};
#endif// any_HAVE_REMOVE_REFERENCE
@ -415,8 +441,7 @@ namespace detail {
#if !any_CONFIG_NO_EXCEPTIONS
class bad_any_cast : public std::bad_cast
{
class bad_any_cast : public std::bad_cast {
public:
#if any_CPP11_OR_GREATER
virtual const char *what() const any_noexcept any_override
@ -430,12 +455,9 @@ public:
#endif// any_CONFIG_NO_EXCEPTIONS
class any
{
class any {
public:
any_constexpr any() any_noexcept
: content( any_nullptr )
{}
any_constexpr any() any_noexcept : content(any_nullptr) {}
any(any const &other)
: content(other.content ? other.content->clone() : any_nullptr)
@ -443,49 +465,46 @@ public:
#if any_CPP11_OR_GREATER
any( any && other ) any_noexcept
: content( std::move( other.content ) )
any(any &&other) any_noexcept : content(std::move(other.content))
{
other.content = any_nullptr;
}
template<
class ValueType, class T = typename std::decay<ValueType>::type
any_REQUIRES_T( ! std::is_same<T, any>::value )
>
template<class ValueType,
class T = typename std::decay<ValueType>::type any_REQUIRES_T(
!std::is_same<T, any>::value)>
any(ValueType &&value) any_noexcept
: content(new holder<T>(std::forward<ValueType>(value)))
{}
template<
class T, class... Args
any_REQUIRES_T( std::is_constructible<T, Args&&...>::value )
>
template<class T,
class... Args any_REQUIRES_T(
std::is_constructible<T, Args &&...>::value)>
explicit any(nonstd_lite_in_place_type_t(T), Args &&...args)
: content(new holder<T>(T(std::forward<Args>(args)...)))
{}
template<
class T, class U, class... Args
any_REQUIRES_T( std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value )
>
explicit any( nonstd_lite_in_place_type_t(T), std::initializer_list<U> il, Args&&... args )
template<class T,
class U,
class... Args any_REQUIRES_T(
std::is_constructible<T,
std::initializer_list<U> &,
Args &&...>::value)>
explicit any(nonstd_lite_in_place_type_t(T),
std::initializer_list<U> il,
Args &&...args)
: content(new holder<T>(T(il, std::forward<Args>(args)...)))
{}
#else
template<class ValueType>
any( ValueType const & value )
: content( new holder<ValueType>( value ) )
any(ValueType const &value) : content(new holder<ValueType>(value))
{}
#endif// any_CPP11_OR_GREATER
~any()
{
reset();
}
~any() { reset(); }
any &operator=(any const &other)
{
@ -501,10 +520,9 @@ public:
return *this;
}
template<
class ValueType, class T = typename std::decay<ValueType>::type
any_REQUIRES_T( ! std::is_same<T, any>::value )
>
template<class ValueType,
class T = typename std::decay<ValueType>::type any_REQUIRES_T(
!std::is_same<T, any>::value)>
any &operator=(T &&value)
{
any(std::move(value)).swap(*this);
@ -517,10 +535,12 @@ public:
any(T(std::forward<Args>(args)...)).swap(*this);
}
template<
class T, class U, class... Args
any_REQUIRES_T( std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value )
>
template<class T,
class U,
class... Args any_REQUIRES_T(
std::is_constructible<T,
std::initializer_list<U> &,
Args &&...>::value)>
void emplace(std::initializer_list<U> il, Args &&...args)
{
any(T(il, std::forward<Args>(args)...)).swap(*this);
@ -539,18 +559,13 @@ public:
void reset() any_noexcept
{
delete content; content = any_nullptr;
delete content;
content = any_nullptr;
}
void swap( any & other ) any_noexcept
{
std::swap( content, other.content );
}
void swap(any &other) any_noexcept { std::swap(content, other.content); }
bool has_value() const any_noexcept
{
return content != any_nullptr;
}
bool has_value() const any_noexcept { return content != any_nullptr; }
const std::type_info &type() const any_noexcept
{
@ -574,12 +589,9 @@ public:
}
private:
class placeholder
{
class placeholder {
public:
virtual ~placeholder()
{
}
virtual ~placeholder() {}
virtual std::type_info const &type() const = 0;
@ -587,17 +599,12 @@ private:
};
template<typename ValueType>
class holder : public placeholder
{
class holder : public placeholder {
public:
holder( ValueType const & value )
: held( value )
{}
holder(ValueType const &value) : held(value) {}
#if any_CPP11_OR_GREATER
holder( ValueType && value )
: held( std::move( value ) )
{}
holder(ValueType &&value) : held(std::move(value)) {}
#endif
virtual std::type_info const &type() const any_override
@ -616,7 +623,8 @@ private:
placeholder *content;
};
inline void swap( any & x, any & y ) any_noexcept
inline void
swap(any &x, any &y) any_noexcept
{
x.swap(y);
}
@ -624,60 +632,66 @@ inline void swap( any & x, any & y ) any_noexcept
#if any_CPP11_OR_GREATER
template<class T, class... Args>
inline any make_any( Args&& ...args )
inline any
make_any(Args &&...args)
{
return any(nonstd_lite_in_place_type(T), std::forward<Args>(args)...);
}
template<class T, class U, class... Args>
inline any make_any( std::initializer_list<U> il, Args&& ...args )
inline any
make_any(std::initializer_list<U> il, Args &&...args)
{
return any(nonstd_lite_in_place_type(T), il, std::forward<Args>(args)...);
}
#endif// any_CPP11_OR_GREATER
template<
class ValueType
template<class ValueType
#if any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG
// any_REQUIRES_T(...) Allow for VC120 (VS2013):
, typename = typename std::enable_if< (std::is_reference<ValueType>::value || std::is_copy_constructible<ValueType>::value), nonstd::any_lite::detail::enabler >::type
,
typename = typename std::enable_if<
(std::is_reference<ValueType>::value
|| std::is_copy_constructible<ValueType>::value),
nonstd::any_lite::detail::enabler>::type
#endif
>
any_nodiscard inline ValueType any_cast( any const & operand )
any_nodiscard inline ValueType
any_cast(any const &operand)
{
const ValueType * result = any_cast< typename std11::add_const< typename std11::remove_reference<ValueType>::type >::type >( &operand );
const ValueType *result = any_cast<typename std11::add_const<
typename std11::remove_reference<ValueType>::type>::type>(&operand);
#if any_CONFIG_NO_EXCEPTIONS
assert(result);
#else
if ( ! result )
{
throw bad_any_cast();
}
if (!result) { throw bad_any_cast(); }
#endif
return *result;
}
template<
class ValueType
template<class ValueType
#if any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG
// any_REQUIRES_T(...) Allow for VC120 (VS2013):
, typename = typename std::enable_if< (std::is_reference<ValueType>::value || std::is_copy_constructible<ValueType>::value), nonstd::any_lite::detail::enabler >::type
,
typename = typename std::enable_if<
(std::is_reference<ValueType>::value
|| std::is_copy_constructible<ValueType>::value),
nonstd::any_lite::detail::enabler>::type
#endif
>
any_nodiscard inline ValueType any_cast( any & operand )
any_nodiscard inline ValueType
any_cast(any &operand)
{
const ValueType * result = any_cast< typename std11::remove_reference<ValueType>::type >( &operand );
const ValueType *result =
any_cast<typename std11::remove_reference<ValueType>::type>(&operand);
#if any_CONFIG_NO_EXCEPTIONS
assert(result);
#else
if ( ! result )
{
throw bad_any_cast();
}
if (!result) { throw bad_any_cast(); }
#endif
return *result;
@ -685,23 +699,22 @@ any_nodiscard inline ValueType any_cast( any & operand )
#if any_CPP11_OR_GREATER
template<
class ValueType
template<class ValueType
#if any_HAVE_DEFAULT_FUNCTION_TEMPLATE_ARG
any_REQUIRES_T( std::is_reference<ValueType>::value || std::is_copy_constructible<ValueType>::value )
any_REQUIRES_T(std::is_reference<ValueType>::value
|| std::is_copy_constructible<ValueType>::value)
#endif
>
any_nodiscard inline ValueType any_cast( any && operand )
any_nodiscard inline ValueType
any_cast(any &&operand)
{
const ValueType * result = any_cast< typename std11::remove_reference<ValueType>::type >( &operand );
const ValueType *result =
any_cast<typename std11::remove_reference<ValueType>::type>(&operand);
#if any_CONFIG_NO_EXCEPTIONS
assert(result);
#else
if ( ! result )
{
throw bad_any_cast();
}
if (!result) { throw bad_any_cast(); }
#endif
return *result;
@ -710,15 +723,21 @@ any_nodiscard inline ValueType any_cast( any && operand )
#endif// any_CPP11_OR_GREATER
template<class ValueType>
any_nodiscard inline ValueType const * any_cast( any const * operand ) any_noexcept
any_nodiscard inline ValueType const *
any_cast(any const *operand) any_noexcept
{
return operand != any_nullptr && operand->type() == typeid(ValueType) ? operand->to_ptr<ValueType>() : any_nullptr;
return operand != any_nullptr && operand->type() == typeid(ValueType)
? operand->to_ptr<ValueType>()
: any_nullptr;
}
template<class ValueType>
any_nodiscard inline ValueType * any_cast( any * operand ) any_noexcept
any_nodiscard inline ValueType *
any_cast(any *operand) any_noexcept
{
return operand != any_nullptr && operand->type() == typeid(ValueType) ? operand->to_ptr<ValueType>() : any_nullptr;
return operand != any_nullptr && operand->type() == typeid(ValueType)
? operand->to_ptr<ValueType>()
: any_nullptr;
}
}// namespace any_lite
@ -727,6 +746,10 @@ using namespace any_lite;
}// namespace nonstd
namespace ulib {
using namespace nonstd::any_lite;
}
#endif// any_USES_STD_ANY
#endif// NONSTD_ANY_LITE_HPP