From 30d57aec7d42b3657a4775ecede1c14d3ddde1bb Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 9 Jul 2015 20:23:35 +0100 Subject: [PATCH] add And, Or and Not type traits (for AND/ORing together integral constants in a SFINAE aware way) --- octa/type_traits.hh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/octa/type_traits.hh b/octa/type_traits.hh index 0438b9e..4466ba8 100644 --- a/octa/type_traits.hh +++ b/octa/type_traits.hh @@ -67,6 +67,50 @@ using False = IntegralConstant; template constexpr T IntegralConstant::value; +/* and */ + +namespace detail { + template struct AndBase; + + template + struct AndBase: False {}; + + template<> + struct AndBase: True {}; + + template + struct AndBase: IntegralConstant {}; + + template + struct AndBase: AndBase {}; +} + +template +struct And: detail::AndBase {}; + +/* or */ + +namespace detail { + template struct OrBase; + + template<> + struct OrBase: False {}; + + template + struct OrBase: OrBase {}; + + template + struct OrBase: True {}; +} + +template +struct Or: detail::OrBase {}; + +/* not */ + +template +struct Not: IntegralConstant {}; + /* is void */ namespace detail { @@ -1193,6 +1237,7 @@ namespace detail { template using UnderlyingType = typename detail::UnderlyingTypeBase::Type; + } /* namespace octa */ #endif \ No newline at end of file