forked from OctaForge/libostd
convert TupleSize to template var
This commit is contained in:
parent
29bf432800
commit
2c4d6fee09
|
@ -77,7 +77,7 @@ struct Array {
|
|||
};
|
||||
|
||||
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>
|
||||
struct TupleElementBase<I, Array<T, N>> {
|
||||
|
|
|
@ -504,7 +504,7 @@ namespace detail {
|
|||
EnableIf<IsTupleLike<T>::value, bool>
|
||||
= true) {
|
||||
if (expandval) {
|
||||
return FmtTupleUnpacker<TupleSize<T>::value>::unpack(writer,
|
||||
return FmtTupleUnpacker<TupleSize<T>>::unpack(writer,
|
||||
fmtn, esc, fmt, item);
|
||||
}
|
||||
return format_impl(writer, fmtn, esc, fmt, item);
|
||||
|
|
|
@ -18,11 +18,11 @@ template<typename T, Size I> struct Array;
|
|||
|
||||
/* 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> struct TupleSize<volatile T>: public TupleSize<T> {};
|
||||
template<typename T> struct TupleSize<const volatile T>: public TupleSize<T> {};
|
||||
template<typename T> constexpr Size TupleSize<const T> = TupleSize<T>;
|
||||
template<typename T> constexpr Size TupleSize<volatile T> = TupleSize<T>;
|
||||
template<typename T> constexpr Size TupleSize<const volatile T> = TupleSize<T>;
|
||||
|
||||
/* tuple element */
|
||||
|
||||
|
@ -142,8 +142,8 @@ public:
|
|||
detail::TupleTypes<T...>>::Type;
|
||||
};
|
||||
|
||||
template<typename ...T> struct TupleSize<detail::TupleTypes<T...>>:
|
||||
Constant<Size, sizeof...(T)> {};
|
||||
template<typename ...T> constexpr Size TupleSize<detail::TupleTypes<T...>>
|
||||
= sizeof...(T);
|
||||
|
||||
template<typename ...T> struct IsTupleLike<detail::TupleTypes<T...>>: True {};
|
||||
|
||||
|
@ -173,7 +173,7 @@ namespace detail {
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ namespace detail {
|
|||
|
||||
template<typename T, typename U>
|
||||
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>
|
||||
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>
|
||||
constexpr bool TupleAssignable<T, U, true, true> = TupleAssignableApply<
|
||||
TupleSize<RemoveReference<T>>::value == TupleSize<U>::value, T, U
|
||||
TupleSize<RemoveReference<T>> == TupleSize<U>, T, U
|
||||
>;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,7 @@ namespace ostd {
|
|||
|
||||
/* tuple size */
|
||||
|
||||
template<typename ...T> struct TupleSize<Tuple<T...>>:
|
||||
Constant<Size, sizeof...(T)> {};
|
||||
template<typename ...T> constexpr Size TupleSize<Tuple<T...>> = sizeof...(T);
|
||||
|
||||
/* tuple element */
|
||||
|
||||
|
@ -507,7 +506,7 @@ namespace detail {
|
|||
struct TupleLess {
|
||||
template<typename T, typename U>
|
||||
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>(y) < get<J>(x)) return false;
|
||||
return TupleLess<I - 1>()(x, y);
|
||||
|
|
|
@ -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<typename> struct Undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -209,7 +209,7 @@ inline constexpr bool operator>=(const Pair<T, U> &x, const Pair<T, U> &y) {
|
|||
}
|
||||
|
||||
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>
|
||||
struct TupleElementBase<0, Pair<T, U>> {
|
||||
|
|
Loading…
Reference in a new issue