Prefer _t over ::type form for std type traits

This commit is contained in:
Martin Hořeňovský 2021-08-16 17:01:00 +02:00
parent 88c27ffaf2
commit edad4d0af7
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
7 changed files with 13 additions and 17 deletions

View File

@ -93,8 +93,7 @@ namespace Catch {
} }
// sets lambda to be used in fun *and* executes benchmark! // sets lambda to be used in fun *and* executes benchmark!
template <typename Fun, template <typename Fun, std::enable_if_t<!Detail::is_related<Fun, Benchmark>::value, int> = 0>
typename std::enable_if<!Detail::is_related<Fun, Benchmark>::value, int>::type = 0>
Benchmark & operator=(Fun func) { Benchmark & operator=(Fun func) {
fun = Detail::BenchmarkFunction(func); fun = Detail::BenchmarkFunction(func);
run(); run();

View File

@ -20,7 +20,7 @@ namespace Catch {
template <typename T, bool Destruct> template <typename T, bool Destruct>
struct ObjectStorage struct ObjectStorage
{ {
using TStorage = typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type; using TStorage = std::aligned_storage_t<sizeof(T), std::alignment_of<T>::value>;
ObjectStorage() : data() {} ObjectStorage() : data() {}
@ -43,7 +43,7 @@ namespace Catch {
} }
template <bool AllowManualDestruction = !Destruct> template <bool AllowManualDestruction = !Destruct>
typename std::enable_if<AllowManualDestruction>::type destruct() std::enable_if_t<AllowManualDestruction> destruct()
{ {
stored_object().~T(); stored_object().~T();
} }
@ -51,10 +51,10 @@ namespace Catch {
private: private:
// If this is a constructor benchmark, destruct the underlying object // If this is a constructor benchmark, destruct the underlying object
template <typename U> template <typename U>
void destruct_on_exit(typename std::enable_if<Destruct, U>::type* = 0) { destruct<true>(); } void destruct_on_exit(std::enable_if_t<Destruct, U>* = 0) { destruct<true>(); }
// Otherwise, don't // Otherwise, don't
template <typename U> template <typename U>
void destruct_on_exit(typename std::enable_if<!Destruct, U>::type* = 0) { } void destruct_on_exit(std::enable_if_t<!Destruct, U>* = 0) { }
T& stored_object() { T& stored_object() {
return *static_cast<T*>(static_cast<void*>(&data)); return *static_cast<T*>(static_cast<void*>(&data));

View File

@ -57,12 +57,12 @@ namespace Catch {
} }
template <typename Fn, typename... Args> template <typename Fn, typename... Args>
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<!std::is_same<void, decltype(fn(args...))>::value>::type { inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<!std::is_same<void, decltype(fn(args...))>::value> {
deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...)); deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...));
} }
template <typename Fn, typename... Args> template <typename Fn, typename... Args>
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<std::is_same<void, decltype(fn(args...))>::value>::type { inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<std::is_same<void, decltype(fn(args...))>::value> {
CATCH_FORWARD(fn) (CATCH_FORWARD(args)...); CATCH_FORWARD(fn) (CATCH_FORWARD(args)...);
} }
} // namespace Benchmark } // namespace Benchmark

View File

@ -22,11 +22,9 @@
namespace Catch { namespace Catch {
namespace Benchmark { namespace Benchmark {
namespace Detail { namespace Detail {
template <typename T>
using Decay = typename std::decay<T>::type;
template <typename T, typename U> template <typename T, typename U>
struct is_related struct is_related
: std::is_same<Decay<T>, Decay<U>> {}; : std::is_same<std::decay_t<T>, std::decay_t<U>> {};
/// We need to reinvent std::function because every piece of code that might add overhead /// We need to reinvent std::function because every piece of code that might add overhead
/// in a measurement context needs to have consistent performance characteristics so that we /// in a measurement context needs to have consistent performance characteristics so that we
@ -76,9 +74,9 @@ namespace Catch {
: f(new model<do_nothing>{ {} }) {} : f(new model<do_nothing>{ {} }) {}
template <typename Fun, template <typename Fun,
typename std::enable_if<!is_related<Fun, BenchmarkFunction>::value, int>::type = 0> std::enable_if_t<!is_related<Fun, BenchmarkFunction>::value, int> = 0>
BenchmarkFunction(Fun&& fun) BenchmarkFunction(Fun&& fun)
: f(new model<typename std::decay<Fun>::type>(CATCH_FORWARD(fun))) {} : f(new model<std::decay_t<Fun>>(CATCH_FORWARD(fun))) {}
BenchmarkFunction( BenchmarkFunction&& that ) noexcept: BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
f( CATCH_MOVE( that.f ) ) {} f( CATCH_MOVE( that.f ) ) {}

View File

@ -26,7 +26,7 @@ namespace Catch {
Fun fun; Fun fun;
}; };
template <typename Fun> template <typename Fun>
repeater<typename std::decay<Fun>::type> repeat(Fun&& fun) { repeater<std::decay_t<Fun>> repeat(Fun&& fun) {
return { CATCH_FORWARD(fun) }; return { CATCH_FORWARD(fun) };
} }
} // namespace Detail } // namespace Detail

View File

@ -36,7 +36,7 @@ namespace Catch {
} }
template <typename Clock, typename Fun> template <typename Clock, typename Fun>
using run_for_at_least_argument_t = typename std::conditional<is_callable<Fun(Chronometer)>::value, Chronometer, int>::type; using run_for_at_least_argument_t = std::conditional_t<is_callable<Fun(Chronometer)>::value, Chronometer, int>;
[[noreturn]] [[noreturn]]

View File

@ -69,8 +69,7 @@ namespace Catch {
template <typename ClassT, typename ReturnT, typename ArgT> template <typename ClassT, typename ReturnT, typename ArgT>
struct UnaryLambdaTraits<ReturnT ( ClassT::* )( ArgT ) const> { struct UnaryLambdaTraits<ReturnT ( ClassT::* )( ArgT ) const> {
static const bool isValid = true; static const bool isValid = true;
using ArgType = typename std::remove_const< using ArgType = std::remove_const_t<std::remove_reference_t<ArgT>>;
typename std::remove_reference<ArgT>::type>::type;
using ReturnType = ReturnT; using ReturnType = ReturnT;
}; };