From d53556d33621227f167f7ca8034a665fab411daf Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 12 Jan 2016 21:45:26 +0000 Subject: [PATCH] convert a part of type traits to template variables (reduces verbosity in a lot of places) --- ostd/atomic.hh | 42 ++++---- ostd/format.hh | 14 +-- ostd/functional.hh | 12 +-- ostd/internal/tuple.hh | 2 +- ostd/keyset.hh | 4 +- ostd/maybe.hh | 4 +- ostd/memory.hh | 65 +++++------ ostd/range.hh | 6 +- ostd/stream.hh | 2 +- ostd/string.hh | 9 +- ostd/tuple.hh | 38 +++---- ostd/type_traits.hh | 240 ++++++++++++++++++++--------------------- ostd/utility.hh | 5 +- ostd/vector.hh | 24 ++--- run_tests.py | 2 +- 15 files changed, 219 insertions(+), 250 deletions(-) diff --git a/ostd/atomic.hh b/ostd/atomic.hh index 6a3b7c2..223b5fb 100644 --- a/ostd/atomic.hh +++ b/ostd/atomic.hh @@ -288,7 +288,7 @@ template inline T kill_dependency(T v) { } namespace detail { - template::value && !IsSame::value> + template && !IsSame::value> struct Atomic { mutable AtomicBase p_a; @@ -656,13 +656,13 @@ inline bool atomic_compare_exchange_strong_explicit(Atomic *a, T *e, } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_add(volatile Atomic *a, T op) { return a->fetch_add(op); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, 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::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_add_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_add(op, ord); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, 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::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_sub(volatile Atomic *a, T op) { return a->fetch_sub(op); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, 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::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_sub_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_sub(op, ord); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, 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::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_and(volatile Atomic *a, T op) { return a->fetch_and(op); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_and(Atomic *a, T op) { return a->fetch_and(op); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_and_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_and(op, ord); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_and_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_and(op, ord); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_or(volatile Atomic *a, T op) { return a->fetch_or(op); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_or(Atomic *a, T op) { return a->fetch_or(op); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_or_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_or(op, ord); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_or_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_or(op, ord); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_xor(volatile Atomic *a, T op) { return a->fetch_xor(op); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_xor(Atomic *a, T op) { return a->fetch_xor(op); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, T> atomic_fetch_xor_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_xor(op, ord); } template -inline EnableIf::value && !IsSame::value, T> +inline EnableIf && !IsSame::value, 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 92c5860..1cd4f1d 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -111,7 +111,7 @@ namespace detail { /* retrieve width/precision */ template bool convert_arg_param(const T &val, int ¶m, EnableIf< - IsIntegral::value, bool + IsIntegral, bool > = true) { param = int(val); return true; @@ -119,7 +119,7 @@ namespace detail { template bool convert_arg_param(const T &, int &, EnableIf< - !IsIntegral::value, bool + !IsIntegral, bool > = true) { assert(false && "invalid argument for width/precision"); return false; @@ -677,7 +677,7 @@ namespace detail { /* signed integers */ template Ptrdiff write(R &writer, bool, T val, EnableIf< - IsIntegral::value && IsSigned::value, bool + IsIntegral && IsSigned, bool > = true) { using UT = MakeUnsigned; return detail::write_u(writer, this, val < 0, @@ -687,7 +687,7 @@ namespace detail { /* unsigned integers */ template Ptrdiff write(R &writer, bool, T val, EnableIf< - IsIntegral::value && IsUnsigned::value, bool + IsIntegral && IsUnsigned, bool > = true) { return detail::write_u(writer, this, false, val); } @@ -695,7 +695,7 @@ namespace detail { template::value > Ptrdiff write(R &writer, bool, T val, EnableIf< - IsFloatingPoint::value, bool + IsFloatingPoint, bool > = true) { char buf[16], rbuf[128]; char fmtspec[Long + 1]; @@ -741,7 +741,7 @@ namespace detail { /* generic value */ template Ptrdiff write(R &writer, bool, const T &val, EnableIf< - !IsArithmetic::value && + !IsArithmetic && !IsConstructible::value && FmtTostrTest::value && !FmtTofmtTest>::value, bool @@ -766,7 +766,7 @@ namespace detail { /* generic failure case */ template Ptrdiff write(R &, bool, const T &, EnableIf< - !IsArithmetic::value && + !IsArithmetic && !IsConstructible::value && !FmtTostrTest::value && !FmtTofmtTest>::value, bool diff --git a/ostd/functional.hh b/ostd/functional.hh index 2515895..8902fc9 100644 --- a/ostd/functional.hh +++ b/ostd/functional.hh @@ -127,9 +127,8 @@ template BinaryNegate not2(const T &fn) { /* endian swap */ -template::value -> struct EndianSwap; +template> +struct EndianSwap; template struct EndianSwap { @@ -171,9 +170,8 @@ template T endian_swap(T x) { return EndianSwap()(x); } namespace detail { - template::value - > struct EndianSame; + template> + struct EndianSame; template struct EndianSame { @@ -942,7 +940,7 @@ namespace detail { using Type = F; }; - template::value> + template> struct DcFuncType { using Type = F; }; diff --git a/ostd/internal/tuple.hh b/ostd/internal/tuple.hh index 0feb8e1..62da5df 100644 --- a/ostd/internal/tuple.hh +++ b/ostd/internal/tuple.hh @@ -157,7 +157,7 @@ namespace detail { struct MakeTupleTypesBase, T, S, E> { using TR = RemoveReference; using Type = typename MakeTupleTypesBase::value, + Conditional, TupleElement &, TupleElement>>, T, S + 1, E>::Type; }; diff --git a/ostd/keyset.hh b/ostd/keyset.hh index 0905efb..832c4ab 100644 --- a/ostd/keyset.hh +++ b/ostd/keyset.hh @@ -26,9 +26,7 @@ namespace detail { template struct KeysetBase { using Key = KeysetKey; - using RetKey = Conditional< - IsReference>::value, Key &, Key - >; + using RetKey = Conditional>, Key &, Key>; static inline RetKey get_key(const T &e) { return e.get_key(); } diff --git a/ostd/maybe.hh b/ostd/maybe.hh index 4b58108..1351051 100644 --- a/ostd/maybe.hh +++ b/ostd/maybe.hh @@ -93,13 +93,13 @@ class Maybe: private detail::MaybeStorage { public: using Value = T; - static_assert(!IsReference::value, + static_assert(!IsReference, "Initialization of Maybe with a reference type is not allowed."); static_assert(!IsSame, InPlace>::value, "Initialization of Maybe with InPlace is not allowed."); static_assert(!IsSame, Nothing>::value, "Initialization of Maybe with Nothing is not allowed."); - static_assert(IsObject::value, + static_assert(IsObject, "Initialization of Maybe with non-object type is not allowed."); static_assert(IsDestructible::value, "Initialization of Maybe with a non-destructible object is not allowed."); diff --git a/ostd/memory.hh b/ostd/memory.hh index a82eeba..580695f 100644 --- a/ostd/memory.hh +++ b/ostd/memory.hh @@ -153,7 +153,7 @@ namespace detail { template struct PointerTo { - static T pointer_to(Conditional>::value, + static T pointer_to(Conditional>, PointerToNat, PointerElement > &r) { return T::pointer_to(r); @@ -162,16 +162,14 @@ namespace detail { template struct PointerTo { - static T pointer_to(Conditional::value, - PointerToNat, T - > &r) { + static T pointer_to(Conditional, PointerToNat, T> &r) { return address_of(r); } }; } template -static T pointer_to(Conditional>::value, +static T pointer_to(Conditional>, detail::PointerToNat, PointerElement > &r) { return detail::PointerTo::pointer_to(r); @@ -242,36 +240,31 @@ private: public: constexpr Box(): p_stor(nullptr, D()) { - static_assert(!IsPointer::value, - "Box constructed with null fptr deleter"); + static_assert(!IsPointer, "Box constructed with null fptr deleter"); } constexpr Box(Nullptr): p_stor(nullptr, D()) { - static_assert(!IsPointer::value, - "Box constructed with null fptr deleter"); + static_assert(!IsPointer, "Box constructed with null fptr deleter"); } explicit Box(Pointer p): p_stor(p, D()) { - static_assert(!IsPointer::value, - "Box constructed with null fptr deleter"); + static_assert(!IsPointer, "Box constructed with null fptr deleter"); } - Box(Pointer p, Conditional::value, - D, AddLvalueReference - > d): p_stor(p, d) {} + Box(Pointer p, Conditional, D, AddLvalueReference> d): + p_stor(p, d) {} Box(Pointer p, RemoveReference &&d): p_stor(p, move(d)) { - static_assert(!IsReference::value, - "rvalue deleter cannot be a ref"); + static_assert(!IsReference, "rvalue deleter cannot be a ref"); } Box(Box &&u): p_stor(u.release(), forward(u.get_deleter())) {} template - Box(Box &&u, EnableIf::value + Box(Box &&u, EnableIf && IsConvertible::Pointer, Pointer>::value && IsConvertible::value - && (!IsReference::value || IsSame::value) + && (!IsReference || IsSame::value) > = Nat()): p_stor(u.release(), forward
(u.get_deleter())) {} Box &operator=(Box &&u) { @@ -281,7 +274,7 @@ public: } template - EnableIf::value + EnableIf && IsConvertible::Pointer, Pointer>::value && IsAssignable::value, Box & @@ -339,7 +332,7 @@ namespace detail { template struct SameOrLessCvQualifiedBase: False {}; - template::value + template || IsSame::value || detail::HasElement::value > struct SameOrLessCvQualified: SameOrLessCvQualifiedBase {}; @@ -361,54 +354,46 @@ private: public: constexpr Box(): p_stor(nullptr, D()) { - static_assert(!IsPointer::value, - "Box constructed with null fptr deleter"); + static_assert(!IsPointer, "Box constructed with null fptr deleter"); } constexpr Box(Nullptr): p_stor(nullptr, D()) { - static_assert(!IsPointer::value, - "Box constructed with null fptr deleter"); + static_assert(!IsPointer, "Box constructed with null fptr deleter"); } template explicit Box(U p, EnableIf< detail::SameOrLessCvQualified::value, Nat > = Nat()): p_stor(p, D()) { - static_assert(!IsPointer::value, - "Box constructed with null fptr deleter"); + static_assert(!IsPointer, "Box constructed with null fptr deleter"); } template Box(U p, Conditional< - IsReference::value, - D, AddLvalueReference + IsReference, D, AddLvalueReference > d, EnableIf::value, Nat> = Nat()): p_stor(p, d) {} - Box(Nullptr, Conditional::value, - D, AddLvalueReference - > d): p_stor(nullptr, d) {} + Box(Nullptr, Conditional, D, AddLvalueReference> d): + p_stor(nullptr, d) {} template Box(U p, RemoveReference &&d, EnableIf< detail::SameOrLessCvQualified::value, Nat > = Nat()): p_stor(p, move(d)) { - static_assert(!IsReference::value, - "rvalue deleter cannot be a ref"); + static_assert(!IsReference, "rvalue deleter cannot be a ref"); } Box(Nullptr, RemoveReference &&d): p_stor(nullptr, move(d)) { - static_assert(!IsReference::value, - "rvalue deleter cannot be a ref"); + static_assert(!IsReference, "rvalue deleter cannot be a ref"); } Box(Box &&u): p_stor(u.release(), forward(u.get_deleter())) {} template - Box(Box &&u, EnableIf::value + Box(Box &&u, EnableIf && detail::SameOrLessCvQualified::Pointer, Pointer>::value && IsConvertible::value - && (!IsReference::value || - IsSame::value)> = Nat() + && (!IsReference || IsSame::value)> = Nat() ): p_stor(u.release(), forward
(u.get_deleter())) {} Box &operator=(Box &&u) { @@ -418,7 +403,7 @@ public: } template - EnableIf::value + EnableIf && detail::SameOrLessCvQualified::Pointer, Pointer>::value && IsAssignable::value, @@ -866,7 +851,7 @@ namespace detail { template::value> struct IsAlwaysEqualBase { - using Type = typename IsEmpty::Type; + using Type = IntegralConstant>; }; template diff --git a/ostd/range.hh b/ostd/range.hh index ed5db82..4a0d1ba 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -874,7 +874,7 @@ public: template PointerRange(T *beg, U end, EnableIf< - (IsPointer::value || IsNullPointer::value) && + (IsPointer || IsNullPointer) && IsConvertible::value, Nat > = Nat()): p_beg(beg), p_end(end) {} @@ -985,7 +985,7 @@ public: Size put_n(const T *p, Size n) { Size ret = size(); if (n < ret) ret = n; - if (IsPod()) { + if (IsPod) { memcpy(p_beg, p, ret * sizeof(T)); p_beg += ret; return ret; @@ -1027,7 +1027,7 @@ namespace detail { template PointerRange iter(T *a, U b, EnableIf< - (IsPointer::vvalue || IsNullPointer::value) && + (IsPointer || IsNullPointer) && IsConvertible::value, detail::PtrNat > = detail::PtrNat()) { return PointerRange(a, b); diff --git a/ostd/stream.hh b/ostd/stream.hh index 86bbc50..30adb63 100644 --- a/ostd/stream.hh +++ b/ostd/stream.hh @@ -30,7 +30,7 @@ enum class StreamSeek { set = SEEK_SET }; -template::value> +template> struct StreamRange; namespace detail { diff --git a/ostd/string.hh b/ostd/string.hh index 4ccda17..4f40bcd 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -32,7 +32,7 @@ public: template CharRangeBase(T *beg, U end, EnableIf< - (IsPointer::value || IsNullPointer::value) && + (IsPointer || IsNullPointer) && IsConvertible::value, Nat > = Nat()): p_beg(beg), p_end(end) {} @@ -41,7 +41,7 @@ public: /* TODO: traits for utf-16/utf-32 string lengths, for now assume char */ template CharRangeBase(U beg, EnableIf< - IsConvertible::value && !IsArray::value, Nat + IsConvertible::value && !IsArray, Nat > = Nat()): p_beg(beg), p_end((T *)beg + (beg ? strlen(beg) : 0)) {} CharRangeBase(Nullptr): p_beg(nullptr), p_end(nullptr) {} @@ -318,7 +318,7 @@ public: template StringBase(U v, const EnableIf< - IsConvertible::value && !IsArray::value, A + IsConvertible::value && !IsArray, A > &a = A()): StringBase(ConstRange(v), a) {} template @@ -387,8 +387,7 @@ public: template EnableIf< - IsConvertible::value && !IsArray::value, - StringBase & + IsConvertible::value && !IsArray, StringBase & > operator=(U v) { return operator=(ConstRange(v)); } diff --git a/ostd/tuple.hh b/ostd/tuple.hh index 7fd4ded..4b7bd9b 100644 --- a/ostd/tuple.hh +++ b/ostd/tuple.hh @@ -30,26 +30,26 @@ struct TupleElementBase> { /* tuple leaf */ namespace detail { - template::value> + template> struct TupleLeaf { constexpr TupleLeaf(): p_value() { - static_assert(!IsReference::value, + static_assert(!IsReference, "attempt to default construct a reference element in a tuple"); } template TupleLeaf(IntegralConstant, const A &): p_value() { - static_assert(!IsReference::value, + static_assert(!IsReference, "attempt to default construct a reference element in a tuple"); } template TupleLeaf(IntegralConstant, const A &a): p_value(allocator_arg, a) { - static_assert(!IsReference::value, + static_assert(!IsReference, "attempt to default construct a reference element in a tuple"); } template TupleLeaf(IntegralConstant, const A &a): p_value(a) { - static_assert(!IsReference::value, + static_assert(!IsReference, "attempt to default construct a reference element in a tuple"); } @@ -57,23 +57,23 @@ namespace detail { typename = EnableIf, TupleLeaf>>, IsConstructible>::value>> explicit TupleLeaf(T &&t): p_value(forward(t)) { - static_assert(!IsReference::value || - (IsLvalueReference::value && - (IsLvalueReference::value || + static_assert(!IsReference || + (IsLvalueReference && + (IsLvalueReference || IsSame, ReferenceWrapper> >::value)) || - (IsRvalueReference::value && - !IsLvalueReference::value), + (IsRvalueReference && + !IsLvalueReference), "attempt to construct a reference element in a tuple with an rvalue"); } template explicit TupleLeaf(IntegralConstant, const A &, T &&t): p_value(forward(t)) { - static_assert(!IsLvalueReference::value || - (IsLvalueReference::value && - (IsLvalueReference::value || + static_assert(!IsLvalueReference || + (IsLvalueReference && + (IsLvalueReference || IsSame, ReferenceWrapper> >::value)), @@ -83,9 +83,9 @@ namespace detail { template explicit TupleLeaf(IntegralConstant, const A &a, T &&t): p_value(allocator_arg, a, forward(t)) { - static_assert(!IsLvalueReference::value || - (IsLvalueReference::value && - (IsLvalueReference::value || + static_assert(!IsLvalueReference || + (IsLvalueReference && + (IsLvalueReference || IsSame, ReferenceWrapper> >::value)), @@ -95,9 +95,9 @@ namespace detail { template explicit TupleLeaf(IntegralConstant, const A &a, T &&t): p_value(forward(t), a) { - static_assert(!IsLvalueReference::value || - (IsLvalueReference::value && - (IsLvalueReference::value || + static_assert(!IsLvalueReference || + (IsLvalueReference && + (IsLvalueReference || IsSame, ReferenceWrapper> >::value)), diff --git a/ostd/type_traits.hh b/ostd/type_traits.hh index 83fd9f3..9cb8708 100644 --- a/ostd/type_traits.hh +++ b/ostd/type_traits.hh @@ -24,7 +24,6 @@ namespace detail { template struct CommonTypeBase; } -template struct IsReference; template struct IsTriviallyDefaultConstructible; template @@ -111,25 +110,20 @@ struct Or: detail::OrBase {}; template struct Not: IntegralConstant {}; +/* type equality */ + +template struct IsSame : False {}; +template struct IsSame: True {}; + /* is void */ -namespace detail { - template struct IsVoidBase : False {}; - template< > struct IsVoidBase: True {}; -} - - template - struct IsVoid: detail::IsVoidBase> {}; +template +static constexpr bool IsVoid = IsSame, void>::value; /* is null pointer */ -namespace detail { - template struct IsNullPointerBase : False {}; - template< > struct IsNullPointerBase: True {}; -} - -template struct IsNullPointer: - detail::IsNullPointerBase> {}; +template +static constexpr bool IsNullPointer = IsSame, Nullptr>::value; /* is integer */ @@ -156,7 +150,7 @@ namespace detail { } template -struct IsIntegral: detail::IsIntegralBase> {}; +static constexpr bool IsIntegral = detail::IsIntegralBase>::value; /* is floating point */ @@ -170,13 +164,18 @@ namespace detail { } template -struct IsFloatingPoint: detail::IsFloatingPointBase> {}; +static constexpr bool IsFloatingPoint = detail::IsFloatingPointBase>::value; /* is array */ -template struct IsArray : False {}; -template struct IsArray: True {}; -template struct IsArray: True {}; +namespace detail { + template struct IsArrayBase : False {}; + template struct IsArrayBase: True {}; + template struct IsArrayBase: True {}; +} + +template +static constexpr bool IsArray = detail::IsArrayBase::value; /* is pointer */ @@ -186,29 +185,44 @@ namespace detail { } template -struct IsPointer: detail::IsPointerBase> {}; +static constexpr bool IsPointer = detail::IsPointerBase>::value; /* is lvalue reference */ -template struct IsLvalueReference : False {}; -template struct IsLvalueReference: True {}; +namespace detail { + template struct IsLvalueReferenceBase : False {}; + template struct IsLvalueReferenceBase: True {}; +} + +template +static constexpr bool IsLvalueReference = detail::IsLvalueReferenceBase::value; /* is rvalue reference */ -template struct IsRvalueReference : False {}; -template struct IsRvalueReference: True {}; +namespace detail { + template struct IsRvalueReferenceBase : False {}; + template struct IsRvalueReferenceBase: True {}; +} + +template +static constexpr bool IsRvalueReference = detail::IsRvalueReferenceBase::value; + +/* is reference */ + +template +static constexpr bool IsReference = IsLvalueReference || IsRvalueReference; /* is enum */ -template struct IsEnum: IntegralConstant {}; +template static constexpr bool IsEnum = __is_enum(T); /* is union */ -template struct IsUnion: IntegralConstant {}; +template static constexpr bool IsUnion = __is_union(T); /* is class */ -template struct IsClass: IntegralConstant {}; +template static constexpr bool IsClass = __is_class(T); /* is function */ @@ -222,11 +236,11 @@ namespace detail { template T &function_source(int); template FunctionTestDummy function_source(...); - template::value || - IsUnion::value || - IsVoid::value || - IsReference::value || - IsNullPointer::value + template || + IsUnion || + IsVoid || + IsReference || + IsNullPointer > struct IsFunctionBase: IntegralConstant(function_source(0))) == 1 > {}; @@ -234,25 +248,24 @@ namespace detail { template struct IsFunctionBase: False {}; } /* namespace detail */ -template struct IsFunction: detail::IsFunctionBase {}; +template +static constexpr bool IsFunction = detail::IsFunctionBase::value; /* is arithmetic */ -template struct IsArithmetic: IntegralConstant::value || IsFloatingPoint::value) -> {}; +template +static constexpr bool IsArithmetic = IsIntegral || IsFloatingPoint; /* is fundamental */ -template struct IsFundamental: IntegralConstant::value || IsVoid::value || IsNullPointer::value) -> {}; +template +static constexpr bool IsFundamental = IsArithmetic || IsVoid || + IsNullPointer; /* is compound */ -template struct IsCompound: IntegralConstant::value -> {}; +template +static constexpr bool IsCompound = !IsFundamental; /* is pointer to member */ @@ -265,7 +278,7 @@ namespace detail { } template -struct IsMemberPointer: detail::IsMemberPointerBase> {}; +static constexpr bool IsMemberPointer = detail::IsMemberPointerBase>::value; /* is pointer to member object */ @@ -275,12 +288,12 @@ namespace detail { template struct IsMemberObjectPointerBase: IntegralConstant::value + !IsFunction > {}; } -template struct IsMemberObjectPointer: - detail::IsMemberObjectPointerBase> {}; +template +static constexpr bool IsMemberObjectPointer = detail::IsMemberObjectPointerBase>::value; /* is pointer to member function */ @@ -290,115 +303,105 @@ namespace detail { template struct IsMemberFunctionPointerBase: IntegralConstant::value + IsFunction > {}; } -template struct IsMemberFunctionPointer: - detail::IsMemberFunctionPointerBase> {}; - -/* is reference */ - -template struct IsReference: IntegralConstant::value || IsRvalueReference::value) -> {}; +template +static constexpr bool IsMemberFunctionPointer = detail::IsMemberFunctionPointerBase>::value; /* is object */ -template struct IsObject: IntegralConstant::value && !IsVoid::value && !IsReference::value) -> {}; +template +static constexpr bool IsObject = !IsFunction && !IsVoid && !IsReference; /* is scalar */ -template struct IsScalar: IntegralConstant::value || IsPointer::value || IsEnum::value - || IsNullPointer ::value || IsArithmetic::value) -> {}; +template static constexpr bool IsScalar + = IsMemberPointer || IsPointer || IsEnum || + IsNullPointer || IsArithmetic; /* is abstract */ -template -struct IsAbstract: IntegralConstant {}; +template static constexpr bool IsAbstract = __is_abstract(T); /* is const */ -template struct IsConst : False {}; -template struct IsConst: True {}; +template +static constexpr bool IsConst = IsSame::value; /* is volatile */ -template struct IsVolatile : False {}; -template struct IsVolatile: True {}; +template +static constexpr bool IsVolatile = IsSame::value; /* is empty */ -template -struct IsEmpty: IntegralConstant {}; +template static constexpr bool IsEmpty = __is_empty(T); /* is POD */ -template struct IsPod: IntegralConstant {}; +template static constexpr bool IsPod = __is_pod(T); /* is polymorphic */ -template -struct IsPolymorphic: IntegralConstant {}; +template static constexpr bool IsPolymorphic = __is_polymorphic(T); /* is signed */ namespace detail { template - struct IsSignedBase: IntegralConstant {}; + struct IsSignedCore: IntegralConstant {}; + + template> + struct IsSignedBase: False {}; + + template + struct IsSignedBase: detail::IsSignedCore {}; } -template::value> -struct IsSigned: False {}; - template -struct IsSigned: detail::IsSignedBase {}; +static constexpr bool IsSigned = detail::IsSignedBase::value; /* is unsigned */ namespace detail { template - struct IsUnsignedBase: IntegralConstant {}; + struct IsUnsignedCore: IntegralConstant {}; + + template> + struct IsUnsignedBase: False {}; + + template + struct IsUnsignedBase: detail::IsUnsignedCore {}; } -template::value> -struct IsUnsigned: False {}; - template -struct IsUnsigned: detail::IsUnsignedBase {}; +static constexpr bool IsUnsigned = detail::IsUnsignedBase::value; /* is standard layout */ template -struct IsStandardLayout: IntegralConstant {}; +static constexpr bool IsStandardLayout = __is_standard_layout(T); /* is literal type */ template -struct IsLiteralType: IntegralConstant {}; +static constexpr bool IsLiteralType = __is_literal_type(T); /* is trivially copyable */ template -struct IsTriviallyCopyable: IntegralConstant>::value -> {}; +static constexpr bool IsTriviallyCopyable = IsScalar>; /* is trivial */ -template -struct IsTrivial: IntegralConstant {}; +template static constexpr bool IsTrivial = __is_trivial(T); /* has virtual destructor */ template -struct HasVirtualDestructor: IntegralConstant {}; +static constexpr bool HasVirtualDestructor = __has_virtual_destructor(T); /* is constructible */ @@ -427,7 +430,7 @@ namespace detail { /* scalars are default constructible, refs are not */ template - struct CtibleCore: IsScalar {}; + struct CtibleCore: IntegralConstant> {}; /* scalars and references are constructible from one arg if * implicitly convertible to scalar or reference */ @@ -449,7 +452,7 @@ namespace detail { /* treat scalars and refs separately */ template struct CtibleVoidCheck: CtibleCore< - (IsScalar::value || IsReference::value), T, A... + (IsScalar || IsReference), T, A... > {}; /* if any of T or A is void, IsConstructible should be false */ @@ -462,14 +465,14 @@ namespace detail { template struct CtibleContainsVoid { - static constexpr bool value = IsVoid::value + static constexpr bool value = IsVoid || CtibleContainsVoid::value; }; /* entry point */ template struct Ctible: CtibleVoidCheck< - CtibleContainsVoid::value || IsAbstract::value, + CtibleContainsVoid::value || IsAbstract, T, A... > {}; @@ -514,9 +517,8 @@ namespace detail { template False assign_test(Any, T &&); - template::value || - IsVoid::value - > struct IsAssignableBase: CommonTypeBase< + template || IsVoid> + struct IsAssignableBase: CommonTypeBase< decltype(assign_test(declval_in(), declval_in())) >::Type {}; @@ -569,13 +571,13 @@ namespace detail { template struct DtibleFalse; template struct DtibleFalse - : DtibleImpl::value> {}; + : DtibleImpl> {}; template struct DtibleFalse: False {}; } /* namespace detail */ template -struct IsDestructible: detail::DtibleFalse::value> {}; +struct IsDestructible: detail::DtibleFalse> {}; template struct IsDestructible: False {}; template< > struct IsDestructible: False {}; @@ -678,10 +680,10 @@ struct IsBaseOf: IntegralConstant {}; /* is convertible */ namespace detail { - template::value - || IsFunction::value || IsArray::value + template + || IsFunction || IsArray > struct IsConvertibleBase { - using Type = typename IsVoid::Type; + using Type = IntegralConstant>; }; template @@ -701,11 +703,6 @@ namespace detail { template struct IsConvertible: detail::IsConvertibleBase::Type {}; -/* type equality */ - -template struct IsSame : False {}; -template struct IsSame: True {}; - /* extent */ template @@ -762,8 +759,7 @@ namespace detail { /* add const, volatile, cv */ namespace detail { - template::value - || IsFunction::value || IsConst::value> + template || IsFunction || IsConst> struct AddConstCore { using Type = T; }; template struct AddConstCore { @@ -774,8 +770,7 @@ namespace detail { using Type = typename AddConstCore::Type; }; - template::value - || IsFunction::value || IsVolatile::value> + template || IsFunction || IsVolatile> struct AddVolatileCore { using Type = T; }; template struct AddVolatileCore { @@ -951,8 +946,8 @@ namespace detail { }; template>::value, - bool = IsVolatile>::value + bool = IsConst>, + bool = IsVolatile> > struct ApplyCv { using Type = U; }; @@ -987,12 +982,10 @@ namespace detail { using Type = const volatile U &; }; - template::value || - IsEnum::value> + template || IsEnum> struct MakeSignedCore {}; - template::value || - IsEnum::value> + template || IsEnum> struct MakeUnsignedCore {}; template @@ -1133,10 +1126,9 @@ namespace detail { private: using U = RemoveReference; public: - using Type = Conditional::value, + using Type = Conditional, RemoveExtent *, - Conditional::value, - AddPointer, RemoveCv> + Conditional, AddPointer, RemoveCv> >; }; } diff --git a/ostd/utility.hh b/ostd/utility.hh index 623f43c..7da133b 100644 --- a/ostd/utility.hh +++ b/ostd/utility.hh @@ -50,7 +50,7 @@ template AddRvalueReference declval(); namespace detail { template auto test_swap(int) -> - decltype(IsVoid().swap(declval()))>()); + IntegralConstant().swap(declval()))>>; template False test_swap(...); @@ -261,8 +261,7 @@ TupleElement> &&get(Pair &&p) { namespace detail { template, RemoveCv>::value, - bool = IsEmpty::value, - bool = IsEmpty::value + bool = IsEmpty, bool = IsEmpty > struct CompressedPairSwitch; /* neither empty */ diff --git a/ostd/vector.hh b/ostd/vector.hh index 121d251..1bc53c4 100644 --- a/ostd/vector.hh +++ b/ostd/vector.hh @@ -35,8 +35,7 @@ class Vector { template void ctor_from_range(R &range, EnableIf< - IsFiniteRandomAccessRange::value && - IsPod::value && + IsFiniteRandomAccessRange::value && IsPod && IsSame>>::value, bool > = true) { RangeSize l = range.size(); @@ -47,8 +46,7 @@ class Vector { template void ctor_from_range(R &range, EnableIf< - !IsFiniteRandomAccessRange::value || - !IsPod::value || + !IsFiniteRandomAccessRange::value || !IsPod || !IsSame>>::value, bool > = true) { Size i = 0; @@ -62,7 +60,7 @@ class Vector { } void copy_contents(const Vector &v) { - if (IsPod()) { + if (IsPod) { memcpy(p_buf.first(), v.p_buf.first(), p_len * sizeof(T)); } else { Pointer cur = p_buf.first(), last = p_buf.first() + p_len; @@ -120,7 +118,7 @@ public: if (a != v.p_buf.second()) { reserve(v.p_cap); p_len = v.p_len; - if (IsPod()) { + if (IsPod) { memcpy(p_buf.first(), v.p_buf.first(), p_len * sizeof(T)); } else { Pointer cur = p_buf.first(), last = p_buf.first() + p_len; @@ -140,7 +138,7 @@ public: Vector(ConstRange r, const A &a = A()): Vector(a) { reserve(r.size()); - if (IsPod()) { + if (IsPod) { memcpy(p_buf.first(), &r[0], r.size() * sizeof(T)); } else { for (Size i = 0; i < r.size(); ++i) @@ -165,7 +163,7 @@ public: } void clear() { - if (p_len > 0 && !IsPod()) { + if (p_len > 0 && !IsPod) { Pointer cur = p_buf.first(), last = p_buf.first() + p_len; while (cur != last) allocator_destroy(p_buf.second(), cur++); @@ -206,7 +204,7 @@ public: clear(); Size ilen = il.end() - il.begin(); reserve(ilen); - if (IsPod()) { + if (IsPod) { memcpy(p_buf.first(), il.begin(), ilen); } else { Pointer tbuf = p_buf.first(), ibuf = il.begin(), @@ -237,7 +235,7 @@ public: Size l = p_len; reserve(n); p_len = n; - if (IsPod()) { + if (IsPod) { for (Size i = l; i < p_len; ++i) { p_buf.first()[i] = T(v); } @@ -259,7 +257,7 @@ public: } Pointer tmp = allocator_allocate(p_buf.second(), p_cap); if (oc > 0) { - if (IsPod()) { + if (IsPod) { memcpy(tmp, p_buf.first(), p_len * sizeof(T)); } else { Pointer cur = p_buf.first(), tcur = tmp, @@ -307,7 +305,7 @@ public: Range push_n(const T *v, Size n) { reserve(p_len + n); - if (IsPod()) { + if (IsPod) { memcpy(p_buf.first() + p_len, v, n * sizeof(T)); } else { for (Size i = 0; i < n; ++i) @@ -327,7 +325,7 @@ public: } void pop() { - if (!IsPod()) { + if (!IsPod) { allocator_destroy(p_buf.second(), &p_buf.first()[--p_len]); } else { --p_len; diff --git a/run_tests.py b/run_tests.py index e13790f..3dea9ea 100644 --- a/run_tests.py +++ b/run_tests.py @@ -7,7 +7,7 @@ import subprocess as sp COMPILER = "c++" CXXFLAGS = [ - "-std=c++11", + "-std=c++14", "-Wall", "-Wextra", "-Wno-missing-braces", # clang false positive "-I."