use standard declval

master
Daniel Kolesa 2017-01-29 15:29:11 +01:00
parent a41299505c
commit a8f7122d45
8 changed files with 53 additions and 62 deletions

View File

@ -849,7 +849,9 @@ public:
namespace detail {
template<typename R, typename F>
using MapReturnType = decltype(declval<F>()(declval<RangeReference<R>>()));
using MapReturnType = decltype(
std::declval<F>()(std::declval<RangeReference<R>>())
);
}
template<typename R, typename F>
@ -928,9 +930,9 @@ public:
namespace detail {
template<typename R, typename P>
using FilterPred = EnableIf<
IsSame<decltype(declval<P>()(declval<RangeReference<R>>())), bool>, P
>;
using FilterPred = EnableIf<IsSame<
decltype(std::declval<P>()(std::declval<RangeReference<R>>())), bool
>, P>;
}
template<typename R, typename P>

View File

@ -438,9 +438,9 @@ protected:
template<
typename T, typename R, typename = EnableIf<
IsSame<decltype(declval<T const &>()
.to_format(declval<R &>(), declval<FormatSpec const &>())), bool
>
IsSame<decltype(std::declval<T const &>().to_format(
std::declval<R &>(), std::declval<FormatSpec const &>()
)), bool>
>
>
inline bool to_format(T const &v, R &writer, FormatSpec const &fs) {
@ -615,7 +615,7 @@ namespace detail {
}
template<typename T>
static True test_fmt_tostr(decltype(ostd::to_string(declval<T>())) *);
static True test_fmt_tostr(decltype(ostd::to_string(std::declval<T>())) *);
template<typename>
static False test_fmt_tostr(...);
@ -662,7 +662,8 @@ namespace detail {
template<typename T, typename R>
static True test_tofmt(decltype(to_format(
declval<T const &>(), declval<R &>(), declval<FormatSpec const &>()
std::declval<T const &>(), std::declval<R &>(),
std::declval<FormatSpec const &>()
)) *);
template<typename, typename>

View File

@ -19,7 +19,7 @@ namespace ostd {
namespace detail {
template<typename T>
using KeysetKeyRet = decltype(declval<T const &>().get_key());
using KeysetKeyRet = decltype(std::declval<T const &>().get_key());
template<typename T>
using KeysetKey = Decay<KeysetKeyRet<T>> const;

View File

@ -533,7 +533,7 @@ namespace detail {
constexpr bool AllocateHintTest =
IsSame<
decltype(allocate_hint_test(
declval<A>(), declval<S>(), declval<CVP>()
std::declval<A>(), std::declval<S>(), std::declval<CVP>()
)), True
>;
@ -586,7 +586,7 @@ namespace detail {
constexpr bool ConstructTest =
IsSame<
decltype(construct_test(
declval<A>(), declval<T>(), declval<Args>()...
std::declval<A>(), std::declval<T>(), std::declval<Args>()...
)), True
>;
@ -619,8 +619,9 @@ namespace detail {
auto destroy_test(A const &, P &&) -> False;
template<typename A, typename P>
constexpr bool DestroyTest =
IsSame<decltype(destroy_test(declval<A>(), declval<P>())), True>;
constexpr bool DestroyTest = IsSame<
decltype(destroy_test(std::declval<A>(), std::declval<P>())), True
>;
template<typename A, typename T>
inline void destroy(True, A &a, T *p) {
@ -649,7 +650,7 @@ namespace detail {
template<typename A>
constexpr bool AllocMaxSizeTest =
IsSame<decltype(alloc_max_size_test(declval<A &>())), True>;
IsSame<decltype(alloc_max_size_test(std::declval<A &>())), True>;
template<typename A>
inline AllocatorSize<A> alloc_max_size(True, A const &a) {
@ -680,7 +681,7 @@ namespace detail {
template<typename A>
constexpr bool AllocCopyTest =
IsSame<decltype(alloc_copy_test(declval<A &>())), True>;
IsSame<decltype(alloc_copy_test(std::declval<A &>())), True>;
template<typename A>
inline AllocatorType<A> alloc_container_copy(True, A const &a) {

View File

@ -756,7 +756,7 @@ struct ranged_traits;
namespace detail {
template<typename C>
static True test_direct_iter(decltype(declval<C>().iter()) *);
static True test_direct_iter(decltype(std::declval<C>().iter()) *);
template<typename>
static False test_direct_iter(...);

View File

@ -779,11 +779,11 @@ namespace detail {
template<typename T, typename R>
static auto test_stringify(int) ->
BoolConstant<IsSame<decltype(declval<T>().stringify()), String>>;
BoolConstant<IsSame<decltype(std::declval<T>().stringify()), String>>;
template<typename T, typename R>
static True test_stringify(decltype(declval<T const &>().to_string
(declval<R &>())) *);
static True test_stringify(decltype(std::declval<T const &>().to_string
(std::declval<R &>())) *);
template<typename, typename>
static False test_stringify(...);
@ -792,7 +792,7 @@ namespace detail {
constexpr bool StringifyTest = decltype(test_stringify<T, R>(0))::value;
template<typename T>
static True test_iterable(decltype(ostd::iter(declval<T>())) *);
static True test_iterable(decltype(ostd::iter(std::declval<T>())) *);
template<typename>
static False test_iterable(...);

View File

@ -10,6 +10,8 @@
#include <limits.h>
#include <stddef.h>
#include <utility>
#include "ostd/types.hh"
namespace ostd {
@ -51,11 +53,6 @@ using RemoveReference = typename detail::RemoveReferenceBase<T>::Type;
template<typename T>
using RemoveAllExtents = typename detail::RemoveAllExtentsBase<T>::Type;
namespace detail {
template<typename T>
AddRvalueReference<T> declval_in() noexcept;
}
/* size in bits */
template<typename T>
@ -613,8 +610,6 @@ constexpr bool HasVirtualDestructor = __has_virtual_destructor(T);
/* is constructible */
namespace detail {
#define OSTD_MOVE(v) static_cast<RemoveReference<decltype(v)> &&>(v)
template<typename, typename T>
struct Select2nd { using Type = T; };
@ -622,18 +617,16 @@ namespace detail {
template<typename T, typename ...A>
typename Select2nd<
decltype(OSTD_MOVE(T(declval_in<A>()...))), True
decltype(std::move(T(std::declval<A>()...))), True
>::Type is_ctible_test(T &&, A &&...);
#undef OSTD_MOVE
template<typename ...A>
False is_ctible_test(Any, A &&...);
template<bool, typename T, typename ...A>
constexpr bool CtibleCore =
CommonTypeBase<
decltype(is_ctible_test(declval_in<T>(), declval_in<A>()...))
decltype(is_ctible_test(std::declval<T>(), std::declval<A>()...))
>::Type::value;
/* function types are not constructible */
@ -654,7 +647,7 @@ namespace detail {
template<typename T, typename U>
constexpr bool CtibleCore<true, T, U> = CommonTypeBase<
decltype(CtibleRef<T>::test(declval_in<U>()))
decltype(CtibleRef<T>::test(std::declval<U>()))
>::Type::value;
/* scalars and references are not constructible from multiple args */
@ -726,14 +719,14 @@ namespace detail {
template<typename T, typename ...A>
constexpr bool NothrowCtibleCore<true, false, T, A...> =
noexcept(T(declval_in<A>()...));
noexcept(T(std::declval<A>()...));
template<typename T>
void implicit_conv_to(T) noexcept {}
template<typename T, typename A>
constexpr bool NothrowCtibleCore<true, true, T, A> =
noexcept(ostd::detail::implicit_conv_to<T>(declval_in<A>()));
noexcept(ostd::detail::implicit_conv_to<T>(std::declval<A>()));
template<typename T, bool R, typename ...A>
constexpr bool NothrowCtibleCore<false, R, T, A...> = false;
@ -767,7 +760,7 @@ constexpr bool IsNothrowMoveConstructible =
namespace detail {
template<typename T, typename U>
typename detail::Select2nd<
decltype((declval_in<T>() = declval_in<U>())), True
decltype((std::declval<T>() = std::declval<U>())), True
>::Type assign_test(T &&, U &&);
template<typename T>
@ -775,7 +768,7 @@ namespace detail {
template<typename T, typename U, bool = IsVoid<T> || IsVoid<U>>
constexpr bool IsAssignableBase = CommonTypeBase<
decltype(assign_test(declval_in<T>(), declval_in<U>()))
decltype(assign_test(std::declval<T>(), std::declval<U>()))
>::Type::value;
template<typename T, typename U>
@ -808,7 +801,7 @@ namespace detail {
template<typename T, typename A>
constexpr bool NothrowAssignableCore<true, T, A> =
noexcept(declval_in<T>() = declval_in<A>());
noexcept(std::declval<T>() = std::declval<A>());
}
template<typename T, typename A> constexpr bool IsNothrowAssignable =
@ -835,7 +828,7 @@ namespace detail {
template<typename T> struct IsDestructorWellformed {
template<typename TT>
static char test(typename IsDtibleApply<
decltype(detail::declval_in<TT &>().~TT())
decltype(std::declval<TT &>().~TT())
>::Type);
template<typename TT>
@ -885,7 +878,7 @@ namespace detail {
constexpr bool NothrowDtibleCore<false, T> = false;
template<typename T>
constexpr bool NothrowDtibleCore<true, T> = noexcept(declval_in<T>().~T());
constexpr bool NothrowDtibleCore<true, T> = noexcept(std::declval<T>().~T());
}
template<typename T>
@ -995,7 +988,7 @@ namespace detail {
static void test_f(TT);
template<typename FF, typename TT,
typename = decltype(test_f<TT>(declval_in<FF>()))
typename = decltype(test_f<TT>(std::declval<FF>()))
>
static True test(int);
@ -1456,7 +1449,6 @@ namespace detail {
struct InvokeAny { InvokeAny(...); };
#define OSTD_FWD(T, _v) static_cast<T &&>(_v)
template<typename ...A>
inline auto func_invoke(InvokeAny, A &&...) -> InvokeNat;
@ -1472,9 +1464,9 @@ namespace detail {
>
>
inline auto func_invoke(F &&f, T &&v, A &&...args) ->
decltype((OSTD_FWD(T, v).*f)(OSTD_FWD(A, args)...))
decltype((std::forward<T>(v).*f)(std::forward<A>(args)...))
{
return (OSTD_FWD(T, v).*f)(OSTD_FWD(A, args)...);
return (std::forward<T>(v).*f)(std::forward<A>(args)...);
}
template<
@ -1488,9 +1480,9 @@ namespace detail {
>
>
inline auto func_invoke(F &&f, T &&v, A &&...args) ->
decltype(((*OSTD_FWD(T, v)).*f)(OSTD_FWD(A, args)...))
decltype(((*std::forward<T>(v)).*f)(std::forward<A>(args)...))
{
return ((*OSTD_FWD(T, v)).*f)(OSTD_FWD(A, args)...);
return ((*std::forward<T>(v)).*f)(std::forward<A>(args)...);
}
template<
@ -1503,8 +1495,8 @@ namespace detail {
>
>
>
inline auto func_invoke(F &&f, T &&v) -> decltype(OSTD_FWD(T, v).*f) {
return OSTD_FWD(T, v).*f;
inline auto func_invoke(F &&f, T &&v) -> decltype(std::forward<T>(v).*f) {
return std::forward<T>(v).*f;
}
template<
@ -1517,22 +1509,21 @@ namespace detail {
>
>
>
inline auto func_invoke(F &&f, T &&v) -> decltype((*OSTD_FWD(T, v)).*f) {
return (*OSTD_FWD(T, v)).*f;
inline auto func_invoke(F &&f, T &&v) -> decltype((*std::forward<T>(v)).*f) {
return (*std::forward<T>(v)).*f;
}
template<typename F, typename ...A>
inline auto func_invoke(F &&f, A &&...args) ->
decltype(OSTD_FWD(F, f)(OSTD_FWD(A, args)...))
decltype(std::forward<F>(f)(std::forward<A>(args)...))
{
return OSTD_FWD(F, f)(OSTD_FWD(A, args)...);
return std::forward<F>(f)(std::forward<A>(args)...);
}
#undef OSTD_FWD
template<typename F, typename ...A>
struct FuncInvokableBase {
using Type = decltype(
func_invoke(declval_in<F>(), declval_in<A>()...)
func_invoke(std::declval<F>(), std::declval<A>()...)
);
static constexpr bool value = !IsSame<Type, InvokeNat>;
};
@ -1596,7 +1587,7 @@ namespace detail {
template<typename T, typename U>
struct CommonTypeBase<T, U> {
using Type = Decay<decltype(
true ? detail::declval_in<T>(): detail::declval_in<U>()
true ? std::declval<T>(): std::declval<U>()
)>;
};

View File

@ -15,17 +15,13 @@
namespace ostd {
/* declval */
template<typename T>
AddRvalueReference<T> declval() noexcept;
/* swap */
namespace detail {
template<typename T>
auto test_swap(int) ->
BoolConstant<IsVoid<decltype(declval<T>().swap(declval<T &>()))>>;
auto test_swap(int) -> BoolConstant<IsVoid<
decltype(std::declval<T>().swap(std::declval<T &>()))
>>;
template<typename>
False test_swap(...);