Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
Kokkos_Pair.hpp
Go to the documentation of this file.
1//@HEADER
2// ************************************************************************
3//
4// Kokkos v. 4.0
5// Copyright (2022) National Technology & Engineering
6// Solutions of Sandia, LLC (NTESS).
7//
8// Under the terms of Contract DE-NA0003525 with NTESS,
9// the U.S. Government retains certain rights in this software.
10//
11// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12// See https://kokkos.org/LICENSE for license information.
13// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14//
15//@HEADER
16
22
23#ifndef KOKKOS_PAIR_HPP
24#define KOKKOS_PAIR_HPP
25#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
26#define KOKKOS_IMPL_PUBLIC_INCLUDE
27#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_PAIR
28#endif
29
30#include <Kokkos_Macros.hpp>
31#include <Kokkos_Swap.hpp>
32#include <utility>
33
34namespace Kokkos {
43template <class T1, class T2>
44struct pair {
46 using first_type = T1;
48 using second_type = T2;
49
54
60 KOKKOS_DEFAULTED_FUNCTION constexpr pair() = default;
61
66#if defined(KOKKOS_COMPILER_NVHPC) && KOKKOS_COMPILER_NVHPC < 230700
67 KOKKOS_FORCEINLINE_FUNCTION
68#else
69 KOKKOS_FORCEINLINE_FUNCTION constexpr
70#endif
71 pair(first_type const& f, second_type const& s) : first(f), second(s) {}
72
77 template <class U, class V>
78#if defined(KOKKOS_COMPILER_NVHPC) && KOKKOS_COMPILER_NVHPC < 230700
79 KOKKOS_FORCEINLINE_FUNCTION
80#else
81 KOKKOS_FORCEINLINE_FUNCTION constexpr
82#endif
84 : first(p.first), second(p.second) {
85 }
86
87#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
92 template <class U, class V>
93 KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION constexpr pair(
94 const volatile pair<U, V>& p)
95 : first(p.first), second(p.second) {}
96#endif
97
102 template <class U, class V>
103 KOKKOS_FORCEINLINE_FUNCTION pair<T1, T2>& operator=(const pair<U, V>& p) {
104 first = p.first;
105 second = p.second;
106 return *this;
107 }
108
109#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
121 template <class U, class V>
122 KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION void operator=(
123 const volatile pair<U, V>& p) volatile {
124 first = p.first;
125 second = p.second;
126 // We deliberately do not return anything here. See explanation
127 // in public documentation above.
128 }
129#endif
130
131 // from std::pair<U,V>
132 template <class U, class V>
133 pair(const std::pair<U, V>& p) : first(p.first), second(p.second) {}
134
144 std::pair<T1, T2> to_std_pair() const {
145 return std::make_pair(first, second);
146 }
147};
148
149template <class T1, class T2>
150struct pair<T1&, T2&> {
152 using first_type = T1&;
154 using second_type = T2&;
155
157 first_type first;
159 second_type second;
160
165 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(first_type f, second_type s)
166 : first(f), second(s) {}
167
172 template <class U, class V>
173 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(const pair<U, V>& p)
174 : first(p.first), second(p.second) {}
175
176 // from std::pair<U,V>
177 template <class U, class V>
178 pair(const std::pair<U, V>& p) : first(p.first), second(p.second) {}
179
184 template <class U, class V>
185 KOKKOS_FORCEINLINE_FUNCTION pair<first_type, second_type>& operator=(
186 const pair<U, V>& p) {
187 first = p.first;
188 second = p.second;
189 return *this;
190 }
191
201 std::pair<T1, T2> to_std_pair() const {
202 return std::make_pair(first, second);
203 }
204};
205
206template <class T1, class T2>
207struct pair<T1, T2&> {
209 using first_type = T1;
211 using second_type = T2&;
212
214 first_type first;
216 second_type second;
217
222 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(first_type const& f, second_type s)
223 : first(f), second(s) {}
224
229 template <class U, class V>
230 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(const pair<U, V>& p)
231 : first(p.first), second(p.second) {}
232
233 // from std::pair<U,V>
234 template <class U, class V>
235 pair(const std::pair<U, V>& p) : first(p.first), second(p.second) {}
236
241 template <class U, class V>
242 KOKKOS_FORCEINLINE_FUNCTION pair<first_type, second_type>& operator=(
243 const pair<U, V>& p) {
244 first = p.first;
245 second = p.second;
246 return *this;
247 }
248
258 std::pair<T1, T2> to_std_pair() const {
259 return std::make_pair(first, second);
260 }
261};
262
263template <class T1, class T2>
264struct pair<T1&, T2> {
266 using first_type = T1&;
268 using second_type = T2;
269
271 first_type first;
273 second_type second;
274
279 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(first_type f, second_type const& s)
280 : first(f), second(s) {}
281
286 template <class U, class V>
287 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(const pair<U, V>& p)
288 : first(p.first), second(p.second) {}
289
290 // from std::pair<U,V>
291 template <class U, class V>
292 pair(const std::pair<U, V>& p) : first(p.first), second(p.second) {}
293
298 template <class U, class V>
299 KOKKOS_FORCEINLINE_FUNCTION pair<first_type, second_type>& operator=(
300 const pair<U, V>& p) {
301 first = p.first;
302 second = p.second;
303 return *this;
304 }
305
315 std::pair<T1, T2> to_std_pair() const {
316 return std::make_pair(first, second);
317 }
318};
319
321template <class T1, class T2>
322KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator==(const pair<T1, T2>& lhs,
323 const pair<T1, T2>& rhs) {
324 return lhs.first == rhs.first && lhs.second == rhs.second;
325}
326
328template <class T1, class T2>
329KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator!=(const pair<T1, T2>& lhs,
330 const pair<T1, T2>& rhs) {
331 return !(lhs == rhs);
332}
333
335template <class T1, class T2>
336KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator<(const pair<T1, T2>& lhs,
337 const pair<T1, T2>& rhs) {
338 return lhs.first < rhs.first ||
339 (!(rhs.first < lhs.first) && lhs.second < rhs.second);
340}
341
343template <class T1, class T2>
344KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator<=(const pair<T1, T2>& lhs,
345 const pair<T1, T2>& rhs) {
346 return !(rhs < lhs);
347}
348
350template <class T1, class T2>
351KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator>(const pair<T1, T2>& lhs,
352 const pair<T1, T2>& rhs) {
353 return rhs < lhs;
354}
355
357template <class T1, class T2>
358KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator>=(const pair<T1, T2>& lhs,
359 const pair<T1, T2>& rhs) {
360 return !(lhs < rhs);
361}
362
367template <class T1, class T2>
368KOKKOS_FORCEINLINE_FUNCTION constexpr pair<T1, T2> make_pair(T1 x, T2 y) {
369 return (pair<T1, T2>(x, y));
370}
371
411template <class T1, class T2>
412KOKKOS_FORCEINLINE_FUNCTION pair<T1&, T2&> tie(T1& x, T2& y) {
413 return (pair<T1&, T2&>(x, y));
414}
415
416#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
417//
418// Specialization of Kokkos::pair for a \c void second argument. This
419// is not actually a "pair"; it only contains one element, the first.
420//
421template <class T1>
422struct KOKKOS_DEPRECATED pair<T1, void> {
423 using first_type = T1;
424 using second_type = void;
425
426 first_type first;
427 enum { second = 0 };
428
429 KOKKOS_DEFAULTED_FUNCTION constexpr pair() = default;
430
431 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(const first_type& f) : first(f) {}
432
433 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(const first_type& f, int)
434 : first(f) {}
435
436 template <class U>
437 KOKKOS_FORCEINLINE_FUNCTION constexpr pair(const pair<U, void>& p)
438 : first(p.first) {}
439
440 template <class U>
441 KOKKOS_FORCEINLINE_FUNCTION pair<T1, void>& operator=(
442 const pair<U, void>& p) {
443 first = p.first;
444 return *this;
445 }
446};
447
448//
449// Specialization of relational operators for Kokkos::pair<T1,void>.
450//
451
452#if defined(KOKKOS_ENABLE_DEPRECATION_WARNINGS) && \
453 defined(KOKKOS_COMPILER_GNU) && (KOKKOS_COMPILER_GNU < 1110)
454KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_PUSH()
455#endif
456template <class T1>
457KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator==(
458 const pair<T1, void>& lhs, const pair<T1, void>& rhs) {
459 return lhs.first == rhs.first;
460}
461
462template <class T1>
463KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator!=(
464 const pair<T1, void>& lhs, const pair<T1, void>& rhs) {
465 return !(lhs == rhs);
466}
467
468template <class T1>
469KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator<(
470 const pair<T1, void>& lhs, const pair<T1, void>& rhs) {
471 return lhs.first < rhs.first;
472}
473
474template <class T1>
475KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator<=(
476 const pair<T1, void>& lhs, const pair<T1, void>& rhs) {
477 return !(rhs < lhs);
478}
479
480template <class T1>
481KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator>(
482 const pair<T1, void>& lhs, const pair<T1, void>& rhs) {
483 return rhs < lhs;
484}
485
486template <class T1>
487KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator>=(
488 const pair<T1, void>& lhs, const pair<T1, void>& rhs) {
489 return !(lhs < rhs);
490}
491#if defined(KOKKOS_ENABLE_DEPRECATION_WARNINGS) && \
492 defined(KOKKOS_COMPILER_GNU) && (KOKKOS_COMPILER_GNU < 1110)
493KOKKOS_IMPL_DISABLE_DEPRECATED_WARNINGS_POP()
494#endif
495#endif
496
497namespace Impl {
498template <class T>
499struct is_pair_like : std::false_type {};
500template <class T, class U>
501struct is_pair_like<Kokkos::pair<T, U>> : std::true_type {};
502template <class T, class U>
503struct is_pair_like<std::pair<T, U>> : std::true_type {};
504
505} // end namespace Impl
506
507} // namespace Kokkos
508
509#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_PAIR
510#undef KOKKOS_IMPL_PUBLIC_INCLUDE
511#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_PAIR
512#endif
513#endif // KOKKOS_PAIR_HPP
KOKKOS_FORCEINLINE_FUNCTION pair< T1 &, T2 & > tie(T1 &x, T2 &y)
Return a pair of references to the input arguments.
KOKKOS_FORCEINLINE_FUNCTION constexpr pair< T1, T2 > make_pair(T1 x, T2 y)
Return a new pair.
KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator<(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Less-than operator for Kokkos::pair.
KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator<=(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Less-than-or-equal-to operator for Kokkos::pair.
KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator>=(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Greater-than-or-equal-to operator for Kokkos::pair.
KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator>(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Greater-than operator for Kokkos::pair.
A thread safe view to a bitset.
Replacement for std::pair that works on CUDA devices.
first_type first
The first element of the pair.
KOKKOS_FORCEINLINE_FUNCTION pair< T1, T2 > & operator=(const pair< U, V > &p)
Assignment operator.
KOKKOS_FORCEINLINE_FUNCTION constexpr pair(first_type const &f, second_type const &s)
Constructor that takes both elements of the pair.
KOKKOS_FORCEINLINE_FUNCTION constexpr pair(const pair< U, V > &p)
Copy constructor.
std::pair< T1, T2 > to_std_pair() const
Return the std::pair version of this object.
second_type second
The second element of the pair.
KOKKOS_DEFAULTED_FUNCTION constexpr pair()=default
Default constructor.