From 05179e28916ada5feb56d7a8f67f9964938498bc Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Thu, 3 Jul 2014 14:24:58 +0200 Subject: [PATCH] internal/meta.h: add some template meta functions * Add/RemoveConst * IsSame, IsConst, IsMoreConst * Enable/DisableIf (including helper macro) --- include/rapidjson/internal/meta.h | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 include/rapidjson/internal/meta.h diff --git a/include/rapidjson/internal/meta.h b/include/rapidjson/internal/meta.h new file mode 100644 index 0000000..8a1e966 --- /dev/null +++ b/include/rapidjson/internal/meta.h @@ -0,0 +1,71 @@ +#ifndef RAPIDJSON_INTERNAL_META_H_ +#define RAPIDJSON_INTERNAL_META_H_ + +//@cond RAPIDJSON_INTERNAL +namespace rapidjson { +namespace internal { + +template struct IntegralC { enum { Value = N }; }; +template struct BoolType : IntegralC {}; +struct TrueType : BoolType {}; +struct FalseType : BoolType {}; + +template struct AddConst { typedef const T Type; }; +template struct RemoveConst { typedef T Type; }; +template struct RemoveConst { typedef T Type; }; + +template struct SelectIfCond; +template struct SelectIfCond { typedef T1 Type; }; +template struct SelectIfCond { typedef T2 Type; }; + +template +struct SelectIf : SelectIfCond {}; + +template +struct MaybeAddConst : SelectIfCond {}; + +template struct IsSame { enum { Value = false }; }; +template struct IsSame { enum { Value = true }; }; + +template struct IsConst { enum { Value = false }; }; +template struct IsConst { enum { Value = true }; }; + +template +struct IsMoreConst { + enum { Value = + ( IsSame< typename RemoveConst::Type, typename RemoveConst::Type>::Value + && ( IsConst::Value >= IsConst::Value ) ) + }; +}; + +template struct EnableIfCond; +template struct EnableIfCond { typedef T Type; }; +template struct EnableIfCond { /* empty */ }; + +template +struct DisableIfCond : EnableIfCond {}; + +template +struct EnableIf : EnableIfCond {}; + +template +struct DisableIf : DisableIfCond {}; + +// SFINAE helpers +struct SfinaeResultTag {}; +template struct RemoveSfinaeFptr {}; +template struct RemoveSfinaeFptr { typedef T Type; }; + +#define RAPIDJSON_REMOVEFPTR_(type) \ + typename ::rapidjson::internal::RemoveSfinaeFptr \ + < ::rapidjson::internal::SfinaeResultTag&(*) type>::Type + +#define RAPIDJSON_ENABLEIF(cond) \ + typename ::rapidjson::internal::EnableIf \ + ::Type * = NULL + +} // namespace internal +} // namespace rapidjson +//@endcond + +#endif // RAPIDJSON_INTERNAL_META_H_