Kokkos Core Kernels Package  Version of the Day
Kokkos_Pair.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 2.0
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
47 
48 #ifndef KOKKOS_PAIR_HPP
49 #define KOKKOS_PAIR_HPP
50 
51 #include <Kokkos_Macros.hpp>
52 #include <utility>
53 
54 namespace Kokkos {
63 template <class T1, class T2>
64 struct pair
65 {
67  typedef T1 first_type;
69  typedef T2 second_type;
70 
72  first_type first;
74  second_type second;
75 
81  KOKKOS_FORCEINLINE_FUNCTION
82  pair()
83  : first(), second()
84  {}
85 
90  KOKKOS_FORCEINLINE_FUNCTION
91  pair(first_type const& f, second_type const& s)
92  : first(f), second(s)
93  {}
94 
99  template <class U, class V>
100  KOKKOS_FORCEINLINE_FUNCTION
101  pair( const pair<U,V> &p)
102  : first(p.first), second(p.second)
103  {}
104 
109  template <class U, class V>
110  KOKKOS_FORCEINLINE_FUNCTION
112  {
113  first = p.first;
114  second = p.second;
115  return *this;
116  }
117 
118  // from std::pair<U,V>
119  template <class U, class V>
120  pair( const std::pair<U,V> &p)
121  : first(p.first), second(p.second)
122  {}
123 
133  std::pair<T1,T2> to_std_pair() const
134  { return std::make_pair(first,second); }
135 };
136 
137 template <class T1, class T2>
138 struct pair<T1&, T2&>
139 {
141  typedef T1& first_type;
143  typedef T2& second_type;
144 
146  first_type first;
148  second_type second;
149 
154  KOKKOS_FORCEINLINE_FUNCTION
155  pair(first_type f, second_type s)
156  : first(f), second(s)
157  {}
158 
163  template <class U, class V>
164  KOKKOS_FORCEINLINE_FUNCTION
165  pair( const pair<U,V> &p)
166  : first(p.first), second(p.second)
167  {}
168 
169  // from std::pair<U,V>
170  template <class U, class V>
171  pair( const std::pair<U,V> &p)
172  : first(p.first), second(p.second)
173  {}
174 
179  template <class U, class V>
180  KOKKOS_FORCEINLINE_FUNCTION
182  {
183  first = p.first;
184  second = p.second;
185  return *this;
186  }
187 
197  std::pair<T1,T2> to_std_pair() const
198  { return std::make_pair(first,second); }
199 };
200 
201 template <class T1, class T2>
202 struct pair<T1, T2&>
203 {
205  typedef T1 first_type;
207  typedef T2& second_type;
208 
210  first_type first;
212  second_type second;
213 
218  KOKKOS_FORCEINLINE_FUNCTION
219  pair(first_type const& f, second_type s)
220  : first(f), second(s)
221  {}
222 
227  template <class U, class V>
228  KOKKOS_FORCEINLINE_FUNCTION
229  pair( const pair<U,V> &p)
230  : first(p.first), second(p.second)
231  {}
232 
233  // from std::pair<U,V>
234  template <class U, class V>
235  pair( const std::pair<U,V> &p)
236  : first(p.first), second(p.second)
237  {}
238 
243  template <class U, class V>
244  KOKKOS_FORCEINLINE_FUNCTION
246  {
247  first = p.first;
248  second = p.second;
249  return *this;
250  }
251 
261  std::pair<T1,T2> to_std_pair() const
262  { return std::make_pair(first,second); }
263 };
264 
265 template <class T1, class T2>
266 struct pair<T1&, T2>
267 {
269  typedef T1& first_type;
271  typedef T2 second_type;
272 
274  first_type first;
276  second_type second;
277 
282  KOKKOS_FORCEINLINE_FUNCTION
283  pair(first_type f, second_type const& s)
284  : first(f), second(s)
285  {}
286 
291  template <class U, class V>
292  KOKKOS_FORCEINLINE_FUNCTION
293  pair( const pair<U,V> &p)
294  : first(p.first), second(p.second)
295  {}
296 
297  // from std::pair<U,V>
298  template <class U, class V>
299  pair( const std::pair<U,V> &p)
300  : first(p.first), second(p.second)
301  {}
302 
307  template <class U, class V>
308  KOKKOS_FORCEINLINE_FUNCTION
310  {
311  first = p.first;
312  second = p.second;
313  return *this;
314  }
315 
325  std::pair<T1,T2> to_std_pair() const
326  { return std::make_pair(first,second); }
327 };
328 
330 template <class T1, class T2>
331 KOKKOS_FORCEINLINE_FUNCTION
332 bool operator== (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
333 { return lhs.first==rhs.first && lhs.second==rhs.second; }
334 
336 template <class T1, class T2>
337 KOKKOS_FORCEINLINE_FUNCTION
338 bool operator!= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
339 { return !(lhs==rhs); }
340 
342 template <class T1, class T2>
343 KOKKOS_FORCEINLINE_FUNCTION
344 bool operator< (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
345 { return lhs.first<rhs.first || (!(rhs.first<lhs.first) && lhs.second<rhs.second); }
346 
348 template <class T1, class T2>
349 KOKKOS_FORCEINLINE_FUNCTION
350 bool operator<= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
351 { return !(rhs<lhs); }
352 
354 template <class T1, class T2>
355 KOKKOS_FORCEINLINE_FUNCTION
356 bool operator> (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
357 { return rhs<lhs; }
358 
360 template <class T1, class T2>
361 KOKKOS_FORCEINLINE_FUNCTION
362 bool operator>= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
363 { return !(lhs<rhs); }
364 
369 template <class T1,class T2>
370 KOKKOS_FORCEINLINE_FUNCTION
371 pair<T1,T2> make_pair (T1 x, T2 y)
372 { return ( pair<T1,T2>(x,y) ); }
373 
413 template <class T1,class T2>
414 KOKKOS_FORCEINLINE_FUNCTION
415 pair<T1 &,T2 &> tie (T1 & x, T2 & y)
416 { return ( pair<T1 &,T2 &>(x,y) ); }
417 
418 //
419 // Specialization of Kokkos::pair for a \c void second argument. This
420 // is not actually a "pair"; it only contains one element, the first.
421 //
422 template <class T1>
423 struct pair<T1,void>
424 {
425  typedef T1 first_type;
426  typedef void second_type;
427 
428  first_type first;
429  enum { second = 0 };
430 
431  KOKKOS_FORCEINLINE_FUNCTION
432  pair()
433  : first()
434  {}
435 
436  KOKKOS_FORCEINLINE_FUNCTION
437  pair(const first_type & f)
438  : first(f)
439  {}
440 
441  KOKKOS_FORCEINLINE_FUNCTION
442  pair(const first_type & f, int)
443  : first(f)
444  {}
445 
446  template <class U>
447  KOKKOS_FORCEINLINE_FUNCTION
448  pair( const pair<U,void> &p)
449  : first(p.first)
450  {}
451 
452  template <class U>
453  KOKKOS_FORCEINLINE_FUNCTION
455  {
456  first = p.first;
457  return *this;
458  }
459 };
460 
461 //
462 // Specialization of relational operators for Kokkos::pair<T1,void>.
463 //
464 
465 template <class T1>
466 KOKKOS_FORCEINLINE_FUNCTION
467 bool operator== (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
468 { return lhs.first==rhs.first; }
469 
470 template <class T1>
471 KOKKOS_FORCEINLINE_FUNCTION
472 bool operator!= (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
473 { return !(lhs==rhs); }
474 
475 template <class T1>
476 KOKKOS_FORCEINLINE_FUNCTION
477 bool operator< (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
478 { return lhs.first<rhs.first; }
479 
480 template <class T1>
481 KOKKOS_FORCEINLINE_FUNCTION
482 bool operator<= (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
483 { return !(rhs<lhs); }
484 
485 template <class T1>
486 KOKKOS_FORCEINLINE_FUNCTION
487 bool operator> (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
488 { return rhs<lhs; }
489 
490 template <class T1>
491 KOKKOS_FORCEINLINE_FUNCTION
492 bool operator>= (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
493 { return !(lhs<rhs); }
494 
495 } // namespace Kokkos
496 
497 
498 #endif //KOKKOS_PAIR_HPP
KOKKOS_FORCEINLINE_FUNCTION pair()
Default constructor.
Definition: Kokkos_Pair.hpp:82
KOKKOS_INLINE_FUNCTION bool operator!=(const complex< RealType > &x, const complex< RealType > &y)
Inequality operator for two complex numbers.
T2 second_type
The second template parameter of this class.
Definition: Kokkos_Pair.hpp:69
Replacement for std::pair that works on CUDA devices.
Definition: Kokkos_Pair.hpp:64
KOKKOS_FORCEINLINE_FUNCTION pair(first_type const &f, second_type const &s)
Constructor that takes both elements of the pair.
Definition: Kokkos_Pair.hpp:91
std::pair< T1, T2 > to_std_pair() const
Return the std::pair version of this object.
first_type first
The first element of the pair.
Definition: Kokkos_Pair.hpp:72
KOKKOS_FORCEINLINE_FUNCTION bool operator>(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Greater-than operator for Kokkos::pair.
T1 first_type
The first template parameter of this class.
Definition: Kokkos_Pair.hpp:67
KOKKOS_INLINE_FUNCTION bool operator==(const complex< RealType > &x, const complex< RealType > &y)
Equality operator for two complex numbers.
KOKKOS_FORCEINLINE_FUNCTION bool operator>=(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Greater-than-or-equal-to operator for Kokkos::pair.
KOKKOS_FORCEINLINE_FUNCTION pair< T1 &, T2 & > tie(T1 &x, T2 &y)
Return a pair of references to the input arguments.
KOKKOS_FORCEINLINE_FUNCTION pair(const pair< U, V > &p)
Copy constructor.
second_type second
The second element of the pair.
Definition: Kokkos_Pair.hpp:74
KOKKOS_FORCEINLINE_FUNCTION pair< T1, T2 > make_pair(T1 x, T2 y)
Return a new pair.
KOKKOS_FORCEINLINE_FUNCTION pair< T1, T2 > & operator=(const pair< U, V > &p)
Assignment operator.