15#ifndef RAPIDJSON_INTERNAL_META_H_
16#define RAPIDJSON_INTERNAL_META_H_
22RAPIDJSON_DIAG_OFF(effc++)
26RAPIDJSON_DIAG_OFF(6334)
29#if RAPIDJSON_HAS_CXX11_TYPETRAITS
34RAPIDJSON_NAMESPACE_BEGIN
38template <
typename T>
struct Void {
typedef void Type; };
43template <
bool Cond>
struct BoolType {
44 static const bool Value = Cond;
45 typedef BoolType
Type;
47typedef BoolType<true> TrueType;
48typedef BoolType<false> FalseType;
55template <
bool C>
struct SelectIfImpl {
template <
typename T1,
typename T2>
struct Apply {
typedef T1
Type; }; };
56template <>
struct SelectIfImpl<false> {
template <
typename T1,
typename T2>
struct Apply {
typedef T2
Type; }; };
57template <
bool C,
typename T1,
typename T2>
struct SelectIfCond : SelectIfImpl<C>::template Apply<T1,T2> {};
58template <
typename C,
typename T1,
typename T2>
struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
60template <
bool Cond1,
bool Cond2>
struct AndExprCond : FalseType {};
61template <>
struct AndExprCond<true, true> : TrueType {};
62template <
bool Cond1,
bool Cond2>
struct OrExprCond : TrueType {};
63template <>
struct OrExprCond<false, false> : FalseType {};
65template <
typename C>
struct BoolExpr : SelectIf<C,TrueType,FalseType>::Type {};
66template <
typename C>
struct NotExpr : SelectIf<C,FalseType,TrueType>::Type {};
67template <
typename C1,
typename C2>
struct AndExpr : AndExprCond<C1::Value, C2::Value>::Type {};
68template <
typename C1,
typename C2>
struct OrExpr : OrExprCond<C1::Value, C2::Value>::Type {};
73template <
typename T>
struct AddConst {
typedef const T
Type; };
74template <
bool Constify,
typename T>
struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
75template <
typename T>
struct RemoveConst {
typedef T
Type; };
76template <
typename T>
struct RemoveConst<const T> {
typedef T
Type; };
82template <
typename T,
typename U>
struct IsSame : FalseType {};
83template <
typename T>
struct IsSame<T, T> : TrueType {};
85template <
typename T>
struct IsConst : FalseType {};
86template <
typename T>
struct IsConst<const T> : TrueType {};
88template <
typename CT,
typename T>
90 : AndExpr<IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>,
91 BoolType<IsConst<CT>::Value >= IsConst<T>::Value> >::Type {};
93template <
typename T>
struct IsPointer : FalseType {};
94template <
typename T>
struct IsPointer<T*> : TrueType {};
99#if RAPIDJSON_HAS_CXX11_TYPETRAITS
101template <
typename B,
typename D>
struct IsBaseOf
102 : BoolType< ::std::is_base_of<B,D>::value> {};
106template<
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)) };
125template <
typename B,
typename D>
struct IsBaseOf
126 : OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D> > >::Type {};
134template <
bool Condition,
typename T =
void>
struct EnableIfCond {
typedef T
Type; };
135template <
typename T>
struct EnableIfCond<false, T> { };
137template <
bool Condition,
typename T =
void>
struct DisableIfCond {
typedef T
Type; };
138template <
typename T>
struct DisableIfCond<true, T> { };
140template <
typename Condition,
typename T =
void>
141struct EnableIf : EnableIfCond<Condition::Value, T> {};
143template <
typename Condition,
typename T =
void>
144struct DisableIf : DisableIfCond<Condition::Value, T> {};
148template <
typename T>
struct RemoveSfinaeTag;
149template <
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
174RAPIDJSON_NAMESPACE_END
177#if defined(__GNUC__) || defined(_MSC_VER)
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition document.h:2008
Type
Type of JSON value.
Definition rapidjson.h:603
common definitions and configuration
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time
Definition rapidjson.h:437