Skip to content

Commit

Permalink
C++17 cleanup: traits replace std::enable_if<>::type with std::enable…
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikeyann authored Feb 26, 2022
1 parent 3e33453 commit 4c9ef51
Show file tree
Hide file tree
Showing 51 changed files with 437 additions and 488 deletions.
12 changes: 5 additions & 7 deletions cpp/benchmarks/common/generate_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct random_value_fn;
* @brief Creates an random timestamp/duration value
*/
template <typename T>
struct random_value_fn<T, typename std::enable_if_t<cudf::is_chrono<T>()>> {
struct random_value_fn<T, std::enable_if_t<cudf::is_chrono<T>()>> {
std::function<int64_t(std::mt19937&)> seconds_gen;
std::function<int64_t(std::mt19937&)> nanoseconds_gen;

Expand Down Expand Up @@ -164,7 +164,7 @@ struct random_value_fn<T, typename std::enable_if_t<cudf::is_chrono<T>()>> {
* @brief Creates an random fixed_point value. Not implemented yet.
*/
template <typename T>
struct random_value_fn<T, typename std::enable_if_t<cudf::is_fixed_point<T>()>> {
struct random_value_fn<T, std::enable_if_t<cudf::is_fixed_point<T>()>> {
using rep = typename T::rep;
rep const lower_bound;
rep const upper_bound;
Expand Down Expand Up @@ -194,9 +194,7 @@ struct random_value_fn<T, typename std::enable_if_t<cudf::is_fixed_point<T>()>>
* @brief Creates an random numeric value with the given distribution.
*/
template <typename T>
struct random_value_fn<
T,
typename std::enable_if_t<!std::is_same_v<T, bool> && cudf::is_numeric<T>()>> {
struct random_value_fn<T, std::enable_if_t<!std::is_same_v<T, bool> && cudf::is_numeric<T>()>> {
T const lower_bound;
T const upper_bound;
distribution_fn<T> dist;
Expand All @@ -219,7 +217,7 @@ struct random_value_fn<
* @brief Creates an boolean value with given probability of returning `true`.
*/
template <typename T>
struct random_value_fn<T, typename std::enable_if_t<std::is_same_v<T, bool>>> {
struct random_value_fn<T, std::enable_if_t<std::is_same_v<T, bool>>> {
std::bernoulli_distribution b_dist;

random_value_fn(distribution_params<bool> const& desc) : b_dist{desc.probability_true} {}
Expand Down Expand Up @@ -260,7 +258,7 @@ struct stored_as {

// Use `int8_t` for bools because that's how they're stored in columns
template <typename T>
struct stored_as<T, typename std::enable_if_t<std::is_same_v<T, bool>>> {
struct stored_as<T, std::enable_if_t<std::is_same_v<T, bool>>> {
using type = int8_t;
};

Expand Down
27 changes: 12 additions & 15 deletions cpp/benchmarks/common/generate_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ struct distribution_params;
* @brief Numeric values are parameterized with a distribution type and bounds of the same type.
*/
template <typename T>
struct distribution_params<
T,
typename std::enable_if_t<!std::is_same_v<T, bool> && cudf::is_numeric<T>()>> {
struct distribution_params<T, std::enable_if_t<!std::is_same_v<T, bool> && cudf::is_numeric<T>()>> {
distribution_id id;
T lower_bound;
T upper_bound;
Expand All @@ -140,15 +138,15 @@ struct distribution_params<
* @brief Booleans are parameterized with the probability of getting `true` value.
*/
template <typename T>
struct distribution_params<T, typename std::enable_if_t<std::is_same_v<T, bool>>> {
struct distribution_params<T, std::enable_if_t<std::is_same_v<T, bool>>> {
double probability_true;
};

/**
* @brief Timestamps and durations are parameterized with a distribution type and int64_t bounds.
*/
template <typename T>
struct distribution_params<T, typename std::enable_if_t<cudf::is_chrono<T>()>> {
struct distribution_params<T, std::enable_if_t<cudf::is_chrono<T>()>> {
distribution_id id;
int64_t lower_bound;
int64_t upper_bound;
Expand All @@ -158,7 +156,7 @@ struct distribution_params<T, typename std::enable_if_t<cudf::is_chrono<T>()>> {
* @brief Strings are parameterized by the distribution of their length, as an integral value.
*/
template <typename T>
struct distribution_params<T, typename std::enable_if_t<std::is_same_v<T, cudf::string_view>>> {
struct distribution_params<T, std::enable_if_t<std::is_same_v<T, cudf::string_view>>> {
distribution_params<uint32_t> length_params;
};

Expand All @@ -167,15 +165,15 @@ struct distribution_params<T, typename std::enable_if_t<std::is_same_v<T, cudf::
* the element type.
*/
template <typename T>
struct distribution_params<T, typename std::enable_if_t<std::is_same_v<T, cudf::list_view>>> {
struct distribution_params<T, std::enable_if_t<std::is_same_v<T, cudf::list_view>>> {
cudf::type_id element_type;
distribution_params<uint32_t> length_params;
cudf::size_type max_depth;
};

// Present for compilation only. To be implemented once reader/writers support the fixed width type.
template <typename T>
struct distribution_params<T, typename std::enable_if_t<cudf::is_fixed_point<T>()>> {
struct distribution_params<T, std::enable_if_t<cudf::is_fixed_point<T>()>> {
};

/**
Expand Down Expand Up @@ -225,8 +223,7 @@ class data_profile {

public:
template <typename T,
typename std::enable_if_t<!std::is_same_v<T, bool> && cuda::std::is_integral_v<T>, T>* =
nullptr>
std::enable_if_t<!std::is_same_v<T, bool> && cuda::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 +236,7 @@ class data_profile {
}
}

template <typename T, typename std::enable_if_t<std::is_floating_point_v<T>, T>* = nullptr>
template <typename T, 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 All @@ -258,7 +255,7 @@ class data_profile {
return distribution_params<T>{bool_probability};
}

template <typename T, typename std::enable_if_t<cudf::is_chrono<T>()>* = nullptr>
template <typename T, std::enable_if_t<cudf::is_chrono<T>()>* = nullptr>
distribution_params<T> get_distribution_params() const
{
auto it = int_params.find(cudf::type_to_id<T>());
Expand All @@ -284,7 +281,7 @@ class data_profile {
return list_dist_desc;
}

template <typename T, typename std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
template <typename T, std::enable_if_t<cudf::is_fixed_point<T>()>* = nullptr>
distribution_params<typename T::rep> get_distribution_params() const
{
using rep = typename T::rep;
Expand All @@ -307,7 +304,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<cuda::std::is_integral_v<T>, T>* = nullptr>
std::enable_if_t<cuda::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 +328,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_v<T>, T>* = nullptr>
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
8 changes: 4 additions & 4 deletions cpp/benchmarks/common/random_distribution_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* @brief Generates a normal(binomial) distribution between zero and upper_bound.
*/
template <typename T, typename std::enable_if_t<cuda::std::is_integral_v<T>, T>* = nullptr>
template <typename T, std::enable_if_t<cuda::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<cuda::std::is_integral_v<T>, T>* = nullptr>
template <typename T, std::enable_if_t<cuda::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<cuda::std::is_integral_v<T>, T>* = nullptr>
template <typename T, std::enable_if_t<cuda::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<cuda::std::is_integral_v<T>, T>* = nullptr>
template <typename T, std::enable_if_t<cuda::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
1 change: 0 additions & 1 deletion cpp/benchmarks/string/json.cu
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ auto build_json_string_column(int desired_bytes, int num_rows)
cudf::type_id::FLOAT32, distribution_id::UNIFORM, 0.0, 1.0);
auto float_2bool_columns =
create_random_table({cudf::type_id::FLOAT32, cudf::type_id::BOOL8, cudf::type_id::BOOL8},
3,
row_count{num_rows},
profile);

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_v<Float>>> {
struct Functor<Float, ft, std::enable_if_t<std::is_floating_point_v<Float>>> {
static __device__ Float f(Float x)
{
if (ft == BANDWIDTH_BOUND) {
Expand Down
18 changes: 9 additions & 9 deletions cpp/include/cudf/detail/calendrical_month_sequence.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, NVIDIA CORPORATION.
* Copyright (c) 2021-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 @@ -30,12 +30,12 @@ namespace cudf {
namespace detail {
struct calendrical_month_sequence_functor {
template <typename T>
typename std::enable_if_t<cudf::is_timestamp_t<T>::value, std::unique_ptr<cudf::column>>
operator()(size_type n,
scalar const& input,
size_type months,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource())
std::enable_if_t<cudf::is_timestamp_t<T>::value, std::unique_ptr<cudf::column>> operator()(
size_type n,
scalar const& input,
size_type months,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource())
{
// Return empty column if n = 0
if (n == 0) return cudf::make_empty_column(input.type());
Expand All @@ -59,8 +59,8 @@ struct calendrical_month_sequence_functor {
}

template <typename T, typename... Args>
typename std::enable_if_t<!cudf::is_timestamp_t<T>::value, std::unique_ptr<cudf::column>>
operator()(Args&&...)
std::enable_if_t<!cudf::is_timestamp_t<T>::value, std::unique_ptr<cudf::column>> operator()(
Args&&...)
{
CUDF_FAIL("Cannot make a date_range of a non-datetime type");
}
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/cudf/detail/reduction.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2020, 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 @@ -49,8 +49,8 @@ namespace detail {
template <typename Op,
typename InputIterator,
typename OutputType = typename thrust::iterator_value<InputIterator>::type,
typename std::enable_if_t<is_fixed_width<OutputType>() &&
not cudf::is_fixed_point<OutputType>()>* = nullptr>
std::enable_if_t<is_fixed_width<OutputType>() &&
not cudf::is_fixed_point<OutputType>()>* = nullptr>
std::unique_ptr<scalar> reduce(InputIterator d_in,
cudf::size_type num_items,
op::simple_op<Op> sop,
Expand Down Expand Up @@ -92,7 +92,7 @@ std::unique_ptr<scalar> reduce(InputIterator d_in,
template <typename Op,
typename InputIterator,
typename OutputType = typename thrust::iterator_value<InputIterator>::type,
typename std::enable_if_t<is_fixed_point<OutputType>()>* = nullptr>
std::enable_if_t<is_fixed_point<OutputType>()>* = nullptr>
std::unique_ptr<scalar> reduce(InputIterator d_in,
cudf::size_type num_items,
op::simple_op<Op> sop,
Expand All @@ -109,7 +109,7 @@ std::unique_ptr<scalar> reduce(InputIterator d_in,
template <typename Op,
typename InputIterator,
typename OutputType = typename thrust::iterator_value<InputIterator>::type,
typename std::enable_if_t<std::is_same_v<OutputType, string_view>>* = nullptr>
std::enable_if_t<std::is_same_v<OutputType, string_view>>* = nullptr>
std::unique_ptr<scalar> reduce(InputIterator d_in,
cudf::size_type num_items,
op::simple_op<Op> sop,
Expand Down
12 changes: 6 additions & 6 deletions cpp/include/cudf/detail/utilities/device_atomics.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ struct typesAtomicCASImpl<T, 8> {
* @returns The old value at `address`
*/
template <typename T, typename BinaryOp>
typename std::enable_if_t<cudf::is_numeric<T>(), T> __forceinline__ __device__
std::enable_if_t<cudf::is_numeric<T>(), T> __forceinline__ __device__
genericAtomicOperation(T* address, T const& update_value, BinaryOp op)
{
auto fun = cudf::detail::genericAtomicOperationImpl<T, BinaryOp>{};
Expand All @@ -435,7 +435,7 @@ genericAtomicOperation(T* address, T const& update_value, BinaryOp op)

// specialization for cudf::detail::timestamp types
template <typename T, typename BinaryOp>
typename std::enable_if_t<cudf::is_timestamp<T>(), T> __forceinline__ __device__
std::enable_if_t<cudf::is_timestamp<T>(), T> __forceinline__ __device__
genericAtomicOperation(T* address, T const& update_value, BinaryOp op)
{
using R = typename T::rep;
Expand All @@ -448,7 +448,7 @@ genericAtomicOperation(T* address, T const& update_value, BinaryOp op)

// specialization for cudf::detail::duration types
template <typename T, typename BinaryOp>
typename std::enable_if_t<cudf::is_duration<T>(), T> __forceinline__ __device__
std::enable_if_t<cudf::is_duration<T>(), T> __forceinline__ __device__
genericAtomicOperation(T* address, T const& update_value, BinaryOp op)
{
using R = typename T::rep;
Expand Down Expand Up @@ -616,7 +616,7 @@ __forceinline__ __device__ T atomicCAS(T* address, T compare, T val)
*
* @returns The old value at `address`
*/
template <typename T, typename std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
template <typename T, std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
__forceinline__ __device__ T atomicAnd(T* address, T val)
{
return cudf::genericAtomicOperation(address, val, cudf::DeviceAnd{});
Expand All @@ -637,7 +637,7 @@ __forceinline__ __device__ T atomicAnd(T* address, T val)
*
* @returns The old value at `address`
*/
template <typename T, typename std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
template <typename T, std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
__forceinline__ __device__ T atomicOr(T* address, T val)
{
return cudf::genericAtomicOperation(address, val, cudf::DeviceOr{});
Expand All @@ -658,7 +658,7 @@ __forceinline__ __device__ T atomicOr(T* address, T val)
*
* @returns The old value at `address`
*/
template <typename T, typename std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
template <typename T, std::enable_if_t<std::is_integral_v<T>, T>* = nullptr>
__forceinline__ __device__ T atomicXor(T* address, T val)
{
return cudf::genericAtomicOperation(address, val, cudf::DeviceXor{});
Expand Down
Loading

0 comments on commit 4c9ef51

Please sign in to comment.