19 #ifndef RAPIDJSON_INTERNAL_META_H_ 20 #define RAPIDJSON_INTERNAL_META_H_ 22 #include "../rapidjson.h" 26 RAPIDJSON_DIAG_OFF(effc++)
29 #if defined(_MSC_VER) && !defined(__clang__) 31 RAPIDJSON_DIAG_OFF(6334)
34 #if RAPIDJSON_HAS_CXX11_TYPETRAITS 35 #include <type_traits> 54 static const bool Value = Cond;
55 typedef BoolType
Type;
57 typedef BoolType<true> TrueType;
58 typedef BoolType<false> FalseType;
66 template <
typename T1,
typename T2>
72 struct SelectIfImpl<false> {
73 template <
typename T1,
typename T2>
78 template <
bool C,
typename T1,
typename T2>
79 struct SelectIfCond : SelectIfImpl<C>::template Apply<T1, T2> {};
80 template <
typename C,
typename T1,
typename T2>
81 struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
83 template <
bool Cond1,
bool Cond2>
84 struct AndExprCond : FalseType {};
86 struct AndExprCond<true, true> : TrueType {};
87 template <
bool Cond1,
bool Cond2>
88 struct OrExprCond : TrueType {};
90 struct OrExprCond<false, false> : FalseType {};
93 struct BoolExpr : SelectIf<C, TrueType, FalseType>
::Type {};
95 struct NotExpr : SelectIf<C, FalseType, TrueType>
::Type {};
96 template <
typename C1,
typename C2>
97 struct AndExpr : AndExprCond<C1::Value, C2::Value>
::Type {};
98 template <
typename C1,
typename C2>
99 struct OrExpr : OrExprCond<C1::Value, C2::Value>
::Type {};
103 template <
typename T>
105 typedef const T
Type;
107 template <
bool Constify,
typename T>
108 struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
109 template <
typename T>
113 template <
typename T>
114 struct RemoveConst<const T> {
121 template <
typename T,
typename U>
122 struct IsSame : FalseType {};
123 template <
typename T>
124 struct IsSame<T, T> : TrueType {};
126 template <
typename T>
127 struct IsConst : FalseType {};
128 template <
typename T>
129 struct IsConst<const T> : TrueType {};
131 template <
typename CT,
typename T>
134 IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>,
135 BoolType<IsConst<CT>::Value >= IsConst<T>::Value>>
::Type {};
137 template <
typename T>
138 struct IsPointer : FalseType {};
139 template <
typename T>
140 struct IsPointer<T *> : TrueType {};
145 #if RAPIDJSON_HAS_CXX11_TYPETRAITS 147 template <
typename B,
typename D>
148 struct IsBaseOf : BoolType<::std::is_base_of<B, D>::value> {};
150 #else // simplified version adopted from Boost 152 template <
typename B,
typename D>
153 struct IsBaseOfImpl {
157 typedef char (&Yes)[1];
158 typedef char (&No)[2];
160 template <
typename T>
161 static Yes Check(
const D *, T);
162 static No Check(
const B *,
int);
165 operator const B *()
const;
166 operator const D *();
169 enum {
Value = (
sizeof(Check(Host(), 0)) ==
sizeof(Yes)) };
172 template <
typename B,
typename D>
173 struct IsBaseOf : OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D>>>
::Type {};
175 #endif // RAPIDJSON_HAS_CXX11_TYPETRAITS 180 template <
bool Condition,
typename T =
void>
181 struct EnableIfCond {
184 template <
typename T>
185 struct EnableIfCond<false, T> {
188 template <
bool Condition,
typename T =
void>
189 struct DisableIfCond {
192 template <
typename T>
193 struct DisableIfCond<true, T> {
196 template <
typename Condition,
typename T =
void>
197 struct EnableIf : EnableIfCond<Condition::Value, T> {};
199 template <
typename Condition,
typename T =
void>
200 struct DisableIf : DisableIfCond<Condition::Value, T> {};
204 template <
typename T>
205 struct RemoveSfinaeTag;
206 template <
typename T>
207 struct RemoveSfinaeTag<SfinaeTag &(*)(T)> {
211 #define RAPIDJSON_REMOVEFPTR_(type) \ 212 typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag< \ 213 ::RAPIDJSON_NAMESPACE::internal::SfinaeTag &(*)type>::Type 215 #define RAPIDJSON_ENABLEIF(cond) \ 216 typename ::RAPIDJSON_NAMESPACE::internal::EnableIf<RAPIDJSON_REMOVEFPTR_( \ 217 cond)>::Type * = NULL 219 #define RAPIDJSON_DISABLEIF(cond) \ 220 typename ::RAPIDJSON_NAMESPACE::internal::DisableIf<RAPIDJSON_REMOVEFPTR_( \ 221 cond)>::Type * = NULL 223 #define RAPIDJSON_ENABLEIF_RETURN(cond, returntype) \ 224 typename ::RAPIDJSON_NAMESPACE::internal::EnableIf< \ 225 RAPIDJSON_REMOVEFPTR_(cond), RAPIDJSON_REMOVEFPTR_(returntype)>::Type 227 #define RAPIDJSON_DISABLEIF_RETURN(cond, returntype) \ 228 typename ::RAPIDJSON_NAMESPACE::internal::DisableIf< \ 229 RAPIDJSON_REMOVEFPTR_(cond), RAPIDJSON_REMOVEFPTR_(returntype)>::Type 235 #if defined(_MSC_VER) && !defined(__clang__) 243 #endif // RAPIDJSON_INTERNAL_META_H_ #define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)