21 #ifndef ROCPRIM_TYPES_TUPLE_HPP_ 22 #define ROCPRIM_TYPES_TUPLE_HPP_ 25 #include <type_traits> 27 #include "../config.hpp" 28 #include "../detail/all_true.hpp" 30 #include "integer_sequence.hpp" 35 BEGIN_ROCPRIM_NAMESPACE
40 template<
class... Types>
57 template<
class... Types>
58 class tuple_size<::rocprim::tuple<Types...>> :
public std::integral_constant<size_t, sizeof...(Types)>
66 :
public std::integral_constant<size_t, tuple_size<T>::value>
73 :
public std::integral_constant<size_t, tuple_size<T>::value>
80 :
public std::integral_constant<size_t, tuple_size<T>::value>
92 template<
size_t I,
class T>
98 template<
size_t I,
class T>
101 template<
size_t I,
class T,
class... Types>
108 template<
class T,
class... Types>
117 static_assert(I != I,
"tuple_element index out of range");
124 template<
size_t I,
class... Types>
128 #ifndef DOXYGEN_SHOULD_SKIP_THIS 135 template<
size_t I,
class T>
139 using type =
typename std::add_const<typename tuple_element<I, T>::type>
::type;
142 template<
size_t I,
class T>
146 using type =
typename std::add_volatile<typename tuple_element<I, T>::type>
::type;
149 template<
size_t I,
class T>
153 using type =
typename std::add_cv<typename tuple_element<I, T>::type>
::type;
159 template <
size_t I,
class T>
163 #ifndef DOXYGEN_SHOULD_SKIP_THIS 164 template<
size_t I,
class... UTypes>
168 template<
size_t I,
class... UTypes>
172 template<
size_t I,
class... UTypes>
186 inline T&& custom_forward(
typename std::remove_reference<T>::type& t) noexcept
188 return static_cast<T&&
>(t);
193 inline T&& custom_forward(
typename std::remove_reference<T>::type&& t) noexcept
195 static_assert(!std::is_lvalue_reference<T>::value,
196 "Can not forward an rvalue as an lvalue.");
197 return static_cast<T&&
>(t);
201 #ifdef __cpp_lib_is_final 203 using is_final = std::is_final<T>;
204 #elif defined(__clang__) // use clang extention 206 using is_final = std::integral_constant<bool, __is_final(T)>;
224 ROCPRIM_HOST_DEVICE
inline 227 static_assert(!std::is_reference<T>::value,
"can't default construct a reference element in a tuple" );
230 ROCPRIM_HOST_DEVICE
inline 233 ROCPRIM_HOST_DEVICE
inline 238 typename =
typename std::enable_if<
239 !std::is_same<typename std::decay<U>::type,
tuple_value>::value
241 typename =
typename std::enable_if<
242 std::is_constructible<T, const U&>::value
245 ROCPRIM_HOST_DEVICE
inline 246 explicit tuple_value(
const U& v) noexcept : value(v)
252 typename =
typename std::enable_if<
254 !std::is_same<typename std::decay<U>::type,
tuple_value>::value
256 typename =
typename std::enable_if<
257 std::is_constructible<T, U&&>::value
260 ROCPRIM_HOST_DEVICE
inline 261 explicit tuple_value(U&& v) noexcept : value(::rocprim::detail::custom_forward<U>(v))
265 ROCPRIM_HOST_DEVICE
inline 269 ROCPRIM_HOST_DEVICE
inline 272 value = ::rocprim::detail::custom_forward<U>(v);
276 ROCPRIM_HOST_DEVICE
inline 279 auto tmp = std::move(v.value);
280 v.value = std::move(this->value);
281 this->value = std::move(tmp);
284 ROCPRIM_HOST_DEVICE
inline 290 ROCPRIM_HOST_DEVICE
inline 291 const T&
get()
const noexcept
298 template<
size_t I,
class T>
301 ROCPRIM_HOST_DEVICE
inline 304 static_assert(!std::is_reference<T>::value,
"can't default construct a reference element in a tuple" );
307 ROCPRIM_HOST_DEVICE
inline 310 ROCPRIM_HOST_DEVICE
inline 315 typename =
typename std::enable_if<
316 !std::is_same<typename std::decay<U>::type,
tuple_value>::value
318 typename =
typename std::enable_if<
319 std::is_constructible<T, const U&>::value
322 ROCPRIM_HOST_DEVICE
inline 329 typename =
typename std::enable_if<
331 !std::is_same<typename std::decay<U>::type,
tuple_value>::value
333 typename =
typename std::enable_if<
334 std::is_constructible<T, U&&>::value
337 ROCPRIM_HOST_DEVICE
inline 338 explicit tuple_value(U&& v) noexcept : T(::rocprim::detail::custom_forward<U>(v))
342 ROCPRIM_HOST_DEVICE
inline 346 ROCPRIM_HOST_DEVICE
inline 349 T::operator=(::rocprim::detail::custom_forward<U>(v));
353 ROCPRIM_HOST_DEVICE
inline 356 auto tmp = std::move(v);
357 v = std::move(*
this);
358 *
this = std::move(tmp);
361 ROCPRIM_HOST_DEVICE
inline 364 return static_cast<T&
>(*this);
367 ROCPRIM_HOST_DEVICE
inline 368 const T&
get()
const noexcept
370 return static_cast<const T&
>(*this);
374 template <
class... Types>
375 ROCPRIM_HOST_DEVICE
inline 376 void swallow(Types&&...) noexcept {}
378 template<
class Sequences,
class... Types>
381 template<
size_t... Indices,
class... Types>
382 struct tuple_impl<::rocprim::index_sequence<Indices...>, Types...>
385 ROCPRIM_HOST_DEVICE
inline 388 ROCPRIM_HOST_DEVICE
inline 391 ROCPRIM_HOST_DEVICE
inline 396 typename =
typename std::enable_if<
397 sizeof...(UTypes) ==
sizeof...(Types)
399 typename =
typename std::enable_if<
400 sizeof...(Types) >= 1
403 ROCPRIM_HOST_DEVICE
inline 411 typename =
typename std::enable_if<
412 sizeof...(UTypes) ==
sizeof...(Types)
414 typename =
typename std::enable_if<
415 sizeof...(Types) >= 1
418 ROCPRIM_HOST_DEVICE
inline 419 tuple_impl(::rocprim::tuple<UTypes...>&& other)
426 typename =
typename std::enable_if<
427 sizeof...(UTypes) ==
sizeof...(Types)
429 typename =
typename std::enable_if<
430 sizeof...(Types) >= 1
433 ROCPRIM_HOST_DEVICE
inline 434 tuple_impl(const ::rocprim::tuple<UTypes...>& other)
439 ROCPRIM_HOST_DEVICE
inline 442 ROCPRIM_HOST_DEVICE
inline 453 ROCPRIM_HOST_DEVICE
inline 464 template<
class... UTypes>
465 ROCPRIM_HOST_DEVICE
inline 466 tuple_impl& operator=(const ::rocprim::tuple<UTypes...>& other) noexcept
472 template<
class... UTypes>
473 ROCPRIM_HOST_DEVICE
inline 474 tuple_impl& operator=(::rocprim::tuple<UTypes...>&& other) noexcept
478 ::rocprim::get<Indices>(std::move(other))
484 ROCPRIM_HOST_DEVICE
inline 496 template<
class... Types>
499 typename ::rocprim::index_sequence_for<Types...>,
514 template<
class... Types>
521 template<
class Dummy>
522 struct check_constructor
524 template<
class... Args>
525 static constexpr
bool enable_default()
530 template<
class... Args>
531 static constexpr
bool enable_copy()
537 #ifndef DOXYGEN_SHOULD_SKIP_THIS 538 template<
size_t I,
class... UTypes>
542 template<
size_t I,
class... UTypes>
546 template<
size_t I,
class... UTypes>
556 #ifndef DOXYGEN_SHOULD_SKIP_THIS 559 typename =
typename std::enable_if<
560 check_constructor<Dummy>::template enable_default<Types...>()
564 ROCPRIM_HOST_DEVICE
inline 565 constexpr
tuple() noexcept : base() {};
568 ROCPRIM_HOST_DEVICE
inline 572 ROCPRIM_HOST_DEVICE
inline 580 #ifndef DOXYGEN_SHOULD_SKIP_THIS 583 typename =
typename std::enable_if<
584 check_constructor<Dummy>::template enable_copy<Types...>()
588 ROCPRIM_HOST_DEVICE
inline 589 explicit tuple(
const Types&... values)
603 #ifndef DOXYGEN_SHOULD_SKIP_THIS 604 ,
typename =
typename std::enable_if<
605 sizeof...(UTypes) ==
sizeof...(Types)
607 typename =
typename std::enable_if<
608 sizeof...(Types) >= 1
610 typename =
typename std::enable_if<
615 ROCPRIM_HOST_DEVICE
inline 616 explicit tuple(UTypes&&... values) noexcept
617 : base(::rocprim::detail::custom_forward<UTypes>(values)...)
630 #ifndef DOXYGEN_SHOULD_SKIP_THIS 631 typename =
typename std::enable_if<
632 sizeof...(UTypes) ==
sizeof...(Types)
634 typename =
typename std::enable_if<
635 sizeof...(Types) >= 1
637 typename =
typename std::enable_if<
638 detail::all_true<std::is_constructible<Types, const UTypes&>::value...>::value
642 ROCPRIM_HOST_DEVICE
inline 657 #ifndef DOXYGEN_SHOULD_SKIP_THIS 658 typename =
typename std::enable_if<
659 sizeof...(UTypes) ==
sizeof...(Types)
661 typename =
typename std::enable_if<
662 sizeof...(Types) >= 1
664 typename =
typename std::enable_if<
669 ROCPRIM_HOST_DEVICE
inline 676 ROCPRIM_HOST_DEVICE
inline 677 ~
tuple() noexcept =
default;
679 #ifndef DOXYGEN_SHOULD_SKIP_THIS 682 typename =
typename std::enable_if<
683 std::is_assignable<base_type&, T>::value
686 ROCPRIM_HOST_DEVICE
inline 687 tuple& operator=(T&& v) noexcept
689 base = ::rocprim::detail::custom_forward<T>(v);
693 ROCPRIM_HOST_DEVICE
inline 699 #else // For documentation 700 tuple& operator=(
const tuple& other) noexcept;
708 template<
class... UTypes>
712 template<
class... UTypes>
720 base.swap(other.base);
724 #ifndef DOXYGEN_SHOULD_SKIP_THIS 729 ROCPRIM_HOST_DEVICE
inline 730 constexpr
tuple() noexcept
734 ROCPRIM_HOST_DEVICE
inline 737 ROCPRIM_HOST_DEVICE
inline 750 template<
class T,
class U>
751 ROCPRIM_HOST_DEVICE
inline 752 bool operator()(
const T& lhs,
const U& rhs)
const 754 return tuple_equal_to<I-1>()(lhs, rhs) &&
get<I-1>(lhs) == get<I-1>(rhs);
761 template<
class T,
class U>
762 ROCPRIM_HOST_DEVICE
inline 763 bool operator()(
const T&,
const U&)
const 772 template<
class T,
class U>
773 ROCPRIM_HOST_DEVICE
inline 774 bool operator()(
const T& lhs,
const U& rhs)
const 777 if(get<idx>(lhs) < get<idx>(rhs))
779 if(get<idx>(rhs) < get<idx>(lhs))
788 template<
class T,
class U>
789 ROCPRIM_HOST_DEVICE
inline 790 bool operator()(
const T&,
const U&)
const 814 typename =
typename std::enable_if<
815 sizeof...(TTypes) ==
sizeof...(UTypes)
818 ROCPRIM_HOST_DEVICE
inline 836 template<
class... TTypes,
class... UTypes>
837 ROCPRIM_HOST_DEVICE
inline 840 return !(lhs == rhs);
859 typename =
typename std::enable_if<
860 sizeof...(TTypes) ==
sizeof...(UTypes)
863 ROCPRIM_HOST_DEVICE
inline 879 template<
class... TTypes,
class... UTypes>
880 ROCPRIM_HOST_DEVICE
inline 896 template<
class... TTypes,
class... UTypes>
897 ROCPRIM_HOST_DEVICE
inline 913 template<
class... TTypes,
class... UTypes>
914 ROCPRIM_HOST_DEVICE
inline 926 template<
class... Types>
927 ROCPRIM_HOST_DEVICE
inline 941 template<
size_t I,
class... Types>
942 ROCPRIM_HOST_DEVICE
inline 946 return static_cast<const type&
>(t.base).
get();
953 template<
size_t I,
class... Types>
954 ROCPRIM_HOST_DEVICE
inline 958 return static_cast<type&
>(t.base).
get();
965 template<
size_t I,
class... Types>
966 ROCPRIM_HOST_DEVICE
inline 971 return static_cast<value_type&&
>(
static_cast<type&
>(t.base).
get());
998 #ifndef DOXYGEN_SHOULD_SKIP_THIS 999 template<
class... Types>
1000 ROCPRIM_HOST_DEVICE
inline 1006 template<
class... Types>
1017 tuple<VTypes...> make_tuple(Types&&... args);
1029 ROCPRIM_HOST_DEVICE
inline 1032 ROCPRIM_HOST_DEVICE
inline 1036 ROCPRIM_HOST_DEVICE
inline 1037 const ignore_t& operator=(
const T&)
const 1044 #ifndef DOXYGEN_SHOULD_SKIP_THIS 1067 template<
class... Types>
1068 ROCPRIM_HOST_DEVICE
inline 1071 return ::rocprim::tuple<Types&...>(args...);
1074 END_ROCPRIM_NAMESPACE
1079 #endif // ROCPRIM_TYPES_TUPLE_HPP_ Definition: tuple.hpp:220
Definition: tuple.hpp:379
ROCPRIM_HOST_DEVICE tuple< Types &... > tie(Types &... args) noexcept
Creates a tuple of lvalue references to its arguments args or instances of rocprim::ignore.
Definition: tuple.hpp:1069
typename detail::tuple_element_impl< I, ::rocprim::tuple< Types... > >::type type
The type of Ith element of the tuple, where I is in [0, sizeof...(Types))
Definition: tuple.hpp:129
const ignore_type ignore
Assigning value to ignore object has no effect.
Definition: tuple.hpp:1055
ROCPRIM_HOST_DEVICE bool operator>=(const tuple< TTypes... > &lhs, const tuple< UTypes... > &rhs)
Greater than or equal to operator for tuples.
Definition: tuple.hpp:915
ROCPRIM_HOST_DEVICE void swap(tuple< Types... > &lhs, tuple< Types... > &rhs) noexcept
Swaps the content of lhs tuple with the content rhs.
Definition: tuple.hpp:928
ROCPRIM_HOST_DEVICE bool operator<(const tuple< TTypes... > &lhs, const tuple< UTypes... > &rhs)
Less than operator for tuples.
Definition: tuple.hpp:864
ROCPRIM_HOST_DEVICE constexpr tuple() noexcept
Default constructor.
Definition: tuple.hpp:565
typename std::add_volatile< typename tuple_element< I, T >::type >::type type
The type of Ith element of the tuple, where I is in [0, sizeof...(Types))
Definition: tuple.hpp:146
typename tuple_element< I, T >::type tuple_element_t
This is an alias used for convenience.
Definition: tuple.hpp:160
ROCPRIM_HOST_DEVICE bool operator!=(const tuple< TTypes... > &lhs, const tuple< UTypes... > &rhs)
Not equal to operator for tuples.
Definition: tuple.hpp:838
ROCPRIM_HOST_DEVICE void swap(tuple &other) noexcept
Swaps the content of the tuple (*this) with the content other.
Definition: tuple.hpp:718
Deprecated: Configuration of device-level scan primitives.
Definition: block_histogram.hpp:62
Definition: all_true.hpp:35
typename std::add_cv< typename tuple_element< I, T >::type >::type type
The type of Ith element of the tuple, where I is in [0, sizeof...(Types))
Definition: tuple.hpp:153
Provides compile-time indexed access to the types of the elements of the tuple.
Definition: tuple.hpp:93
ROCPRIM_HOST_DEVICE bool operator<=(const tuple< TTypes... > &lhs, const tuple< UTypes... > &rhs)
Less than or equal to operator for tuples.
Definition: tuple.hpp:898
Definition: tuple.hpp:982
Fixed-size collection of heterogeneous values.
Definition: tuple.hpp:41
ROCPRIM_HOST_DEVICE bool operator>(const tuple< TTypes... > &lhs, const tuple< UTypes... > &rhs)
Greater than operator for tuples.
Definition: tuple.hpp:881
ROCPRIM_HOST_DEVICE bool operator==(const tuple< TTypes... > &lhs, const tuple< UTypes... > &rhs)
Equal to operator for tuples.
Definition: tuple.hpp:819
Definition: tuple.hpp:748
Definition: tuple.hpp:1027
Definition: tuple.hpp:209
Provides access to the number of elements in a tuple as a compile-time constant expression.
Definition: tuple.hpp:51
ROCPRIM_HOST_DEVICE tuple(const Types &... values)
Direct constructor.
Definition: tuple.hpp:589
Definition: tuple.hpp:770
typename std::add_const< typename tuple_element< I, T >::type >::type type
The type of Ith element of the tuple, where I is in [0, sizeof...(Types))
Definition: tuple.hpp:139