From 9b11c1d319805ef265cfc4741bc87cbc97855864 Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 12 Jan 2016 22:24:40 +0000 Subject: [PATCH] convert IsSame to template variable --- ostd/algorithm.hh | 2 +- ostd/atomic.hh | 42 +++++++++++++++++++------------------- ostd/format.hh | 10 ++++----- ostd/functional.hh | 4 ++-- ostd/internal/hashtable.hh | 4 ++-- ostd/maybe.hh | 6 +++--- ostd/memory.hh | 21 ++++++++----------- ostd/string.hh | 6 +++--- ostd/tuple.hh | 27 ++++++++++-------------- ostd/type_traits.hh | 17 +++++++++------ ostd/utility.hh | 2 +- ostd/vector.hh | 4 ++-- tests/utility.cc | 4 ++-- 13 files changed, 72 insertions(+), 77 deletions(-) diff --git a/ostd/algorithm.hh b/ostd/algorithm.hh index ce939a1..edf75d0 100644 --- a/ostd/algorithm.hh +++ b/ostd/algorithm.hh @@ -619,7 +619,7 @@ namespace detail { template using FilterPred = EnableIf()(declval>())), bool - >::value, P>; + >, P>; } template diff --git a/ostd/atomic.hh b/ostd/atomic.hh index 223b5fb..c159a68 100644 --- a/ostd/atomic.hh +++ b/ostd/atomic.hh @@ -288,7 +288,7 @@ template inline T kill_dependency(T v) { } namespace detail { - template && !IsSame::value> + template && !IsSame> struct Atomic { mutable AtomicBase p_a; @@ -656,13 +656,13 @@ inline bool atomic_compare_exchange_strong_explicit(Atomic *a, T *e, } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_add(volatile Atomic *a, T op) { return a->fetch_add(op); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_add(Atomic *a, T op) { return a->fetch_add(op); } @@ -678,14 +678,14 @@ inline T *atomic_fetch_add(Atomic *a, Ptrdiff op) { } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_add_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_add(op, ord); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_add_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_add(op, ord); } @@ -703,13 +703,13 @@ inline T *atomic_fetch_add_explicit(Atomic *a, Ptrdiff op, } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_sub(volatile Atomic *a, T op) { return a->fetch_sub(op); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_sub(Atomic *a, T op) { return a->fetch_sub(op); } @@ -725,14 +725,14 @@ inline T *atomic_fetch_sub(Atomic *a, Ptrdiff op) { } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_sub_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_sub(op, ord); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_sub_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_sub(op, ord); } @@ -750,76 +750,76 @@ inline T *atomic_fetch_sub_explicit(Atomic *a, Ptrdiff op, } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_and(volatile Atomic *a, T op) { return a->fetch_and(op); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_and(Atomic *a, T op) { return a->fetch_and(op); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_and_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_and(op, ord); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_and_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_and(op, ord); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_or(volatile Atomic *a, T op) { return a->fetch_or(op); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_or(Atomic *a, T op) { return a->fetch_or(op); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_or_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_or(op, ord); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_or_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_or(op, ord); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_xor(volatile Atomic *a, T op) { return a->fetch_xor(op); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_xor(Atomic *a, T op) { return a->fetch_xor(op); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_xor_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_xor(op, ord); } template -inline EnableIf && !IsSame::value, T> +inline EnableIf && !IsSame, T> atomic_fetch_xor_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_xor(op, ord); } diff --git a/ostd/format.hh b/ostd/format.hh index 0265ddd..e4eda0d 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -401,7 +401,7 @@ protected: template() .to_format(declval(), declval())), bool - >::value + > >> inline bool to_format(const T &v, R &writer, const FormatSpec &fs) { return v.to_format(writer, fs); } @@ -692,11 +692,9 @@ namespace detail { return detail::write_u(writer, this, false, val); } - template::value - > Ptrdiff write(R &writer, bool, T val, EnableIf< - IsFloatingPoint, bool - > = true) { + template> + Ptrdiff write(R &writer, bool, T val, EnableIf, bool> + = true) { char buf[16], rbuf[128]; char fmtspec[Long + 1]; diff --git a/ostd/functional.hh b/ostd/functional.hh index b8acf08..b376f25 100644 --- a/ostd/functional.hh +++ b/ostd/functional.hh @@ -48,7 +48,7 @@ OSTD_DEFINE_BINARY_OP(BitXor, ^, T) #undef OSTD_DEFINE_BINARY_OP namespace detail { - template, char>::value> + template, char>> struct CharEqual { using FirstArgument = T *; using SecondArgument = T *; @@ -372,7 +372,7 @@ template<> struct ToHash: detail::ScalarHash { }; namespace detail { - template, char>::value> + template, char>> struct ToHashPtr { using Argument = T *; using Result = Size; diff --git a/ostd/internal/hashtable.hh b/ostd/internal/hashtable.hh index 5f38a15..57bea35 100644 --- a/ostd/internal/hashtable.hh +++ b/ostd/internal/hashtable.hh @@ -56,7 +56,7 @@ public: template HashRange(const HashRange &v, EnableIf< - IsSame, RemoveCv>::value && + IsSame, RemoveCv> && IsConvertible::value, bool > = true): p_node((Chain *)v.p_node) {} @@ -95,7 +95,7 @@ public: template BucketRange(const BucketRange &v, EnableIf< - IsSame, RemoveCv>::value && + IsSame, RemoveCv> && IsConvertible::value, bool > = true): p_node((Chain *)v.p_node), p_end((Chain *)v.p_end) {} diff --git a/ostd/maybe.hh b/ostd/maybe.hh index 71241e6..7451134 100644 --- a/ostd/maybe.hh +++ b/ostd/maybe.hh @@ -95,9 +95,9 @@ public: static_assert(!IsReference, "Initialization of Maybe with a reference type is not allowed."); - static_assert(!IsSame, InPlace>::value, + static_assert(!IsSame, InPlace>, "Initialization of Maybe with InPlace is not allowed."); - static_assert(!IsSame, Nothing>::value, + static_assert(!IsSame, Nothing>, "Initialization of Maybe with Nothing is not allowed."); static_assert(IsObject, "Initialization of Maybe with non-object type is not allowed."); @@ -159,7 +159,7 @@ public: } template, Value>::value && + IsSame, Value> && IsConstructible && IsAssignable >> Maybe &operator=(U &&v) { diff --git a/ostd/memory.hh b/ostd/memory.hh index bf5fb7c..46c2000 100644 --- a/ostd/memory.hh +++ b/ostd/memory.hh @@ -264,7 +264,7 @@ public: Box(Box &&u, EnableIf && IsConvertible::Pointer, Pointer>::value && IsConvertible::value - && (!IsReference || IsSame::value) + && (!IsReference || IsSame) > = Nat()): p_stor(u.release(), forward
(u.get_deleter())) {} Box &operator=(Box &&u) { @@ -327,13 +327,13 @@ namespace detail { template>, RemoveCv> - >::value> struct SameOrLessCvQualifiedBase: IsConvertible {}; + >> struct SameOrLessCvQualifiedBase: IsConvertible {}; template struct SameOrLessCvQualifiedBase: False {}; template - || IsSame::value || detail::HasElement::value + || IsSame || detail::HasElement::value > struct SameOrLessCvQualified: SameOrLessCvQualifiedBase {}; template @@ -393,7 +393,7 @@ public: && detail::SameOrLessCvQualified::Pointer, Pointer>::value && IsConvertible::value - && (!IsReference || IsSame::value)> = Nat() + && (!IsReference || IsSame)> = Nat() ): p_stor(u.release(), forward
(u.get_deleter())) {} Box &operator=(Box &&u) { @@ -885,7 +885,7 @@ namespace detail { IsSame(), declval(), declval())), True - >::value + > > {}; template @@ -938,7 +938,7 @@ namespace detail { IsSame< decltype(construct_test(declval(), declval(), declval()...)), True - >::value + > > {}; template @@ -969,8 +969,7 @@ namespace detail { template struct DestroyTest: IntegralConstant(), declval

())), True - >::value + IsSame(), declval

())), True> > {}; template @@ -1000,8 +999,7 @@ namespace detail { template struct AllocMaxSizeTest: IntegralConstant())), True - >::value + IsSame())), True> > {}; template @@ -1031,8 +1029,7 @@ namespace detail { template struct AllocCopyTest: IntegralConstant())), True - >::value + IsSame())), True> > {}; template diff --git a/ostd/string.hh b/ostd/string.hh index 4f40bcd..7d9fefe 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -210,7 +210,7 @@ class StringBase { template void ctor_from_range(R &range, EnableIf< IsFiniteRandomAccessRange::value && - IsSame>>::value, bool + IsSame>>, bool > = true) { if (range.empty()) return; RangeSize l = range.size(); @@ -223,7 +223,7 @@ class StringBase { template void ctor_from_range(R &range, EnableIf< !IsFiniteRandomAccessRange::value || - !IsSame>>::value, bool + !IsSame>>, bool > = true) { if (range.empty()) return; Size i = 0; @@ -669,7 +669,7 @@ namespace detail { template auto test_stringify(int) -> - decltype(IsSame().stringify()), String>()); + IntegralConstant().stringify()), String>>; template static True test_stringify(decltype(declval().to_string diff --git a/ostd/tuple.hh b/ostd/tuple.hh index cd91cfe..f14c682 100644 --- a/ostd/tuple.hh +++ b/ostd/tuple.hh @@ -53,18 +53,16 @@ namespace detail { "attempt to default construct a reference element in a tuple"); } - template, TupleLeaf>>, - IntegralConstant - >>::value>> + template, TupleLeaf>>>, + IntegralConstant> + >::value>> explicit TupleLeaf(T &&t): p_value(forward(t)) { static_assert(!IsReference || (IsLvalueReference && (IsLvalueReference || IsSame, - ReferenceWrapper> - >::value)) || + ReferenceWrapper>>)) || (IsRvalueReference && !IsLvalueReference), "attempt to construct a reference element in a tuple with an rvalue"); @@ -77,8 +75,7 @@ namespace detail { (IsLvalueReference && (IsLvalueReference || IsSame, - ReferenceWrapper> - >::value)), + ReferenceWrapper>>)), "attempt to construct a reference element in a tuple with an rvalue"); } @@ -89,8 +86,7 @@ namespace detail { (IsLvalueReference && (IsLvalueReference || IsSame, - ReferenceWrapper> - >::value)), + ReferenceWrapper>>)), "attempt to construct a reference element in a tuple with an rvalue"); } @@ -101,8 +97,7 @@ namespace detail { (IsLvalueReference && (IsLvalueReference || IsSame, - ReferenceWrapper> - >::value)), + ReferenceWrapper>>)), "attempt to construct a reference element in a tuple with an rvalue"); } @@ -143,7 +138,7 @@ namespace detail { template, TupleLeaf>>, + Not, TupleLeaf>>>, IntegralConstant> >::value> > explicit TupleLeaf(T &&t): H(forward(t)) {} @@ -187,8 +182,8 @@ namespace detail { template inline void tuple_swallow(A &&...) {} - template - struct TupleAll: IsSame, TupleAll<(A, true)...>> {}; + template struct TupleAll: + IntegralConstant, TupleAll<(A, true)...>>> {}; template struct TupleAllDefaultConstructible; diff --git a/ostd/type_traits.hh b/ostd/type_traits.hh index 0487e8f..07771a7 100644 --- a/ostd/type_traits.hh +++ b/ostd/type_traits.hh @@ -110,18 +110,23 @@ struct Not: IntegralConstant {}; /* type equality */ -template struct IsSame : False {}; -template struct IsSame: True {}; +namespace detail { + template struct IsSameBase : False {}; + template struct IsSameBase: True {}; +} + +template +static constexpr bool IsSame = detail::IsSameBase::value; /* is void */ template -static constexpr bool IsVoid = IsSame, void>::value; +static constexpr bool IsVoid = IsSame, void>; /* is null pointer */ template -static constexpr bool IsNullPointer = IsSame, Nullptr>::value; +static constexpr bool IsNullPointer = IsSame, Nullptr>; /* is integer */ @@ -326,12 +331,12 @@ template static constexpr bool IsAbstract = __is_abstract(T); /* is const */ template -static constexpr bool IsConst = IsSame::value; +static constexpr bool IsConst = IsSame; /* is volatile */ template -static constexpr bool IsVolatile = IsSame::value; +static constexpr bool IsVolatile = IsSame; /* is empty */ diff --git a/ostd/utility.hh b/ostd/utility.hh index 7da133b..dec9fd1 100644 --- a/ostd/utility.hh +++ b/ostd/utility.hh @@ -260,7 +260,7 @@ TupleElement> &&get(Pair &&p) { namespace detail { template, RemoveCv>::value, + bool = IsSame, RemoveCv>, bool = IsEmpty, bool = IsEmpty > struct CompressedPairSwitch; diff --git a/ostd/vector.hh b/ostd/vector.hh index 1bc53c4..75abd29 100644 --- a/ostd/vector.hh +++ b/ostd/vector.hh @@ -36,7 +36,7 @@ class Vector { template void ctor_from_range(R &range, EnableIf< IsFiniteRandomAccessRange::value && IsPod && - IsSame>>::value, bool + IsSame>>, bool > = true) { RangeSize l = range.size(); reserve(l); @@ -47,7 +47,7 @@ class Vector { template void ctor_from_range(R &range, EnableIf< !IsFiniteRandomAccessRange::value || !IsPod || - !IsSame>>::value, bool + !IsSame>>, bool > = true) { Size i = 0; for (; !range.empty(); range.pop_front()) { diff --git a/tests/utility.cc b/tests/utility.cc index a6d2b60..44bd63b 100644 --- a/tests/utility.cc +++ b/tests/utility.cc @@ -77,8 +77,8 @@ int main() { auto x = make_pair(5, 3.14f); - assert((IsSame::value)); - assert((IsSame::value)); + assert((IsSame)); + assert((IsSame)); assert(x.first == 5); assert(x.second == 3.14f);