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

View File

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

View File

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

View File

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

View File

@ -612,7 +612,7 @@ namespace detail {
template<typename F, typename T, bool = IsVoid<F>
|| IsFunction<T> || IsArray<T>
> struct IsConvertibleBase {
using Type = Constant<bool, IsVoid<T>>;
static constexpr bool value = IsVoid<T>;
};
template<typename F, typename T>
@ -625,12 +625,12 @@ namespace detail {
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
= detail::IsConvertibleBase<F, T>::Type::value;
= detail::IsConvertibleBase<F, T>::value;
/* extent */

View File

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