Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
Kokkos_Pair.hpp File Reference

Declaration and definition of Kokkos::pair. More...

#include <Kokkos_Macros.hpp>
#include <utility>

Go to the source code of this file.

Classes

struct  Kokkos::pair< T1, T2 >
 Replacement for std::pair that works on CUDA devices. More...
 

Namespaces

namespace  Kokkos::Impl
 ScopeGuard Some user scope issues have been identified with some Kokkos::finalize calls; ScopeGuard aims to correct these issues.
 

Functions

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator== (const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
 Equality operator for Kokkos::pair.
 
template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator!= (const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
 Inequality operator for Kokkos::pair.
 
template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator< (const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
 Less-than operator for Kokkos::pair.
 
template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator<= (const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
 Less-than-or-equal-to operator for Kokkos::pair.
 
template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator> (const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
 Greater-than operator for Kokkos::pair.
 
template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator>= (const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
 Greater-than-or-equal-to operator for Kokkos::pair.
 
template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr pair< T1, T2 > Kokkos::make_pair (T1 x, T2 y)
 Return a new pair.
 
template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION pair< T1 &, T2 & > Kokkos::tie (T1 &x, T2 &y)
 Return a pair of references to the input arguments.
 

Detailed Description

Declaration and definition of Kokkos::pair.

This header file declares and defines Kokkos::pair and its related nonmember functions.

Definition in file Kokkos_Pair.hpp.

Function Documentation

◆ operator==()

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator== ( const pair< T1, T2 > &  lhs,
const pair< T1, T2 > &  rhs 
)
constexpr

Equality operator for Kokkos::pair.

Definition at line 323 of file Kokkos_Pair.hpp.

◆ operator!=()

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator!= ( const pair< T1, T2 > &  lhs,
const pair< T1, T2 > &  rhs 
)
constexpr

Inequality operator for Kokkos::pair.

Definition at line 330 of file Kokkos_Pair.hpp.

◆ operator<()

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator< ( const pair< T1, T2 > &  lhs,
const pair< T1, T2 > &  rhs 
)
constexpr

Less-than operator for Kokkos::pair.

Definition at line 337 of file Kokkos_Pair.hpp.

◆ operator<=()

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator<= ( const pair< T1, T2 > &  lhs,
const pair< T1, T2 > &  rhs 
)
constexpr

Less-than-or-equal-to operator for Kokkos::pair.

Definition at line 345 of file Kokkos_Pair.hpp.

◆ operator>()

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator> ( const pair< T1, T2 > &  lhs,
const pair< T1, T2 > &  rhs 
)
constexpr

Greater-than operator for Kokkos::pair.

Definition at line 352 of file Kokkos_Pair.hpp.

◆ operator>=()

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr bool Kokkos::operator>= ( const pair< T1, T2 > &  lhs,
const pair< T1, T2 > &  rhs 
)
constexpr

Greater-than-or-equal-to operator for Kokkos::pair.

Definition at line 359 of file Kokkos_Pair.hpp.

◆ make_pair()

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION constexpr pair< T1, T2 > Kokkos::make_pair ( T1  x,
T2  y 
)
constexpr

Return a new pair.

This is a "nonmember constructor" for Kokkos::pair. It works just like std::make_pair.

Definition at line 369 of file Kokkos_Pair.hpp.

◆ tie()

template<class T1 , class T2 >
KOKKOS_FORCEINLINE_FUNCTION pair< T1 &, T2 & > Kokkos::tie ( T1 &  x,
T2 &  y 
)

Return a pair of references to the input arguments.

This compares to std::tie (new in C++11). You can use it to assign to two variables at once, from the result of a function that returns a pair. For example (device and host attributes omitted for brevity):

// Declaration of the function to call.
// First return value: operation count.
// Second return value: whether all operations succeeded.
Kokkos::pair<int, bool> someFunction ();
// Code that uses Kokkos::tie.
int myFunction () {
int count = 0;
bool success = false;
// This assigns to both count and success.
Kokkos::tie (count, success) = someFunction ();
if (! success) {
// ... Some operation failed;
// take corrective action ...
}
return count;
}
Replacement for std::pair that works on CUDA devices.
Definition: Kokkos_Pair.hpp:43

The line that uses tie() could have been written like this:

Kokkos::pair<int, bool> result = someFunction ();
count = result.first;
success = result.second;
first_type first
The first element of the pair.
Definition: Kokkos_Pair.hpp:50
second_type second
The second element of the pair.
Definition: Kokkos_Pair.hpp:52

Using tie() saves two lines of code and avoids a copy of each element of the pair. The latter could be significant if one or both elements of the pair are more substantial objects than int or bool.

Definition at line 413 of file Kokkos_Pair.hpp.