convert most of the rest to template vars

master
Daniel Kolesa 2016-01-20 18:42:29 +00:00
parent 7802efa1a1
commit 8a1671f6ea
6 changed files with 36 additions and 41 deletions

View File

@ -466,7 +466,7 @@ namespace detail {
static False test_fmt_range(...); static False test_fmt_range(...);
template<typename T> template<typename T>
using FmtRangeTest = decltype(test_fmt_range<T>(0)); constexpr bool FmtRangeTest = decltype(test_fmt_range<T>(0))::value;
template<Size I> template<Size I>
struct FmtTupleUnpacker { struct FmtTupleUnpacker {
@ -515,7 +515,7 @@ namespace detail {
bool escape, bool expandval, bool escape, bool expandval,
ConstCharRange sep, ConstCharRange sep,
const T &val, const T &val,
EnableIf<FmtRangeTest<T>::value, bool> EnableIf<FmtRangeTest<T>, bool>
= true) { = true) {
auto range = ostd::iter(val); auto range = ostd::iter(val);
if (range.empty()) return 0; if (range.empty()) return 0;
@ -544,7 +544,7 @@ namespace detail {
template<typename R, typename T> template<typename R, typename T>
inline Ptrdiff write_range(R &, const FormatSpec *, bool, bool, inline Ptrdiff write_range(R &, const FormatSpec *, bool, bool,
ConstCharRange, const T &, ConstCharRange, const T &,
EnableIf<!FmtRangeTest<T>::value, bool> EnableIf<!FmtRangeTest<T>, bool>
= true) { = true) {
assert(false && "invalid value for ranged format"); assert(false && "invalid value for ranged format");
return -1; return -1;
@ -555,7 +555,7 @@ namespace detail {
template<typename> static False test_fmt_tostr(...); template<typename> static False test_fmt_tostr(...);
template<typename T> template<typename T>
using FmtTostrTest = decltype(test_fmt_tostr<T>(0)); constexpr bool FmtTostrTest = decltype(test_fmt_tostr<T>(0))::value;
/* non-printable escapes up to 0x20 (space) */ /* non-printable escapes up to 0x20 (space) */
static constexpr const char *fmt_escapes[] = { static constexpr const char *fmt_escapes[] = {
@ -603,7 +603,7 @@ namespace detail {
static False test_tofmt(...); static False test_tofmt(...);
template<typename T, typename R> template<typename T, typename R>
using FmtTofmtTest = decltype(test_tofmt<T, R>(0)); constexpr bool FmtTofmtTest = decltype(test_tofmt<T, R>(0))::value;
struct WriteSpec: FormatSpec { struct WriteSpec: FormatSpec {
WriteSpec(): FormatSpec() {} WriteSpec(): FormatSpec() {}
@ -741,8 +741,7 @@ namespace detail {
Ptrdiff write(R &writer, bool, const T &val, EnableIf< Ptrdiff write(R &writer, bool, const T &val, EnableIf<
!IsArithmetic<T> && !IsArithmetic<T> &&
!IsConstructible<ConstCharRange, const T &> && !IsConstructible<ConstCharRange, const T &> &&
FmtTostrTest<T>::value && FmtTostrTest<T> && !FmtTofmtTest<T, TostrRange<R>>, bool
!FmtTofmtTest<T, TostrRange<R>>::value, bool
> = true) { > = true) {
if (this->spec() != 's') { if (this->spec() != 's') {
assert(false && "custom objects need '%s' format"); assert(false && "custom objects need '%s' format");
@ -754,7 +753,7 @@ namespace detail {
/* custom format case */ /* custom format case */
template<typename R, typename T> template<typename R, typename T>
Ptrdiff write(R &writer, bool, const T &val, Ptrdiff write(R &writer, bool, const T &val,
EnableIf<FmtTofmtTest<T, TostrRange<R>>::value, bool EnableIf<FmtTofmtTest<T, TostrRange<R>>, bool
> = true) { > = true) {
TostrRange<R> sink(writer); TostrRange<R> sink(writer);
if (!to_format(val, sink, *this)) return -1; if (!to_format(val, sink, *this)) return -1;
@ -766,8 +765,7 @@ namespace detail {
Ptrdiff write(R &, bool, const T &, EnableIf< Ptrdiff write(R &, bool, const T &, EnableIf<
!IsArithmetic<T> && !IsArithmetic<T> &&
!IsConstructible<ConstCharRange, const T &> && !IsConstructible<ConstCharRange, const T &> &&
!FmtTostrTest<T>::value && !FmtTostrTest<T> && !FmtTofmtTest<T, TostrRange<R>>, bool
!FmtTofmtTest<T, TostrRange<R>>::value, bool
> = true) { > = true) {
assert(false && "value cannot be formatted"); assert(false && "value cannot be formatted");
return -1; return -1;

View File

@ -1063,23 +1063,21 @@ namespace detail {
}; };
template<typename T, typename A, bool = HasAllocatorType<T>::value> template<typename T, typename A, bool = HasAllocatorType<T>::value>
struct UsesAllocatorBase: Constant<bool, constexpr bool UsesAllocatorBase = IsConvertible<A, typename T::Allocator>;
IsConvertible<A, typename T::Allocator>
> {};
template<typename T, typename A> template<typename T, typename A>
struct UsesAllocatorBase<T, A, false>: False {}; constexpr bool UsesAllocatorBase<T, A, false> = false;
} }
template<typename T, typename A> template<typename T, typename A>
struct UsesAllocator: detail::UsesAllocatorBase<T, A> {}; constexpr bool UsesAllocator = detail::UsesAllocatorBase<T, A>;
/* uses allocator ctor */ /* uses allocator ctor */
namespace detail { namespace detail {
template<typename T, typename A, typename ...Args> template<typename T, typename A, typename ...Args>
struct UsesAllocCtor { struct UsesAllocCtor {
static constexpr bool ua = UsesAllocator<T, A>::value; static constexpr bool ua = UsesAllocator<T, A>;
static constexpr bool ic = IsConstructible< static constexpr bool ic = IsConstructible<
T, AllocatorArg, A, Args... T, AllocatorArg, A, Args...
>; >;
@ -1088,9 +1086,8 @@ namespace detail {
} }
template<typename T, typename A, typename ...Args> template<typename T, typename A, typename ...Args>
struct UsesAllocatorConstructor: Constant<int, constexpr int UsesAllocatorConstructor
detail::UsesAllocCtor<T, A, Args...>::value = detail::UsesAllocCtor<T, A, Args...>::value;
> {};
} /* namespace ostd */ } /* namespace ostd */

View File

@ -658,7 +658,7 @@ namespace detail {
template<typename T, typename R> template<typename T, typename R>
auto test_stringify(int) -> auto test_stringify(int) ->
Constant<bool, IsSame<decltype(declval<T>().stringify()), String>>; BoolConstant<IsSame<decltype(declval<T>().stringify()), String>>;
template<typename T, typename R> template<typename T, typename R>
static True test_stringify(decltype(declval<const T &>().to_string static True test_stringify(decltype(declval<const T &>().to_string
@ -668,21 +668,21 @@ namespace detail {
False test_stringify(...); False test_stringify(...);
template<typename T, typename R> template<typename T, typename R>
using StringifyTest = decltype(test_stringify<T, R>(0)); constexpr bool StringifyTest = decltype(test_stringify<T, R>(0))::value;
template<typename T> template<typename T>
True test_iterable(decltype(ostd::iter(declval<T>())) *); True test_iterable(decltype(ostd::iter(declval<T>())) *);
template<typename> static False test_iterable(...); template<typename> static False test_iterable(...);
template<typename T> template<typename T>
using IterableTest = decltype(test_iterable<T>(0)); constexpr bool IterableTest = decltype(test_iterable<T>(0))::value;
} }
template<typename T, typename = void> template<typename T, typename = void>
struct ToString; struct ToString;
template<typename T> template<typename T>
struct ToString<T, EnableIf<detail::IterableTest<T>::value>> { struct ToString<T, EnableIf<detail::IterableTest<T>>> {
using Argument = RemoveCv<RemoveReference<T>>; using Argument = RemoveCv<RemoveReference<T>>;
using Result = String; using Result = String;
@ -701,7 +701,7 @@ struct ToString<T, EnableIf<detail::IterableTest<T>::value>> {
template<typename T> template<typename T>
struct ToString<T, EnableIf< struct ToString<T, EnableIf<
detail::StringifyTest<T, detail::TostrRange<AppenderRange<String>>>::value detail::StringifyTest<T, detail::TostrRange<AppenderRange<String>>>
>> { >> {
using Argument = RemoveCv<RemoveReference<T>>; using Argument = RemoveCv<RemoveReference<T>>;
using Result = String; using Result = String;

View File

@ -177,15 +177,15 @@ namespace detail {
template<typename ...A> template<typename ...A>
inline void tuple_swallow(A &&...) {} inline void tuple_swallow(A &&...) {}
template<bool ...A> struct TupleAll: template<bool ...A> constexpr bool TupleAll
Constant<bool, IsSame<TupleAll<A...>, TupleAll<(A, true)...>>> {}; = IsSame<TupleAll<A...>, TupleAll<(A, true)...>>;
template<typename T> template<typename T>
struct TupleAllDefaultConstructible; constexpr bool TupleAllDefaultConstructible = detail::Undefined<T>();
template<typename ...A> template<typename ...A>
struct TupleAllDefaultConstructible<TupleTypes<A...>>: constexpr bool TupleAllDefaultConstructible<TupleTypes<A...>>
TupleAll<IsDefaultConstructible<A>...> {}; = TupleAll<IsDefaultConstructible<A>...>;
} }
/* tuple implementation */ /* tuple implementation */
@ -211,9 +211,9 @@ namespace detail {
TupleIndices<Ia...>, TupleTypes<Aa...>, TupleIndices<Ia...>, TupleTypes<Aa...>,
TupleIndices<Ib...>, TupleTypes<Ab...>, TupleIndices<Ib...>, TupleTypes<Ab...>,
T &&...t): T &&...t):
TupleLeaf<Ia, Aa>(UsesAllocatorConstructor<Aa, Alloc, T>(), a, TupleLeaf<Ia, Aa>(UsesAllocatorConstructor<Aa, Alloc, T>, a,
forward<T>(t))..., forward<T>(t))...,
TupleLeaf<Ib, Ab>(UsesAllocatorConstructor<Ab, Alloc>(), a)... TupleLeaf<Ib, Ab>(UsesAllocatorConstructor<Ab, Alloc>, a)...
{} {}
template<typename T, typename = EnableIf< template<typename T, typename = EnableIf<
@ -227,7 +227,7 @@ namespace detail {
>> TupleBase(AllocatorArg, const Alloc &a, T &&t): >> TupleBase(AllocatorArg, const Alloc &a, T &&t):
TupleLeaf<I, A>(UsesAllocatorConstructor< TupleLeaf<I, A>(UsesAllocatorConstructor<
A, Alloc, TupleElement<I, MakeTupleTypes<T>> A, Alloc, TupleElement<I, MakeTupleTypes<T>>
>(), a, forward<TupleElement<I, MakeTupleTypes<T>>>(get<I>(t)))... >, a, forward<TupleElement<I, MakeTupleTypes<T>>>(get<I>(t)))...
{} {}
template<typename T> template<typename T>
@ -276,7 +276,7 @@ class Tuple {
public: public:
template<bool D = true, typename = EnableIf< template<bool D = true, typename = EnableIf<
detail::TupleAll<(D && IsDefaultConstructible<A>)...>::value detail::TupleAll<(D && IsDefaultConstructible<A>)...>
>> Tuple() {} >> Tuple() {}
explicit Tuple(const A &...t): explicit Tuple(const A &...t):
@ -307,7 +307,7 @@ public:
(sizeof...(T) < sizeof...(A)) ? sizeof...(T) (sizeof...(T) < sizeof...(A)) ? sizeof...(T)
: sizeof...(A) : sizeof...(A)
> >
>::value, bool >, bool
> = true> > = true>
Tuple(T &&...t): Tuple(T &&...t):
p_base(detail::MakeTupleIndices<sizeof...(T)>(), p_base(detail::MakeTupleIndices<sizeof...(T)>(),
@ -337,7 +337,7 @@ public:
(sizeof...(T) < sizeof...(A)) ? sizeof...(T) (sizeof...(T) < sizeof...(A)) ? sizeof...(T)
: sizeof...(A) : sizeof...(A)
> >
>::value, bool >, bool
> = true> > = true>
Tuple(T &&...t): Tuple(T &&...t):
p_base(detail::MakeTupleIndices<sizeof...(T)>(), p_base(detail::MakeTupleIndices<sizeof...(T)>(),
@ -360,7 +360,7 @@ public:
(sizeof...(T) < sizeof...(A)) ? sizeof...(T) (sizeof...(T) < sizeof...(A)) ? sizeof...(T)
: sizeof...(A) : sizeof...(A)
> >
>::value >
>> Tuple(AllocatorArg, const Alloc &a, T &&...t): >> Tuple(AllocatorArg, const Alloc &a, T &&...t):
p_base(allocator_arg, a, detail::MakeTupleIndices<sizeof...(T)>(), p_base(allocator_arg, a, detail::MakeTupleIndices<sizeof...(T)>(),
detail::MakeTupleTypes<Tuple, sizeof...(T)>(), detail::MakeTupleTypes<Tuple, sizeof...(T)>(),
@ -545,7 +545,7 @@ inline bool operator>=(const Tuple<T...> &x, const Tuple<U...> &y) {
/* uses alloc */ /* uses alloc */
template<typename ...T, typename A> template<typename ...T, typename A>
struct UsesAllocator<Tuple<T...>, A>: True {}; constexpr bool UsesAllocator<Tuple<T...>, A> = true;
} /* namespace ostd */ } /* namespace ostd */

View File

@ -612,7 +612,7 @@ namespace detail {
template<typename F, typename T, bool = IsVoid<F> template<typename F, typename T, bool = IsVoid<F>
|| IsFunction<T> || IsArray<T> || IsFunction<T> || IsArray<T>
> struct IsConvertibleBase { > struct IsConvertibleBase {
using Type = Constant<bool, IsVoid<T>>; static constexpr bool value = IsVoid<T>;
}; };
template<typename F, typename T> template<typename F, typename T>
@ -625,12 +625,12 @@ namespace detail {
template<typename, typename> static False test(...); template<typename, typename> static False test(...);
using Type = decltype(test<F, T>(0)); static constexpr bool value = decltype(test<F, T>(0))::value;
}; };
} }
template<typename F, typename T> constexpr bool IsConvertible template<typename F, typename T> constexpr bool IsConvertible
= detail::IsConvertibleBase<F, T>::Type::value; = detail::IsConvertibleBase<F, T>::value;
/* extent */ /* extent */

View File

@ -50,7 +50,7 @@ template<typename T> AddRvalueReference<T> declval();
namespace detail { namespace detail {
template<typename T> template<typename T>
auto test_swap(int) -> auto test_swap(int) ->
Constant<bool, IsVoid<decltype(declval<T>().swap(declval<T &>()))>>; BoolConstant<IsVoid<decltype(declval<T>().swap(declval<T &>()))>>;
template<typename> template<typename>
False test_swap(...); False test_swap(...);