mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 13:50:11 +00:00
[libc++] Remove cycle between <type_traits> and <cstddef>
This was caused by byte depending on traits. This patch moves the minimal amount of meta-programming into <cstddef> to break the cycle.
This commit is contained in:
parent
0d2ba6577d
commit
cccf1ef0c8
@ -57,6 +57,32 @@ using ::max_align_t;
|
||||
typedef long double max_align_t;
|
||||
#endif
|
||||
|
||||
template <class _Tp> struct __libcpp_is_integral { enum { value = 0 }; };
|
||||
template <> struct __libcpp_is_integral<bool> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<char> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<signed char> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<unsigned char> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<wchar_t> { enum { value = 1 }; };
|
||||
#ifndef _LIBCPP_NO_HAS_CHAR8_T
|
||||
template <> struct __libcpp_is_integral<char8_t> { enum { value = 1 }; };
|
||||
#endif
|
||||
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||
template <> struct __libcpp_is_integral<char16_t> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<char32_t> { enum { value = 1 }; };
|
||||
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||
template <> struct __libcpp_is_integral<short> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<unsigned short> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<int> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<unsigned int> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<long> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<unsigned long> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<long long> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<unsigned long long> { enum { value = 1 }; };
|
||||
#ifndef _LIBCPP_HAS_NO_INT128
|
||||
template <> struct __libcpp_is_integral<__int128_t> { enum { value = 1 }; };
|
||||
template <> struct __libcpp_is_integral<__uint128_t> { enum { value = 1 }; };
|
||||
#endif
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
@ -64,6 +90,11 @@ namespace std // purposefully not versioned
|
||||
{
|
||||
enum class byte : unsigned char {};
|
||||
|
||||
|
||||
template <bool> struct __enable_if_integral_imp {};
|
||||
template <> struct __enable_if_integral_imp<true> { using type = byte; };
|
||||
template <class _Tp> using _EnableByteOverload = typename __enable_if_integral_imp<__libcpp_is_integral<_Tp>::value>::type;
|
||||
|
||||
constexpr byte operator| (byte __lhs, byte __rhs) noexcept
|
||||
{
|
||||
return static_cast<byte>(
|
||||
@ -104,10 +135,31 @@ constexpr byte operator~ (byte __b) noexcept
|
||||
~static_cast<unsigned int>(__b)
|
||||
));
|
||||
}
|
||||
template <class _Integer>
|
||||
constexpr _EnableByteOverload<_Integer> &
|
||||
operator<<=(byte& __lhs, _Integer __shift) noexcept
|
||||
{ return __lhs = __lhs << __shift; }
|
||||
|
||||
template <class _Integer>
|
||||
constexpr _EnableByteOverload<_Integer>
|
||||
operator<< (byte __lhs, _Integer __shift) noexcept
|
||||
{ return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); }
|
||||
|
||||
template <class _Integer>
|
||||
constexpr _EnableByteOverload<_Integer> &
|
||||
operator>>=(byte& __lhs, _Integer __shift) noexcept
|
||||
{ return __lhs = __lhs >> __shift; }
|
||||
|
||||
template <class _Integer>
|
||||
constexpr _EnableByteOverload<_Integer>
|
||||
operator>> (byte __lhs, _Integer __shift) noexcept
|
||||
{ return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
|
||||
|
||||
template <class _Integer, class = _EnableByteOverload<_Integer> >
|
||||
constexpr _Integer
|
||||
to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
|
||||
}
|
||||
|
||||
#include <type_traits> // rest of byte
|
||||
#endif
|
||||
|
||||
#endif // _LIBCPP_CSTDDEF
|
||||
|
@ -735,34 +735,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_null_pointer_v
|
||||
|
||||
// is_integral
|
||||
|
||||
template <class _Tp> struct __libcpp_is_integral : public false_type {};
|
||||
template <> struct __libcpp_is_integral<bool> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<char> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<signed char> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<unsigned char> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<wchar_t> : public true_type {};
|
||||
#ifndef _LIBCPP_NO_HAS_CHAR8_T
|
||||
template <> struct __libcpp_is_integral<char8_t> : public true_type {};
|
||||
#endif
|
||||
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||
template <> struct __libcpp_is_integral<char16_t> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<char32_t> : public true_type {};
|
||||
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
|
||||
template <> struct __libcpp_is_integral<short> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<unsigned short> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<int> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<unsigned int> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<long> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<unsigned long> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<long long> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<unsigned long long> : public true_type {};
|
||||
#ifndef _LIBCPP_HAS_NO_INT128
|
||||
template <> struct __libcpp_is_integral<__int128_t> : public true_type {};
|
||||
template <> struct __libcpp_is_integral<__uint128_t> : public true_type {};
|
||||
#endif
|
||||
|
||||
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
|
||||
: public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
|
||||
: public _BoolConstant<__libcpp_is_integral<typename remove_cv<_Tp>::type>::value> {};
|
||||
|
||||
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
|
||||
template <class _Tp>
|
||||
@ -4046,29 +4020,7 @@ _LIBCPP_END_NAMESPACE_STD
|
||||
// std::byte
|
||||
namespace std // purposefully not versioned
|
||||
{
|
||||
template <class _Integer>
|
||||
constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
|
||||
operator<<=(byte& __lhs, _Integer __shift) noexcept
|
||||
{ return __lhs = __lhs << __shift; }
|
||||
|
||||
template <class _Integer>
|
||||
constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
|
||||
operator<< (byte __lhs, _Integer __shift) noexcept
|
||||
{ return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); }
|
||||
|
||||
template <class _Integer>
|
||||
constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
|
||||
operator>>=(byte& __lhs, _Integer __shift) noexcept
|
||||
{ return __lhs = __lhs >> __shift; }
|
||||
|
||||
template <class _Integer>
|
||||
constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
|
||||
operator>> (byte __lhs, _Integer __shift) noexcept
|
||||
{ return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
|
||||
|
||||
template <class _Integer>
|
||||
constexpr typename enable_if<is_integral_v<_Integer>, _Integer>::type
|
||||
to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
|
||||
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user