Skip to content

Commit

Permalink
C++17 cleanup: traits replace ::value with _v (NVIDIA#10319)
Browse files Browse the repository at this point in the history
- replace `std::is_*<T>::value` with `std::is_*_v<T>`

Please suggest any other C++17 tech debts.

Authors:
  - Karthikeyan (https://github.com/karthikeyann)

Approvers:
  - Conor Hoekstra (https://github.com/codereport)
  - Christopher Harris (https://github.com/cwharris)

URL: rapidsai/cudf#10319
  • Loading branch information
karthikeyann authored Feb 22, 2022
1 parent cf65ac3 commit c163886
Show file tree
Hide file tree
Showing 67 changed files with 403 additions and 431 deletions.
15 changes: 7 additions & 8 deletions cpp/benchmarks/common/generate_input.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,15 +69,14 @@ distribution_id default_distribution_id()
return distribution_id::GEOMETRIC;
}

template <typename T,
std::enable_if_t<!std::is_unsigned<T>::value && cudf::is_numeric<T>()>* = nullptr>
template <typename T, std::enable_if_t<!std::is_unsigned_v<T> && cudf::is_numeric<T>()>* = nullptr>
distribution_id default_distribution_id()
{
return distribution_id::NORMAL;
}

template <typename T,
std::enable_if_t<!std::is_same_v<T, bool> && std::is_unsigned<T>::value &&
std::enable_if_t<!std::is_same_v<T, bool> && std::is_unsigned_v<T> &&
cudf::is_numeric<T>()>* = nullptr>
distribution_id default_distribution_id()
{
Expand Down Expand Up @@ -226,7 +225,7 @@ class data_profile {
public:
template <
typename T,
typename std::enable_if_t<!std::is_same_v<T, bool> && std::is_integral<T>::value, T>* = nullptr>
typename std::enable_if_t<!std::is_same_v<T, bool> && std::is_integral_v<T>, T>* = nullptr>
distribution_params<T> get_distribution_params() const
{
auto it = int_params.find(cudf::type_to_id<T>());
Expand All @@ -239,7 +238,7 @@ class data_profile {
}
}

template <typename T, typename std::enable_if_t<std::is_floating_point<T>::value, T>* = nullptr>
template <typename T, typename std::enable_if_t<std::is_floating_point_v<T>, T>* = nullptr>
distribution_params<T> get_distribution_params() const
{
auto it = float_params.find(cudf::type_to_id<T>());
Expand Down Expand Up @@ -307,7 +306,7 @@ class data_profile {
// discrete distributions (integers, strings, lists). Otherwise the call with have no effect.
template <typename T,
typename Type_enum,
typename std::enable_if_t<std::is_integral<T>::value, T>* = nullptr>
typename std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
void set_distribution_params(Type_enum type_or_group,
distribution_id dist,
T lower_bound,
Expand All @@ -331,7 +330,7 @@ class data_profile {
// have continuous distributions (floating point types). Otherwise the call with have no effect.
template <typename T,
typename Type_enum,
typename std::enable_if_t<std::is_floating_point<T>::value, T>* = nullptr>
typename std::enable_if_t<std::is_floating_point_v<T>, T>* = nullptr>
void set_distribution_params(Type_enum type_or_group,
distribution_id dist,
T lower_bound,
Expand Down
10 changes: 5 additions & 5 deletions cpp/benchmarks/common/random_distribution_factory.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,7 @@
/**
* @brief Generates a normal(binomial) distribution between zero and upper_bound.
*/
template <typename T, typename std::enable_if_t<std::is_integral<T>::value, T>* = nullptr>
template <typename T, typename std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
auto make_normal_dist(T upper_bound)
{
using uT = typename std::make_unsigned<T>::type;
Expand All @@ -42,7 +42,7 @@ auto make_normal_dist(T upper_bound)
return std::normal_distribution<T>(mean, stddev);
}

template <typename T, typename std::enable_if_t<std::is_integral<T>::value, T>* = nullptr>
template <typename T, typename std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
auto make_uniform_dist(T range_start, T range_end)
{
return std::uniform_int_distribution<T>(range_start, range_end);
Expand All @@ -62,7 +62,7 @@ double geometric_dist_p(T range_size)
return p ? p : std::numeric_limits<double>::epsilon();
}

template <typename T, typename std::enable_if_t<std::is_integral<T>::value, T>* = nullptr>
template <typename T, typename std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
auto make_geometric_dist(T range_start, T range_end)
{
using uT = typename std::make_unsigned<T>::type;
Expand All @@ -82,7 +82,7 @@ auto make_geometric_dist(T range_start, T range_end)
template <typename T>
using distribution_fn = std::function<T(std::mt19937&)>;

template <typename T, typename std::enable_if_t<std::is_integral<T>::value, T>* = nullptr>
template <typename T, typename std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
distribution_fn<T> make_distribution(distribution_id did, T lower_bound, T upper_bound)
{
switch (did) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/benchmarks/type_dispatcher/type_dispatcher.cu
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct Functor {
};

template <class Float, FunctorType ft>
struct Functor<Float, ft, typename std::enable_if_t<std::is_floating_point<Float>::value>> {
struct Functor<Float, ft, typename std::enable_if_t<std::is_floating_point_v<Float>>> {
static __device__ Float f(Float x)
{
if (ft == BANDWIDTH_BOUND) {
Expand Down
42 changes: 21 additions & 21 deletions cpp/include/cudf/ast/detail/operators.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, NVIDIA CORPORATION.
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,10 +35,10 @@ namespace detail {

// Traits for valid operator / type combinations
template <typename Op, typename LHS, typename RHS>
constexpr bool is_valid_binary_op = cuda::std::is_invocable<Op, LHS, RHS>::value;
constexpr bool is_valid_binary_op = cuda::std::is_invocable_v<Op, LHS, RHS>;

template <typename Op, typename T>
constexpr bool is_valid_unary_op = cuda::std::is_invocable<Op, T>::value;
constexpr bool is_valid_unary_op = cuda::std::is_invocable_v<Op, T>;

/**
* @brief Operator dispatcher
Expand Down Expand Up @@ -301,8 +301,8 @@ struct operator_functor<ast_operator::MOD, false> {

template <typename LHS,
typename RHS,
typename CommonType = std::common_type_t<LHS, RHS>,
std::enable_if_t<std::is_integral<CommonType>::value>* = nullptr>
typename CommonType = std::common_type_t<LHS, RHS>,
std::enable_if_t<std::is_integral_v<CommonType>>* = nullptr>
__device__ inline auto operator()(LHS lhs, RHS rhs)
-> decltype(static_cast<CommonType>(lhs) % static_cast<CommonType>(rhs))
{
Expand Down Expand Up @@ -336,8 +336,8 @@ struct operator_functor<ast_operator::PYMOD, false> {

template <typename LHS,
typename RHS,
typename CommonType = std::common_type_t<LHS, RHS>,
std::enable_if_t<std::is_integral<CommonType>::value>* = nullptr>
typename CommonType = std::common_type_t<LHS, RHS>,
std::enable_if_t<std::is_integral_v<CommonType>>* = nullptr>
__device__ inline auto operator()(LHS lhs, RHS rhs)
-> decltype(((static_cast<CommonType>(lhs) % static_cast<CommonType>(rhs)) +
static_cast<CommonType>(rhs)) %
Expand Down Expand Up @@ -542,7 +542,7 @@ template <>
struct operator_functor<ast_operator::SIN, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::sin(input))
{
return std::sin(input);
Expand All @@ -553,7 +553,7 @@ template <>
struct operator_functor<ast_operator::COS, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::cos(input))
{
return std::cos(input);
Expand All @@ -564,7 +564,7 @@ template <>
struct operator_functor<ast_operator::TAN, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::tan(input))
{
return std::tan(input);
Expand All @@ -575,7 +575,7 @@ template <>
struct operator_functor<ast_operator::ARCSIN, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::asin(input))
{
return std::asin(input);
Expand All @@ -586,7 +586,7 @@ template <>
struct operator_functor<ast_operator::ARCCOS, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::acos(input))
{
return std::acos(input);
Expand All @@ -597,7 +597,7 @@ template <>
struct operator_functor<ast_operator::ARCTAN, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::atan(input))
{
return std::atan(input);
Expand All @@ -608,7 +608,7 @@ template <>
struct operator_functor<ast_operator::SINH, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::sinh(input))
{
return std::sinh(input);
Expand All @@ -619,7 +619,7 @@ template <>
struct operator_functor<ast_operator::COSH, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::cosh(input))
{
return std::cosh(input);
Expand All @@ -630,7 +630,7 @@ template <>
struct operator_functor<ast_operator::TANH, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::tanh(input))
{
return std::tanh(input);
Expand All @@ -641,7 +641,7 @@ template <>
struct operator_functor<ast_operator::ARCSINH, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::asinh(input))
{
return std::asinh(input);
Expand All @@ -652,7 +652,7 @@ template <>
struct operator_functor<ast_operator::ARCCOSH, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::acosh(input))
{
return std::acosh(input);
Expand All @@ -663,7 +663,7 @@ template <>
struct operator_functor<ast_operator::ARCTANH, false> {
static constexpr auto arity{1};

template <typename InputT, std::enable_if_t<std::is_floating_point<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_floating_point_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::atanh(input))
{
return std::atanh(input);
Expand Down Expand Up @@ -741,13 +741,13 @@ struct operator_functor<ast_operator::ABS, false> {
static constexpr auto arity{1};

// Only accept signed or unsigned types (both require is_arithmetic<T> to be true)
template <typename InputT, std::enable_if_t<std::is_signed<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_signed_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(std::abs(input))
{
return std::abs(input);
}

template <typename InputT, std::enable_if_t<std::is_unsigned<InputT>::value>* = nullptr>
template <typename InputT, std::enable_if_t<std::is_unsigned_v<InputT>>* = nullptr>
__device__ inline auto operator()(InputT input) -> decltype(input)
{
return input;
Expand Down
7 changes: 3 additions & 4 deletions cpp/include/cudf/column/column_device_view.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -380,16 +380,15 @@ class alignas(16) column_device_view : public detail::column_device_view_base {
*/
struct index_element_fn {
template <typename IndexType,
CUDF_ENABLE_IF(is_index_type<IndexType>() and std::is_unsigned<IndexType>::value)>
CUDF_ENABLE_IF(is_index_type<IndexType>() and std::is_unsigned_v<IndexType>)>
__device__ size_type operator()(column_device_view const& indices, size_type index)
{
return static_cast<size_type>(indices.element<IndexType>(index));
}

template <typename IndexType,
typename... Args,
CUDF_ENABLE_IF(not(is_index_type<IndexType>() and
std::is_unsigned<IndexType>::value))>
CUDF_ENABLE_IF(not(is_index_type<IndexType>() and std::is_unsigned_v<IndexType>))>
__device__ size_type operator()(Args&&... args)
{
cudf_assert(false and "dictionary indices must be an unsigned integral type");
Expand Down
9 changes: 4 additions & 5 deletions cpp/include/cudf/detail/aggregation/aggregation.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -108,7 +108,7 @@ using corresponding_operator_t = typename corresponding_operator<k>::type;
template <aggregation::Kind k>
constexpr bool has_corresponding_operator()
{
return !std::is_same<typename corresponding_operator<k>::type, void>::value;
return !std::is_same_v<typename corresponding_operator<k>::type, void>;
}

template <typename Source,
Expand Down Expand Up @@ -602,16 +602,15 @@ struct identity_initializer {
}

template <typename T, aggregation::Kind k>
std::enable_if_t<not std::is_same<corresponding_operator_t<k>, void>::value, T>
std::enable_if_t<not std::is_same_v<corresponding_operator_t<k>, void>, T>
identity_from_operator()
{
using DeviceType = device_storage_type_t<T>;
return corresponding_operator_t<k>::template identity<DeviceType>();
}

template <typename T, aggregation::Kind k>
std::enable_if_t<std::is_same<corresponding_operator_t<k>, void>::value, T>
identity_from_operator()
std::enable_if_t<std::is_same_v<corresponding_operator_t<k>, void>, T> identity_from_operator()
{
CUDF_FAIL("Unable to get identity/sentinel from device operator");
}
Expand Down
11 changes: 5 additions & 6 deletions cpp/include/cudf/detail/aggregation/aggregation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,10 +1158,9 @@ constexpr bool is_sum_product_agg(aggregation::Kind k)

// Summing/Multiplying integers of any type, always use int64_t accumulator
template <typename Source, aggregation::Kind k>
struct target_type_impl<
Source,
k,
std::enable_if_t<std::is_integral<Source>::value && is_sum_product_agg(k)>> {
struct target_type_impl<Source,
k,
std::enable_if_t<std::is_integral_v<Source> && is_sum_product_agg(k)>> {
using type = int64_t;
};

Expand All @@ -1179,7 +1178,7 @@ template <typename Source, aggregation::Kind k>
struct target_type_impl<
Source,
k,
std::enable_if_t<std::is_floating_point<Source>::value && is_sum_product_agg(k)>> {
std::enable_if_t<std::is_floating_point_v<Source> && is_sum_product_agg(k)>> {
using type = Source;
};

Expand Down Expand Up @@ -1539,7 +1538,7 @@ data_type target_type(data_type source_type, aggregation::Kind k);
template <typename Source, aggregation::Kind k>
constexpr inline bool is_valid_aggregation()
{
return (not std::is_void<target_type_t<Source, k>>::value);
return (not std::is_void_v<target_type_t<Source, k>>);
}

/**
Expand Down
Loading

0 comments on commit c163886

Please sign in to comment.