mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1241901 part 3 - Add IsMemberPointer and IsScalar type traits. r=froydnj
This commit is contained in:
parent
7f63ffdc57
commit
137556e781
@ -355,6 +355,41 @@ struct IsArithmetic
|
||||
: IntegralConstant<bool, IsIntegral<T>::value || IsFloatingPoint<T>::value>
|
||||
{};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
struct IsMemberPointerHelper : FalseType {};
|
||||
|
||||
template<typename T, typename U>
|
||||
struct IsMemberPointerHelper<T U::*> : TrueType {};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
/**
|
||||
* IsMemberPointer determines whether a type is pointer to non-static member
|
||||
* object or a pointer to non-static member function.
|
||||
*
|
||||
* mozilla::IsMemberPointer<int(cls::*)>::value is true
|
||||
* mozilla::IsMemberPointer<int*>::value is false
|
||||
*/
|
||||
template<typename T>
|
||||
struct IsMemberPointer
|
||||
: detail::IsMemberPointerHelper<typename RemoveCV<T>::Type>
|
||||
{};
|
||||
|
||||
/**
|
||||
* IsScalar determines whether a type is a scalar type.
|
||||
*
|
||||
* mozilla::IsScalar<int>::value is true
|
||||
* mozilla::IsScalar<int*>::value is true
|
||||
* mozilla::IsScalar<cls>::value is false
|
||||
*/
|
||||
template<typename T>
|
||||
struct IsScalar
|
||||
: IntegralConstant<bool, IsArithmetic<T>::value || IsEnum<T>::value ||
|
||||
IsPointer<T>::value || IsMemberPointer<T>::value>
|
||||
{};
|
||||
|
||||
/* 20.9.4.3 Type properties [meta.unary.prop] */
|
||||
|
||||
/**
|
||||
|
@ -7,6 +7,12 @@
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/TypeTraits.h"
|
||||
|
||||
#define TEST_CV_QUALIFIERS(test, type, ...) \
|
||||
test(type, __VA_ARGS__) \
|
||||
test(const type, __VA_ARGS__) \
|
||||
test(volatile type, __VA_ARGS__) \
|
||||
test(const volatile type, __VA_ARGS__)
|
||||
|
||||
using mozilla::AddLvalueReference;
|
||||
using mozilla::AddPointer;
|
||||
using mozilla::AddRvalueReference;
|
||||
@ -137,6 +143,77 @@ static_assert(IsReference<int&>::value,
|
||||
static_assert(IsReference<int&&>::value,
|
||||
"int&& is a reference");
|
||||
|
||||
namespace CPlusPlus11IsMemberPointer {
|
||||
|
||||
using mozilla::IsMemberPointer;
|
||||
|
||||
struct S {};
|
||||
union U {};
|
||||
|
||||
#define ASSERT_IS_MEMBER_POINTER(type, msg) \
|
||||
static_assert(IsMemberPointer<type>::value, #type msg);
|
||||
#define TEST_IS_MEMBER_POINTER(type) \
|
||||
TEST_CV_QUALIFIERS(ASSERT_IS_MEMBER_POINTER, type, \
|
||||
" is a member pointer type")
|
||||
|
||||
TEST_IS_MEMBER_POINTER(int S::*)
|
||||
TEST_IS_MEMBER_POINTER(int U::*)
|
||||
|
||||
#undef TEST_IS_MEMBER_POINTER
|
||||
#undef ASSERT_IS_MEMBER_POINTER
|
||||
|
||||
#define ASSERT_IS_NOT_MEMBER_POINTER(type, msg) \
|
||||
static_assert(!IsMemberPointer<type>::value, #type msg);
|
||||
#define TEST_IS_NOT_MEMBER_POINTER(type) \
|
||||
TEST_CV_QUALIFIERS(ASSERT_IS_NOT_MEMBER_POINTER, type, \
|
||||
" is not a member pointer type")
|
||||
|
||||
TEST_IS_NOT_MEMBER_POINTER(int*)
|
||||
|
||||
#undef TEST_IS_NOT_MEMBER_POINTER
|
||||
#undef ASSERT_IS_NOT_MEMBER_POINTER
|
||||
|
||||
} // CPlusPlus11IsMemberPointer
|
||||
|
||||
namespace CPlusPlus11IsScalar {
|
||||
|
||||
using mozilla::IsScalar;
|
||||
|
||||
enum E {};
|
||||
enum class EC {};
|
||||
class C {};
|
||||
struct S {};
|
||||
union U {};
|
||||
|
||||
#define ASSERT_IS_SCALAR(type, msg) \
|
||||
static_assert(IsScalar<type>::value, #type msg);
|
||||
#define TEST_IS_SCALAR(type) \
|
||||
TEST_CV_QUALIFIERS(ASSERT_IS_SCALAR, type, " is a scalar type")
|
||||
|
||||
TEST_IS_SCALAR(int)
|
||||
TEST_IS_SCALAR(float)
|
||||
TEST_IS_SCALAR(E)
|
||||
TEST_IS_SCALAR(EC)
|
||||
TEST_IS_SCALAR(S*)
|
||||
TEST_IS_SCALAR(int S::*)
|
||||
|
||||
#undef TEST_IS_SCALAR
|
||||
#undef ASSERT_IS_SCALAR
|
||||
|
||||
#define ASSERT_IS_NOT_SCALAR(type, msg) \
|
||||
static_assert(!IsScalar<type>::value, #type msg);
|
||||
#define TEST_IS_NOT_SCALAR(type) \
|
||||
TEST_CV_QUALIFIERS(ASSERT_IS_NOT_SCALAR, type, " is not a scalar type")
|
||||
|
||||
TEST_IS_NOT_SCALAR(C)
|
||||
TEST_IS_NOT_SCALAR(S)
|
||||
TEST_IS_NOT_SCALAR(U)
|
||||
|
||||
#undef TEST_IS_NOT_SCALAR
|
||||
#undef ASSERT_IS_NOT_SCALAR
|
||||
|
||||
} // CPlusPlus11IsScalar
|
||||
|
||||
struct S1 {};
|
||||
union U1 { int mX; };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user