convert TupleSize to template var

master
Daniel Kolesa 2016-01-19 19:14:02 +00:00
parent 29bf432800
commit 2c4d6fee09
6 changed files with 21 additions and 16 deletions

View File

@ -77,7 +77,7 @@ struct Array {
}; };
template<typename T, Size N> template<typename T, Size N>
struct TupleSize<Array<T, N>>: Constant<Size, N> {}; constexpr Size TupleSize<Array<T, N>> = N;
template<Size I, typename T, Size N> template<Size I, typename T, Size N>
struct TupleElementBase<I, Array<T, N>> { struct TupleElementBase<I, Array<T, N>> {

View File

@ -504,7 +504,7 @@ namespace detail {
EnableIf<IsTupleLike<T>::value, bool> EnableIf<IsTupleLike<T>::value, bool>
= true) { = true) {
if (expandval) { if (expandval) {
return FmtTupleUnpacker<TupleSize<T>::value>::unpack(writer, return FmtTupleUnpacker<TupleSize<T>>::unpack(writer,
fmtn, esc, fmt, item); fmtn, esc, fmt, item);
} }
return format_impl(writer, fmtn, esc, fmt, item); return format_impl(writer, fmtn, esc, fmt, item);

View File

@ -18,11 +18,11 @@ template<typename T, Size I> struct Array;
/* tuple size */ /* tuple size */
template<typename T> struct TupleSize; template<typename T> constexpr Size TupleSize = detail::Undefined<T>();
template<typename T> struct TupleSize<const T>: public TupleSize<T> {}; template<typename T> constexpr Size TupleSize<const T> = TupleSize<T>;
template<typename T> struct TupleSize<volatile T>: public TupleSize<T> {}; template<typename T> constexpr Size TupleSize<volatile T> = TupleSize<T>;
template<typename T> struct TupleSize<const volatile T>: public TupleSize<T> {}; template<typename T> constexpr Size TupleSize<const volatile T> = TupleSize<T>;
/* tuple element */ /* tuple element */
@ -142,8 +142,8 @@ public:
detail::TupleTypes<T...>>::Type; detail::TupleTypes<T...>>::Type;
}; };
template<typename ...T> struct TupleSize<detail::TupleTypes<T...>>: template<typename ...T> constexpr Size TupleSize<detail::TupleTypes<T...>>
Constant<Size, sizeof...(T)> {}; = sizeof...(T);
template<typename ...T> struct IsTupleLike<detail::TupleTypes<T...>>: True {}; template<typename ...T> struct IsTupleLike<detail::TupleTypes<T...>>: True {};
@ -173,7 +173,7 @@ namespace detail {
using Type = typename MakeTupleTypesBase<TupleTypes<>, T, S, E>::Type; using Type = typename MakeTupleTypesBase<TupleTypes<>, T, S, E>::Type;
}; };
template<typename T, Size E = TupleSize<RemoveReference<T>>::value, Size S = 0> template<typename T, Size E = TupleSize<RemoveReference<T>>, Size S = 0>
using MakeTupleTypes = typename MakeTupleTypesImpl<T, E, S>::Type; using MakeTupleTypes = typename MakeTupleTypesImpl<T, E, S>::Type;
} }
@ -204,7 +204,7 @@ namespace detail {
template<typename T, typename U> template<typename T, typename U>
constexpr bool TupleConvertible<T, U, true, true> = TupleConvertibleApply< constexpr bool TupleConvertible<T, U, true, true> = TupleConvertibleApply<
TupleSize<RemoveReference<T>>::value == TupleSize<U>::value, T, U TupleSize<RemoveReference<T>> == TupleSize<U>, T, U
>; >;
} }
@ -235,7 +235,7 @@ namespace detail {
template<typename T, typename U> template<typename T, typename U>
constexpr bool TupleConstructible<T, U, true, true> = TupleConstructibleApply< constexpr bool TupleConstructible<T, U, true, true> = TupleConstructibleApply<
TupleSize<RemoveReference<T>>::value == TupleSize<U>::value, T, U TupleSize<RemoveReference<T>> == TupleSize<U>, T, U
>; >;
} }
@ -266,7 +266,7 @@ namespace detail {
template<typename T, typename U> template<typename T, typename U>
constexpr bool TupleAssignable<T, U, true, true> = TupleAssignableApply< constexpr bool TupleAssignable<T, U, true, true> = TupleAssignableApply<
TupleSize<RemoveReference<T>>::value == TupleSize<U>::value, T, U TupleSize<RemoveReference<T>> == TupleSize<U>, T, U
>; >;
} }

View File

@ -17,8 +17,7 @@ namespace ostd {
/* tuple size */ /* tuple size */
template<typename ...T> struct TupleSize<Tuple<T...>>: template<typename ...T> constexpr Size TupleSize<Tuple<T...>> = sizeof...(T);
Constant<Size, sizeof...(T)> {};
/* tuple element */ /* tuple element */
@ -507,7 +506,7 @@ namespace detail {
struct TupleLess { struct TupleLess {
template<typename T, typename U> template<typename T, typename U>
bool operator()(const T &x, const U &y) { bool operator()(const T &x, const U &y) {
constexpr Size J = TupleSize<T>::value - I; constexpr Size J = TupleSize<T> - I;
if (get<J>(x) < get<J>(y)) return true; if (get<J>(x) < get<J>(y)) return true;
if (get<J>(y) < get<J>(x)) return false; if (get<J>(y) < get<J>(x)) return false;
return TupleLess<I - 1>()(x, y); return TupleLess<I - 1>()(x, y);

View File

@ -84,6 +84,12 @@ using UintFast16 = uint_fast16_t;
using UintFast32 = uint_fast32_t; using UintFast32 = uint_fast32_t;
using UintFast64 = uint_fast64_t; using UintFast64 = uint_fast64_t;
/* used occasionally for template variables */
namespace detail {
template<typename> struct Undefined;
}
} }
#endif #endif

View File

@ -209,7 +209,7 @@ inline constexpr bool operator>=(const Pair<T, U> &x, const Pair<T, U> &y) {
} }
template<typename T, typename U> template<typename T, typename U>
struct TupleSize<Pair<T, U>>: Constant<Size, 2> {}; constexpr Size TupleSize<Pair<T, U>> = 2;
template<typename T, typename U> template<typename T, typename U>
struct TupleElementBase<0, Pair<T, U>> { struct TupleElementBase<0, Pair<T, U>> {