From 2c4d6fee09d179185d61eb3f47cb843ff1740a0f Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 19 Jan 2016 19:14:02 +0000 Subject: [PATCH] convert TupleSize to template var --- ostd/array.hh | 2 +- ostd/format.hh | 2 +- ostd/internal/tuple.hh | 20 ++++++++++---------- ostd/tuple.hh | 5 ++--- ostd/types.hh | 6 ++++++ ostd/utility.hh | 2 +- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/ostd/array.hh b/ostd/array.hh index e861b1e..c27a4b1 100644 --- a/ostd/array.hh +++ b/ostd/array.hh @@ -77,7 +77,7 @@ struct Array { }; template -struct TupleSize>: Constant {}; +constexpr Size TupleSize> = N; template struct TupleElementBase> { diff --git a/ostd/format.hh b/ostd/format.hh index e4eda0d..9f9b54d 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -504,7 +504,7 @@ namespace detail { EnableIf::value, bool> = true) { if (expandval) { - return FmtTupleUnpacker::value>::unpack(writer, + return FmtTupleUnpacker>::unpack(writer, fmtn, esc, fmt, item); } return format_impl(writer, fmtn, esc, fmt, item); diff --git a/ostd/internal/tuple.hh b/ostd/internal/tuple.hh index a12789d..4878d26 100644 --- a/ostd/internal/tuple.hh +++ b/ostd/internal/tuple.hh @@ -18,11 +18,11 @@ template struct Array; /* tuple size */ -template struct TupleSize; +template constexpr Size TupleSize = detail::Undefined(); -template struct TupleSize: public TupleSize {}; -template struct TupleSize: public TupleSize {}; -template struct TupleSize: public TupleSize {}; +template constexpr Size TupleSize = TupleSize; +template constexpr Size TupleSize = TupleSize; +template constexpr Size TupleSize = TupleSize; /* tuple element */ @@ -142,8 +142,8 @@ public: detail::TupleTypes>::Type; }; -template struct TupleSize>: - Constant {}; +template constexpr Size TupleSize> + = sizeof...(T); template struct IsTupleLike>: True {}; @@ -173,7 +173,7 @@ namespace detail { using Type = typename MakeTupleTypesBase, T, S, E>::Type; }; - template>::value, Size S = 0> + template>, Size S = 0> using MakeTupleTypes = typename MakeTupleTypesImpl::Type; } @@ -204,7 +204,7 @@ namespace detail { template constexpr bool TupleConvertible = TupleConvertibleApply< - TupleSize>::value == TupleSize::value, T, U + TupleSize> == TupleSize, T, U >; } @@ -235,7 +235,7 @@ namespace detail { template constexpr bool TupleConstructible = TupleConstructibleApply< - TupleSize>::value == TupleSize::value, T, U + TupleSize> == TupleSize, T, U >; } @@ -266,7 +266,7 @@ namespace detail { template constexpr bool TupleAssignable = TupleAssignableApply< - TupleSize>::value == TupleSize::value, T, U + TupleSize> == TupleSize, T, U >; } diff --git a/ostd/tuple.hh b/ostd/tuple.hh index ac6375d..704f0fc 100644 --- a/ostd/tuple.hh +++ b/ostd/tuple.hh @@ -17,8 +17,7 @@ namespace ostd { /* tuple size */ -template struct TupleSize>: - Constant {}; +template constexpr Size TupleSize> = sizeof...(T); /* tuple element */ @@ -507,7 +506,7 @@ namespace detail { struct TupleLess { template bool operator()(const T &x, const U &y) { - constexpr Size J = TupleSize::value - I; + constexpr Size J = TupleSize - I; if (get(x) < get(y)) return true; if (get(y) < get(x)) return false; return TupleLess()(x, y); diff --git a/ostd/types.hh b/ostd/types.hh index 8ba0373..3a39e9d 100644 --- a/ostd/types.hh +++ b/ostd/types.hh @@ -84,6 +84,12 @@ using UintFast16 = uint_fast16_t; using UintFast32 = uint_fast32_t; using UintFast64 = uint_fast64_t; +/* used occasionally for template variables */ + +namespace detail { + template struct Undefined; +} + } #endif \ No newline at end of file diff --git a/ostd/utility.hh b/ostd/utility.hh index 3de716c..453c26d 100644 --- a/ostd/utility.hh +++ b/ostd/utility.hh @@ -209,7 +209,7 @@ inline constexpr bool operator>=(const Pair &x, const Pair &y) { } template -struct TupleSize>: Constant {}; +constexpr Size TupleSize> = 2; template struct TupleElementBase<0, Pair> {