Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Kokkos_Pair.hpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 #ifndef KOKKOS_PAIR_HPP
00008 #define KOKKOS_PAIR_HPP
00009 
00010 #include <Kokkos_Macros.hpp>
00011 #include <utility>
00012 
00013 namespace Kokkos {
00022 template <class T1, class T2>
00023 struct pair
00024 {
00026   typedef T1 first_type;
00028   typedef T2 second_type;
00029 
00031   first_type  first;
00033   second_type second;
00034 
00040   KOKKOS_FORCEINLINE_FUNCTION
00041   pair()
00042     : first(), second()
00043   {}
00044 
00049   KOKKOS_FORCEINLINE_FUNCTION
00050   pair(first_type const& f, second_type const& s)
00051     : first(f), second(s)
00052   {}
00053 
00058   template <class U, class V>
00059   KOKKOS_FORCEINLINE_FUNCTION
00060   pair( const pair<U,V> &p)
00061     : first(p.first), second(p.second)
00062   {}
00063 
00068   template <class U, class V>
00069   KOKKOS_FORCEINLINE_FUNCTION
00070   pair<T1, T2> & operator=(const pair<U,V> &p)
00071   {
00072     first = p.first;
00073     second = p.second;
00074     return *this;
00075   }
00076 
00077   // from std::pair<U,V>
00078   template <class U, class V>
00079   pair( const std::pair<U,V> &p)
00080     : first(p.first), second(p.second)
00081   {}
00082 
00092   std::pair<T1,T2> to_std_pair() const
00093   { return std::make_pair(first,second); }
00094 };
00095 
00096 template <class T1, class T2>
00097 struct pair<T1&, T2&>
00098 {
00100   typedef T1& first_type;
00102   typedef T2& second_type;
00103 
00105   first_type  first;
00107   second_type second;
00108 
00113   KOKKOS_FORCEINLINE_FUNCTION
00114   pair(first_type f, second_type s)
00115     : first(f), second(s)
00116   {}
00117 
00122   template <class U, class V>
00123   KOKKOS_FORCEINLINE_FUNCTION
00124   pair( const pair<U,V> &p)
00125     : first(p.first), second(p.second)
00126   {}
00127 
00128   // from std::pair<U,V>
00129   template <class U, class V>
00130   pair( const std::pair<U,V> &p)
00131     : first(p.first), second(p.second)
00132   {}
00133 
00138   template <class U, class V>
00139   KOKKOS_FORCEINLINE_FUNCTION
00140   pair<first_type, second_type> & operator=(const pair<U,V> &p)
00141   {
00142     first = p.first;
00143     second = p.second;
00144     return *this;
00145   }
00146 
00156   std::pair<T1,T2> to_std_pair() const
00157   { return std::make_pair(first,second); }
00158 };
00159 
00160 template <class T1, class T2>
00161 struct pair<T1, T2&>
00162 {
00164   typedef T1  first_type;
00166   typedef T2& second_type;
00167 
00169   first_type  first;
00171   second_type second;
00172 
00177   KOKKOS_FORCEINLINE_FUNCTION
00178   pair(first_type const& f, second_type s)
00179     : first(f), second(s)
00180   {}
00181 
00186   template <class U, class V>
00187   KOKKOS_FORCEINLINE_FUNCTION
00188   pair( const pair<U,V> &p)
00189     : first(p.first), second(p.second)
00190   {}
00191 
00192   // from std::pair<U,V>
00193   template <class U, class V>
00194   pair( const std::pair<U,V> &p)
00195     : first(p.first), second(p.second)
00196   {}
00197 
00202   template <class U, class V>
00203   KOKKOS_FORCEINLINE_FUNCTION
00204   pair<first_type, second_type> & operator=(const pair<U,V> &p)
00205   {
00206     first = p.first;
00207     second = p.second;
00208     return *this;
00209   }
00210 
00220   std::pair<T1,T2> to_std_pair() const
00221   { return std::make_pair(first,second); }
00222 };
00223 
00224 template <class T1, class T2>
00225 struct pair<T1&, T2>
00226 {
00228   typedef T1&  first_type;
00230   typedef T2 second_type;
00231 
00233   first_type  first;
00235   second_type second;
00236 
00241   KOKKOS_FORCEINLINE_FUNCTION
00242   pair(first_type f, second_type const& s)
00243     : first(f), second(s)
00244   {}
00245 
00250   template <class U, class V>
00251   KOKKOS_FORCEINLINE_FUNCTION
00252   pair( const pair<U,V> &p)
00253     : first(p.first), second(p.second)
00254   {}
00255 
00256   // from std::pair<U,V>
00257   template <class U, class V>
00258   pair( const std::pair<U,V> &p)
00259     : first(p.first), second(p.second)
00260   {}
00261 
00266   template <class U, class V>
00267   KOKKOS_FORCEINLINE_FUNCTION
00268   pair<first_type, second_type> & operator=(const pair<U,V> &p)
00269   {
00270     first = p.first;
00271     second = p.second;
00272     return *this;
00273   }
00274 
00284   std::pair<T1,T2> to_std_pair() const
00285   { return std::make_pair(first,second); }
00286 };
00287 
00289 template <class T1, class T2>
00290 KOKKOS_FORCEINLINE_FUNCTION
00291 bool operator== (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
00292 { return lhs.first==rhs.first && lhs.second==rhs.second; }
00293 
00295 template <class T1, class T2>
00296 KOKKOS_FORCEINLINE_FUNCTION
00297 bool operator!= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
00298 { return !(lhs==rhs); }
00299 
00301 template <class T1, class T2>
00302 KOKKOS_FORCEINLINE_FUNCTION
00303 bool operator<  (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
00304 { return lhs.first<rhs.first || (!(rhs.first<lhs.first) && lhs.second<rhs.second); }
00305 
00307 template <class T1, class T2>
00308 KOKKOS_FORCEINLINE_FUNCTION
00309 bool operator<= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
00310 { return !(rhs<lhs); }
00311 
00313 template <class T1, class T2>
00314 KOKKOS_FORCEINLINE_FUNCTION
00315 bool operator>  (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
00316 { return rhs<lhs; }
00317 
00319 template <class T1, class T2>
00320 KOKKOS_FORCEINLINE_FUNCTION
00321 bool operator>= (const pair<T1,T2>& lhs, const pair<T1,T2>& rhs)
00322 { return !(lhs<rhs); }
00323 
00328 template <class T1,class T2>
00329 KOKKOS_FORCEINLINE_FUNCTION
00330 pair<T1,T2> make_pair (T1 x, T2 y)
00331 { return ( pair<T1,T2>(x,y) ); }
00332 
00372 template <class T1,class T2>
00373 KOKKOS_FORCEINLINE_FUNCTION
00374 pair<T1 &,T2 &> tie (T1 & x, T2 & y)
00375 { return ( pair<T1 &,T2 &>(x,y) ); }
00376 
00377 //
00378 // Specialization of Kokkos::pair for a \c void second argument.  This
00379 // is not actually a "pair"; it only contains one element, the first.
00380 //
00381 template <class T1>
00382 struct pair<T1,void>
00383 {
00384   typedef T1 first_type;
00385   typedef void second_type;
00386 
00387   first_type  first;
00388   enum { second = 0 };
00389 
00390   KOKKOS_FORCEINLINE_FUNCTION
00391   pair()
00392     : first()
00393   {}
00394 
00395   KOKKOS_FORCEINLINE_FUNCTION
00396   pair(const first_type & f)
00397     : first(f)
00398   {}
00399 
00400   KOKKOS_FORCEINLINE_FUNCTION
00401   pair(const first_type & f, int)
00402     : first(f)
00403   {}
00404 
00405   template <class U>
00406   KOKKOS_FORCEINLINE_FUNCTION
00407   pair( const pair<U,void> &p)
00408     : first(p.first)
00409   {}
00410 
00411   template <class U>
00412   KOKKOS_FORCEINLINE_FUNCTION
00413   pair<T1, void> & operator=(const pair<U,void> &p)
00414   {
00415     first = p.first;
00416     return *this;
00417   }
00418 };
00419 
00420 //
00421 // Specialization of relational operators for Kokkos::pair<T1,void>.
00422 //
00423 
00424 template <class T1>
00425 KOKKOS_FORCEINLINE_FUNCTION
00426 bool operator== (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
00427 { return lhs.first==rhs.first; }
00428 
00429 template <class T1>
00430 KOKKOS_FORCEINLINE_FUNCTION
00431 bool operator!= (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
00432 { return !(lhs==rhs); }
00433 
00434 template <class T1>
00435 KOKKOS_FORCEINLINE_FUNCTION
00436 bool operator<  (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
00437 { return lhs.first<rhs.first; }
00438 
00439 template <class T1>
00440 KOKKOS_FORCEINLINE_FUNCTION
00441 bool operator<= (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
00442 { return !(rhs<lhs); }
00443 
00444 template <class T1>
00445 KOKKOS_FORCEINLINE_FUNCTION
00446 bool operator>  (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
00447 { return rhs<lhs; }
00448 
00449 template <class T1>
00450 KOKKOS_FORCEINLINE_FUNCTION
00451 bool operator>= (const pair<T1,void>& lhs, const pair<T1,void>& rhs)
00452 { return !(lhs<rhs); }
00453 
00454 } // namespace Kokkos
00455 
00456 
00457 #endif //KOKKOS_PAIR_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends