16#ifndef RAPIDJSON_INTERNAL_META_H_
17#define RAPIDJSON_INTERNAL_META_H_
19#include "../rapidjson.h"
23RAPIDJSON_DIAG_OFF(effc++)
26#if defined(_MSC_VER) && !defined(__clang__)
28RAPIDJSON_DIAG_OFF(6334)
31#if RAPIDJSON_HAS_CXX11_TYPETRAITS
40template <
typename T>
struct Void {
typedef void Type; };
45template <
bool Cond>
struct BoolType {
46 static const bool Value = Cond;
47 typedef BoolType
Type;
49typedef BoolType<true> TrueType;
50typedef BoolType<false> FalseType;
57template <
bool C>
struct SelectIfImpl {
template <
typename T1,
typename T2>
struct Apply {
typedef T1
Type; }; };
58template <>
struct SelectIfImpl<false> {
template <
typename T1,
typename T2>
struct Apply {
typedef T2
Type; }; };
59template <
bool C,
typename T1,
typename T2>
struct SelectIfCond : SelectIfImpl<C>::template Apply<T1,T2> {};
60template <
typename C,
typename T1,
typename T2>
struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
62template <
bool Cond1,
bool Cond2>
struct AndExprCond : FalseType {};
63template <>
struct AndExprCond<true, true> : TrueType {};
64template <
bool Cond1,
bool Cond2>
struct OrExprCond : TrueType {};
65template <>
struct OrExprCond<false, false> : FalseType {};
67template <
typename C>
struct BoolExpr : SelectIf<C,TrueType,FalseType>
::Type {};
68template <
typename C>
struct NotExpr : SelectIf<C,FalseType,TrueType>
::Type {};
69template <
typename C1,
typename C2>
struct AndExpr : AndExprCond<C1::Value, C2::Value>
::Type {};
70template <
typename C1,
typename C2>
struct OrExpr : OrExprCond<C1::Value, C2::Value>
::Type {};
75template <
typename T>
struct AddConst {
typedef const T
Type; };
76template <
bool Constify,
typename T>
struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
77template <
typename T>
struct RemoveConst {
typedef T
Type; };
78template <
typename T>
struct RemoveConst<const T> {
typedef T
Type; };
84template <
typename T,
typename U>
struct IsSame : FalseType {};
85template <
typename T>
struct IsSame<T, T> : TrueType {};
87template <
typename T>
struct IsConst : FalseType {};
88template <
typename T>
struct IsConst<const T> : TrueType {};
90template <
typename CT,
typename T>
92 : AndExpr<IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>,
93 BoolType<IsConst<CT>::Value >= IsConst<T>::Value> >
::Type {};
95template <
typename T>
struct IsPointer : FalseType {};
96template <
typename T>
struct IsPointer<T*> : TrueType {};
101#if RAPIDJSON_HAS_CXX11_TYPETRAITS
103template <
typename B,
typename D>
struct IsBaseOf
104 : BoolType< ::std::is_base_of<B,D>::value> {};
108template<
typename B,
typename D>
struct IsBaseOfImpl {
112 typedef char (&Yes)[1];
113 typedef char (&No) [2];
115 template <
typename T>
116 static Yes Check(
const D*, T);
117 static No Check(
const B*,
int);
120 operator const B*()
const;
124 enum {
Value = (
sizeof(Check(Host(), 0)) ==
sizeof(Yes)) };
127template <
typename B,
typename D>
struct IsBaseOf
128 : OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D> > >
::Type {};
136template <
bool Condition,
typename T =
void>
struct EnableIfCond {
typedef T
Type; };
137template <
typename T>
struct EnableIfCond<false, T> { };
139template <
bool Condition,
typename T =
void>
struct DisableIfCond {
typedef T
Type; };
140template <
typename T>
struct DisableIfCond<true, T> { };
142template <
typename Condition,
typename T =
void>
143struct EnableIf : EnableIfCond<Condition::Value, T> {};
145template <
typename Condition,
typename T =
void>
146struct DisableIf : DisableIfCond<Condition::Value, T> {};
150template <
typename T>
struct RemoveSfinaeTag;
151template <
typename T>
struct RemoveSfinaeTag<SfinaeTag&(*)(T)> {
typedef T
Type; };
153#define RAPIDJSON_REMOVEFPTR_(type) \
154 typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \
155 < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type
157#define RAPIDJSON_ENABLEIF(cond) \
158 typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
159 <RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
161#define RAPIDJSON_DISABLEIF(cond) \
162 typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
163 <RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
165#define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \
166 typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
167 <RAPIDJSON_REMOVEFPTR_(cond), \
168 RAPIDJSON_REMOVEFPTR_(returntype)>::Type
170#define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \
171 typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
172 <RAPIDJSON_REMOVEFPTR_(cond), \
173 RAPIDJSON_REMOVEFPTR_(returntype)>::Type
179#if defined(_MSC_VER) && !defined(__clang__)
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
#define RAPIDJSON_STATIC_ASSERT(x)
(Internal) macro to check for conditions at compile-time