rocPRIM
match_result_type.hpp
1 // Copyright (c) 2018-2021 Advanced Micro Devices, Inc. All rights reserved.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef ROCPRIM_DETAIL_MATCH_RESULT_TYPE_HPP_
22 #define ROCPRIM_DETAIL_MATCH_RESULT_TYPE_HPP_
23 
24 #include <type_traits>
25 
26 #include "../config.hpp"
27 
28 BEGIN_ROCPRIM_NAMESPACE
29 namespace detail
30 {
31 
32 // invoke_result is based on std::invoke_result.
33 // The main difference is using ROCPRIM_HOST_DEVICE, this allows to
34 // use invoke_result with device-only lambdas/functors in host-only functions
35 // on HIP-clang.
36 
37 template <class T>
38 struct is_reference_wrapper : std::false_type {};
39 template <class U>
40 struct is_reference_wrapper<std::reference_wrapper<U>> : std::true_type {};
41 
42 template<class T>
43 struct invoke_impl {
44  template<class F, class... Args>
45  ROCPRIM_HOST_DEVICE
46  static auto call(F&& f, Args&&... args)
47  -> decltype(std::forward<F>(f)(std::forward<Args>(args)...));
48 };
49 
50 template<class B, class MT>
51 struct invoke_impl<MT B::*>
52 {
53  template<class T, class Td = typename std::decay<T>::type,
54  class = typename std::enable_if<std::is_base_of<B, Td>::value>::type
55  >
56  ROCPRIM_HOST_DEVICE
57  static auto get(T&& t) -> T&&;
58 
59  template<class T, class Td = typename std::decay<T>::type,
60  class = typename std::enable_if<is_reference_wrapper<Td>::value>::type
61  >
62  ROCPRIM_HOST_DEVICE
63  static auto get(T&& t) -> decltype(t.get());
64 
65  template<class T, class Td = typename std::decay<T>::type,
66  class = typename std::enable_if<!std::is_base_of<B, Td>::value>::type,
67  class = typename std::enable_if<!is_reference_wrapper<Td>::value>::type
68  >
69  ROCPRIM_HOST_DEVICE
70  static auto get(T&& t) -> decltype(*std::forward<T>(t));
71 
72  template<class T, class... Args, class MT1,
73  class = typename std::enable_if<std::is_function<MT1>::value>::type
74  >
75  ROCPRIM_HOST_DEVICE
76  static auto call(MT1 B::*pmf, T&& t, Args&&... args)
77  -> decltype((invoke_impl::get(std::forward<T>(t)).*pmf)(std::forward<Args>(args)...));
78 
79  template<class T>
80  ROCPRIM_HOST_DEVICE
81  static auto call(MT B::*pmd, T&& t)
82  -> decltype(invoke_impl::get(std::forward<T>(t)).*pmd);
83 };
84 
85 template<class F, class... Args, class Fd = typename std::decay<F>::type>
86 ROCPRIM_HOST_DEVICE
87 auto INVOKE(F&& f, Args&&... args)
88  -> decltype(invoke_impl<Fd>::call(std::forward<F>(f), std::forward<Args>(args)...));
89 
90 // Conforming C++14 implementation (is also a valid C++11 implementation):
91 template <typename AlwaysVoid, typename, typename...>
92 struct invoke_result_impl { };
93 template <typename F, typename...Args>
94 struct invoke_result_impl<decltype(void(INVOKE(std::declval<F>(), std::declval<Args>()...))), F, Args...>
95 {
96  using type = decltype(INVOKE(std::declval<F>(), std::declval<Args>()...));
97 };
98 
99 template <class F, class... ArgTypes>
100 struct invoke_result : invoke_result_impl<void, F, ArgTypes...> {};
101 
102 template<class InputType, class BinaryFunction>
104 {
106 };
107 
108 } // end namespace detail
109 END_ROCPRIM_NAMESPACE
110 
111 #endif // ROCPRIM_DETAIL_MATCH_RESULT_TYPE_HPP_
Definition: match_result_type.hpp:38
Deprecated: Configuration of device-level scan primitives.
Definition: block_histogram.hpp:62
Definition: match_result_type.hpp:100
Definition: match_result_type.hpp:92
Definition: match_result_type.hpp:43
Definition: match_result_type.hpp:103