diff --git a/thrust/detail/type_traits.h b/thrust/detail/type_traits.h index 5596f569e..c6387f9a2 100644 --- a/thrust/detail/type_traits.h +++ b/thrust/detail/type_traits.h @@ -1,5 +1,5 @@ /* - * Copyright 2008-2018 NVIDIA Corporation + * Copyright 2008-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. @@ -24,9 +24,9 @@ #include -#if THRUST_CPP_DIALECT >= 2011 -# include -#endif +#include + +#include THRUST_NAMESPACE_BEGIN @@ -47,7 +47,6 @@ namespace detail // We don't want to switch to std::integral_constant, because we want access // to the C++14 operator(), but we'd like standard traits to interoperate // with our version when tag dispatching. - #if THRUST_CPP_DIALECT >= 2011 integral_constant() = default; integral_constant(integral_constant const&) = default; @@ -56,7 +55,6 @@ namespace detail constexpr __host__ __device__ integral_constant(std::integral_constant) noexcept {} - #endif constexpr __host__ __device__ operator value_type() const noexcept { return value; } constexpr __host__ __device__ value_type operator()() const noexcept { return value; } @@ -715,6 +713,20 @@ template { }; +template +using invoke_result_t = +#if THRUST_CPP_DIALECT < 2017 + typename cuda::std::result_of::type; +#else // 2017+ + cuda::std::invoke_result_t; +#endif + +template +struct invoke_result +{ + using type = invoke_result_t; +}; + } // end detail using detail::integral_constant; diff --git a/thrust/detail/type_traits/result_of_adaptable_function.h b/thrust/detail/type_traits/result_of_adaptable_function.h index 908c8abea..3021538fb 100644 --- a/thrust/detail/type_traits/result_of_adaptable_function.h +++ b/thrust/detail/type_traits/result_of_adaptable_function.h @@ -29,7 +29,6 @@ namespace detail // Sets `type` to the result of the specified Signature invocation. If the // callable defines a `result_type` alias member, that type is used instead. // Use invoke_result / result_of when FuncType::result_type is not defined. -#if THRUST_CPP_DIALECT >= 2017 template struct result_of_adaptable_function { @@ -39,16 +38,12 @@ struct result_of_adaptable_function template struct impl { - using type = std::invoke_result_t; + using type = invoke_result_t; }; public: using type = typename impl::type; }; -#else // < C++17 -template -struct result_of_adaptable_function : std::result_of {}; -#endif // < C++17 // specialization for invocations which define result_type template diff --git a/thrust/iterator/detail/transform_input_output_iterator.inl b/thrust/iterator/detail/transform_input_output_iterator.inl index 7e7273ae6..b4792f724 100644 --- a/thrust/iterator/detail/transform_input_output_iterator.inl +++ b/thrust/iterator/detail/transform_input_output_iterator.inl @@ -17,8 +17,8 @@ #pragma once #include - #include +#include THRUST_NAMESPACE_BEGIN @@ -35,12 +35,7 @@ template { using iterator_value_type = typename thrust::iterator_value::type; - // std::result_of is deprecated in 2017, replace with std::invoke_result -#if THRUST_CPP_DIALECT < 2017 - using Value = typename std::result_of::type; -#else - using Value = std::invoke_result_t; -#endif + using Value = invoke_result_t; public: __host__ __device__ @@ -93,12 +88,7 @@ public: < transform_input_output_iterator , Iterator - // std::result_of is deprecated in 2017, replace with std::invoke_result -#if THRUST_CPP_DIALECT < 2017 - , typename std::result_of::type -#else - , std::invoke_result_t -#endif + , detail::invoke_result_t , thrust::use_default , thrust::use_default , transform_input_output_iterator_proxy diff --git a/thrust/optional.h b/thrust/optional.h index 8f881ee5b..52008e4f6 100644 --- a/thrust/optional.h +++ b/thrust/optional.h @@ -15,6 +15,7 @@ #include #include +#include #if THRUST_CPP_DIALECT >= 2011 @@ -255,22 +256,6 @@ constexpr auto invoke(Fn &&f, Args &&... args) { return std::forward(f)(std::forward(args)...); } - -// std::invoke_result from C++17 -template struct invoke_result_impl; - -template -struct invoke_result_impl< - F, decltype(detail::invoke(std::declval(), std::declval()...), void()), - Us...> { - using type = decltype(detail::invoke(std::declval(), std::declval()...)); -}; - -template -using invoke_result = invoke_result_impl; - -template -using invoke_result_t = typename invoke_result::type; #endif // std::void_t from C++17 diff --git a/thrust/system/cuda/detail/transform_scan.h b/thrust/system/cuda/detail/transform_scan.h index cb81a1ab0..1fc10fbde 100644 --- a/thrust/system/cuda/detail/transform_scan.h +++ b/thrust/system/cuda/detail/transform_scan.h @@ -30,8 +30,9 @@ #if THRUST_DEVICE_COMPILER == THRUST_DEVICE_COMPILER_NVCC #include -#include +#include #include +#include THRUST_NAMESPACE_BEGIN @@ -52,12 +53,7 @@ transform_inclusive_scan(execution_policy &policy, { // Use the transformed input iterator's value type per https://wg21.link/P0571 using input_type = typename thrust::iterator_value::type; -#if THRUST_CPP_DIALECT < 2017 - using result_type = typename std::result_of::type; -#else - using result_type = std::invoke_result_t; -#endif - + using result_type = thrust::detail::invoke_result_t; using value_type = typename std::remove_reference::type; typedef typename iterator_traits::difference_type size_type; diff --git a/thrust/system/detail/generic/transform_scan.inl b/thrust/system/detail/generic/transform_scan.inl index 68b9031c7..505bdbfab 100644 --- a/thrust/system/detail/generic/transform_scan.inl +++ b/thrust/system/detail/generic/transform_scan.inl @@ -49,11 +49,7 @@ __host__ __device__ { // Use the input iterator's value type per https://wg21.link/P0571 using InputType = typename thrust::iterator_value::type; -#if THRUST_CPP_DIALECT < 2017 - using ResultType = typename std::result_of::type; -#else - using ResultType = std::invoke_result_t; -#endif + using ResultType = thrust::detail::invoke_result_t; using ValueType = typename std::remove_reference::type; thrust::transform_iterator _first(first, unary_op);