15 #ifndef RAPIDJSON_INTERNAL_META_H_ 16 #define RAPIDJSON_INTERNAL_META_H_ 18 #include "../rapidjson.h" 22 RAPIDJSON_DIAG_OFF(effc++)
26 RAPIDJSON_DIAG_OFF(6334)
29 #if RAPIDJSON_HAS_CXX11_TYPETRAITS 30 #include <type_traits> 38 template <
typename T>
struct Void {
typedef void Type; };
43 template <
bool Cond>
struct BoolType {
44 static const bool Value = Cond;
45 typedef BoolType
Type;
47 typedef BoolType<true> TrueType;
48 typedef BoolType<false> FalseType;
55 template <
bool C>
struct SelectIfImpl {
template <
typename T1,
typename T2>
struct Apply {
typedef T1
Type; }; };
56 template <>
struct SelectIfImpl<false> {
template <
typename T1,
typename T2>
struct Apply {
typedef T2
Type; }; };
57 template <
bool C,
typename T1,
typename T2>
struct SelectIfCond : SelectIfImpl<C>::template Apply<T1,T2> {};
58 template <
typename C,
typename T1,
typename T2>
struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
60 template <
bool Cond1,
bool Cond2>
struct AndExprCond : FalseType {};
61 template <>
struct AndExprCond<true, true> : TrueType {};
62 template <
bool Cond1,
bool Cond2>
struct OrExprCond : TrueType {};
63 template <>
struct OrExprCond<false, false> : FalseType {};
65 template <
typename C>
struct BoolExpr : SelectIf<C,TrueType,FalseType>
::Type {};
66 template <
typename C>
struct NotExpr : SelectIf<C,FalseType,TrueType>
::Type {};
67 template <
typename C1,
typename C2>
struct AndExpr : AndExprCond<C1::Value, C2::Value>
::Type {};
68 template <
typename C1,
typename C2>
struct OrExpr : OrExprCond<C1::Value, C2::Value>
::Type {};
73 template <
typename T>
struct AddConst {
typedef const T Type; };
74 template <
bool Constify,
typename T>
struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
75 template <
typename T>
struct RemoveConst {
typedef T Type; };
76 template <
typename T>
struct RemoveConst<const
T> {
typedef T Type; };
82 template <
typename T,
typename U>
struct IsSame : FalseType {};
83 template <
typename T>
struct IsSame<
T,
T> : TrueType {};
85 template <
typename T>
struct IsConst : FalseType {};
86 template <
typename T>
struct IsConst<const T> : TrueType {};
88 template <
typename CT,
typename T>
90 : AndExpr<IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>,
91 BoolType<IsConst<CT>::Value >= IsConst<T>::Value> >
::Type {};
93 template <
typename T>
struct IsPointer : FalseType {};
94 template <
typename T>
struct IsPointer<T*> : TrueType {};
99 #if RAPIDJSON_HAS_CXX11_TYPETRAITS 101 template <
typename B,
typename D>
struct IsBaseOf
102 : BoolType< ::std::is_base_of<B,D>::value> {};
104 #else // simplified version adopted from Boost 106 template<
typename B,
typename D>
struct IsBaseOfImpl {
110 typedef char (&Yes)[1];
111 typedef char (&No) [2];
113 template <
typename T>
114 static Yes Check(
const D*, T);
115 static No Check(
const B*,
int);
118 operator const B*()
const;
122 enum {
Value = (
sizeof(Check(Host(), 0)) ==
sizeof(Yes)) };
125 template <
typename B,
typename D>
struct IsBaseOf
126 : OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D> > >
::Type {};
128 #endif // RAPIDJSON_HAS_CXX11_TYPETRAITS 134 template <
bool Condition,
typename T =
void>
struct EnableIfCond {
typedef T
Type; };
135 template <
typename T>
struct EnableIfCond<false, T> { };
137 template <
bool Condition,
typename T =
void>
struct DisableIfCond {
typedef T
Type; };
138 template <
typename T>
struct DisableIfCond<true, T> { };
140 template <
typename Condition,
typename T =
void>
141 struct EnableIf : EnableIfCond<Condition::Value, T> {};
143 template <
typename Condition,
typename T =
void>
144 struct DisableIf : DisableIfCond<Condition::Value, T> {};
148 template <
typename T>
struct RemoveSfinaeTag;
149 template <
typename T>
struct RemoveSfinaeTag<SfinaeTag&(*)(
T)> {
typedef T
Type; };
151 #define RAPIDJSON_REMOVEFPTR_(type) \ 152 typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \ 153 < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type 155 #define RAPIDJSON_ENABLEIF(cond) \ 156 typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 157 <RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL 159 #define RAPIDJSON_DISABLEIF(cond) \ 160 typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 161 <RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL 163 #define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ 164 typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 165 <RAPIDJSON_REMOVEFPTR_(cond), \ 166 RAPIDJSON_REMOVEFPTR_(returntype)>::Type 168 #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ 169 typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 170 <RAPIDJSON_REMOVEFPTR_(cond), \ 171 RAPIDJSON_REMOVEFPTR_(returntype)>::Type 177 #if defined(__GNUC__) || defined(_MSC_VER) 181 #endif // RAPIDJSON_INTERNAL_META_H_ #define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)