From 8a1671f6ea24e97441283976f768f2ce44b7a52c Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 20 Jan 2016 18:42:29 +0000 Subject: [PATCH] convert most of the rest to template vars --- ostd/format.hh | 18 ++++++++---------- ostd/memory.hh | 15 ++++++--------- ostd/string.hh | 10 +++++----- ostd/tuple.hh | 26 +++++++++++++------------- ostd/type_traits.hh | 6 +++--- ostd/utility.hh | 2 +- 6 files changed, 36 insertions(+), 41 deletions(-) diff --git a/ostd/format.hh b/ostd/format.hh index 49b5faa..2e41356 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -466,7 +466,7 @@ namespace detail { static False test_fmt_range(...); template - using FmtRangeTest = decltype(test_fmt_range(0)); + constexpr bool FmtRangeTest = decltype(test_fmt_range(0))::value; template struct FmtTupleUnpacker { @@ -515,7 +515,7 @@ namespace detail { bool escape, bool expandval, ConstCharRange sep, const T &val, - EnableIf::value, bool> + EnableIf, bool> = true) { auto range = ostd::iter(val); if (range.empty()) return 0; @@ -544,7 +544,7 @@ namespace detail { template inline Ptrdiff write_range(R &, const FormatSpec *, bool, bool, ConstCharRange, const T &, - EnableIf::value, bool> + EnableIf, bool> = true) { assert(false && "invalid value for ranged format"); return -1; @@ -555,7 +555,7 @@ namespace detail { template static False test_fmt_tostr(...); template - using FmtTostrTest = decltype(test_fmt_tostr(0)); + constexpr bool FmtTostrTest = decltype(test_fmt_tostr(0))::value; /* non-printable escapes up to 0x20 (space) */ static constexpr const char *fmt_escapes[] = { @@ -603,7 +603,7 @@ namespace detail { static False test_tofmt(...); template - using FmtTofmtTest = decltype(test_tofmt(0)); + constexpr bool FmtTofmtTest = decltype(test_tofmt(0))::value; struct WriteSpec: FormatSpec { WriteSpec(): FormatSpec() {} @@ -741,8 +741,7 @@ namespace detail { Ptrdiff write(R &writer, bool, const T &val, EnableIf< !IsArithmetic && !IsConstructible && - FmtTostrTest::value && - !FmtTofmtTest>::value, bool + FmtTostrTest && !FmtTofmtTest>, bool > = true) { if (this->spec() != 's') { assert(false && "custom objects need '%s' format"); @@ -754,7 +753,7 @@ namespace detail { /* custom format case */ template Ptrdiff write(R &writer, bool, const T &val, - EnableIf>::value, bool + EnableIf>, bool > = true) { TostrRange sink(writer); if (!to_format(val, sink, *this)) return -1; @@ -766,8 +765,7 @@ namespace detail { Ptrdiff write(R &, bool, const T &, EnableIf< !IsArithmetic && !IsConstructible && - !FmtTostrTest::value && - !FmtTofmtTest>::value, bool + !FmtTostrTest && !FmtTofmtTest>, bool > = true) { assert(false && "value cannot be formatted"); return -1; diff --git a/ostd/memory.hh b/ostd/memory.hh index 7f6722d..8db68ee 100644 --- a/ostd/memory.hh +++ b/ostd/memory.hh @@ -1063,23 +1063,21 @@ namespace detail { }; template::value> - struct UsesAllocatorBase: Constant - > {}; + constexpr bool UsesAllocatorBase = IsConvertible; template - struct UsesAllocatorBase: False {}; + constexpr bool UsesAllocatorBase = false; } template -struct UsesAllocator: detail::UsesAllocatorBase {}; +constexpr bool UsesAllocator = detail::UsesAllocatorBase; /* uses allocator ctor */ namespace detail { template struct UsesAllocCtor { - static constexpr bool ua = UsesAllocator::value; + static constexpr bool ua = UsesAllocator; static constexpr bool ic = IsConstructible< T, AllocatorArg, A, Args... >; @@ -1088,9 +1086,8 @@ namespace detail { } template -struct UsesAllocatorConstructor: Constant::value -> {}; +constexpr int UsesAllocatorConstructor + = detail::UsesAllocCtor::value; } /* namespace ostd */ diff --git a/ostd/string.hh b/ostd/string.hh index d92b29c..440f688 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -658,7 +658,7 @@ namespace detail { template auto test_stringify(int) -> - Constant().stringify()), String>>; + BoolConstant().stringify()), String>>; template static True test_stringify(decltype(declval().to_string @@ -668,21 +668,21 @@ namespace detail { False test_stringify(...); template - using StringifyTest = decltype(test_stringify(0)); + constexpr bool StringifyTest = decltype(test_stringify(0))::value; template True test_iterable(decltype(ostd::iter(declval())) *); template static False test_iterable(...); template - using IterableTest = decltype(test_iterable(0)); + constexpr bool IterableTest = decltype(test_iterable(0))::value; } template struct ToString; template -struct ToString::value>> { +struct ToString>> { using Argument = RemoveCv>; using Result = String; @@ -701,7 +701,7 @@ struct ToString::value>> { template struct ToString>>::value + detail::StringifyTest>> >> { using Argument = RemoveCv>; using Result = String; diff --git a/ostd/tuple.hh b/ostd/tuple.hh index 704f0fc..bd97e83 100644 --- a/ostd/tuple.hh +++ b/ostd/tuple.hh @@ -177,15 +177,15 @@ namespace detail { template inline void tuple_swallow(A &&...) {} - template struct TupleAll: - Constant, TupleAll<(A, true)...>>> {}; + template constexpr bool TupleAll + = IsSame, TupleAll<(A, true)...>>; template - struct TupleAllDefaultConstructible; + constexpr bool TupleAllDefaultConstructible = detail::Undefined(); template - struct TupleAllDefaultConstructible>: - TupleAll...> {}; + constexpr bool TupleAllDefaultConstructible> + = TupleAll...>; } /* tuple implementation */ @@ -211,9 +211,9 @@ namespace detail { TupleIndices, TupleTypes, TupleIndices, TupleTypes, T &&...t): - TupleLeaf(UsesAllocatorConstructor(), a, + TupleLeaf(UsesAllocatorConstructor, a, forward(t))..., - TupleLeaf(UsesAllocatorConstructor(), a)... + TupleLeaf(UsesAllocatorConstructor, a)... {} template> TupleBase(AllocatorArg, const Alloc &a, T &&t): TupleLeaf(UsesAllocatorConstructor< A, Alloc, TupleElement> - >(), a, forward>>(get(t)))... + >, a, forward>>(get(t)))... {} template @@ -276,7 +276,7 @@ class Tuple { public: template)...>::value + detail::TupleAll<(D && IsDefaultConstructible)...> >> Tuple() {} explicit Tuple(const A &...t): @@ -307,7 +307,7 @@ public: (sizeof...(T) < sizeof...(A)) ? sizeof...(T) : sizeof...(A) > - >::value, bool + >, bool > = true> Tuple(T &&...t): p_base(detail::MakeTupleIndices(), @@ -337,7 +337,7 @@ public: (sizeof...(T) < sizeof...(A)) ? sizeof...(T) : sizeof...(A) > - >::value, bool + >, bool > = true> Tuple(T &&...t): p_base(detail::MakeTupleIndices(), @@ -360,7 +360,7 @@ public: (sizeof...(T) < sizeof...(A)) ? sizeof...(T) : sizeof...(A) > - >::value + > >> Tuple(AllocatorArg, const Alloc &a, T &&...t): p_base(allocator_arg, a, detail::MakeTupleIndices(), detail::MakeTupleTypes(), @@ -545,7 +545,7 @@ inline bool operator>=(const Tuple &x, const Tuple &y) { /* uses alloc */ template -struct UsesAllocator, A>: True {}; +constexpr bool UsesAllocator, A> = true; } /* namespace ostd */ diff --git a/ostd/type_traits.hh b/ostd/type_traits.hh index c45ef8a..7f5660e 100644 --- a/ostd/type_traits.hh +++ b/ostd/type_traits.hh @@ -612,7 +612,7 @@ namespace detail { template || IsFunction || IsArray > struct IsConvertibleBase { - using Type = Constant>; + static constexpr bool value = IsVoid; }; template @@ -625,12 +625,12 @@ namespace detail { template static False test(...); - using Type = decltype(test(0)); + static constexpr bool value = decltype(test(0))::value; }; } template constexpr bool IsConvertible - = detail::IsConvertibleBase::Type::value; + = detail::IsConvertibleBase::value; /* extent */ diff --git a/ostd/utility.hh b/ostd/utility.hh index 453c26d..d6d2315 100644 --- a/ostd/utility.hh +++ b/ostd/utility.hh @@ -50,7 +50,7 @@ template AddRvalueReference declval(); namespace detail { template auto test_swap(int) -> - Constant().swap(declval()))>>; + BoolConstant().swap(declval()))>>; template False test_swap(...);