All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
meta.h
1 #ifndef RAPIDJSON_INTERNAL_META_H_
2 #define RAPIDJSON_INTERNAL_META_H_
3 
4 //@cond RAPIDJSON_INTERNAL
5 namespace rapidjson {
6 namespace internal {
7 
8 template <int N> struct IntegralC { enum { Value = N }; };
9 template <bool Cond> struct BoolType : IntegralC<Cond> {};
10 struct TrueType : BoolType<true> {};
11 struct FalseType : BoolType<false> {};
12 
13 template <typename T> struct AddConst { typedef const T Type; };
14 template <typename T> struct RemoveConst { typedef T Type; };
15 template <typename T> struct RemoveConst<const T> { typedef T Type; };
16 
17 template <bool Condition, typename T1, typename T2> struct SelectIfCond;
18 template <typename T1, typename T2> struct SelectIfCond<true,T1,T2> { typedef T1 Type; };
19 template <typename T1, typename T2> struct SelectIfCond<false,T1,T2> { typedef T2 Type; };
20 
21 template <typename Condition, typename T1, typename T2>
22 struct SelectIf : SelectIfCond<Condition::Value,T1,T2> {};
23 
24 template <bool Constify, typename T>
25 struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
26 
27 template <typename T, typename U> struct IsSame : FalseType {};
28 template <typename T> struct IsSame<T,T> : TrueType {};
29 
30 template <typename T> struct IsConst : FalseType {};
31 template <typename T> struct IsConst<const T> : TrueType {};
32 
33 template <typename T> struct IsPointer : FalseType {};
34 template <typename T> struct IsPointer<T*> : TrueType {};
35 
36 template <typename CT, typename T>
37 struct IsMoreConst {
38  enum { Value =
40  && ( IsConst<CT>::Value >= IsConst<T>::Value ) )
41  };
42 };
43 
44 template <bool Condition, typename T = void> struct EnableIfCond;
45 template <typename T> struct EnableIfCond<true, T> { typedef T Type; };
46 template <typename T> struct EnableIfCond<false, T> { /* empty */ };
47 
48 template <bool Condition, typename T = void>
49 struct DisableIfCond : EnableIfCond<!Condition, T> {};
50 
51 template <typename Condition, typename T = void>
52 struct EnableIf : EnableIfCond<Condition::Value, T> {};
53 
54 template <typename Condition, typename T = void>
55 struct DisableIf : DisableIfCond<Condition::Value, T> {};
56 
57 // SFINAE helpers
58 struct SfinaeResultTag {};
59 template <typename T> struct RemoveSfinaeFptr {};
60 template <typename T> struct RemoveSfinaeFptr<SfinaeResultTag&(*)(T)> { typedef T Type; };
61 
62 #define RAPIDJSON_REMOVEFPTR_(type) \
63  typename ::rapidjson::internal::RemoveSfinaeFptr \
64  < ::rapidjson::internal::SfinaeResultTag&(*) type>::Type
65 
66 #define RAPIDJSON_ENABLEIF(cond) \
67  typename ::rapidjson::internal::EnableIf \
68  <RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
69 
70 #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \
71  typename ::rapidjson::internal::DisableIf<cond,returntype>::Type
72 
73 } // namespace internal
74 } // namespace rapidjson
75 //@endcond
76 
77 #endif // RAPIDJSON_INTERNAL_META_H_
Type
Type of JSON value.
Definition: rapidjson.h:391
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:1191