VTK-m  2.0
Pair.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 
11 #ifndef vtk_m_Pair_h
12 #define vtk_m_Pair_h
13 
14 #include <vtkm/internal/Configure.h>
16 
17 #include <iostream>
18 #include <utility>
19 
20 namespace vtkm
21 {
22 
28 template <typename T1, typename T2>
29 struct Pair
30 {
33  using FirstType = T1;
34 
37  using SecondType = T2;
38 
42 
46 
51 
56 
57  Pair() = default;
58 
60  Pair(const FirstType& firstSrc, const SecondType& secondSrc)
61  : first(firstSrc)
62  , second(secondSrc)
63  {
64  }
65 
68  Pair(FirstType&& firstSrc,
69  SecondType&& secondSrc) noexcept(noexcept(FirstType{ std::declval<FirstType&&>() },
70  SecondType{ std::declval<SecondType&&>() }))
71  : first(std::move(firstSrc))
72  , second(std::move(secondSrc))
73  {
74  }
75 
76  Pair(const Pair&) = default;
77  Pair(Pair&&) = default;
78 
79  template <typename U1, typename U2>
81  : first(src.first)
82  , second(src.second)
83  {
84  }
85 
86  template <typename U1, typename U2>
87  VTKM_EXEC_CONT Pair(vtkm::Pair<U1, U2>&& src) noexcept(noexcept(U1{ std::declval<U1&&>() },
88  U2{ std::declval<U2&&>() }))
89  : first(std::move(src.first))
90  , second(std::move(src.second))
91  {
92  }
93 
94  template <typename U1, typename U2>
95  VTKM_EXEC_CONT Pair(const std::pair<U1, U2>& src)
96  : first(src.first)
97  , second(src.second)
98  {
99  }
100 
101  template <typename U1, typename U2>
102  VTKM_EXEC_CONT Pair(std::pair<U1, U2>&& src) noexcept(noexcept(U1{ std::declval<U1&&>() },
103  U2{ std::declval<U2&&>() }))
104  : first(std::move(src.first))
105  , second(std::move(src.second))
106  {
107  }
108 
110  default;
112 
115  {
116  return ((this->first == other.first) && (this->second == other.second));
117  }
118 
121  {
122  return !(*this == other);
123  }
124 
130  {
131  return ((this->first < other.first) ||
132  (!(other.first < this->first) && (this->second < other.second)));
133  }
134 
139  bool operator>(const vtkm::Pair<FirstType, SecondType>& other) const { return (other < *this); }
140 
145  bool operator<=(const vtkm::Pair<FirstType, SecondType>& other) const { return !(other < *this); }
146 
151  bool operator>=(const vtkm::Pair<FirstType, SecondType>& other) const { return !(*this < other); }
152 };
153 
157 template <typename T, typename U>
159 {
160  return vtkm::Pair<T, U>(a.first + b.first, a.second + b.second);
161 }
162 
163 template <typename T1, typename T2>
165  T1&& v1,
166  T2&& v2)
167 {
168  using DT1 = typename std::decay<T1>::type;
169  using DT2 = typename std::decay<T2>::type;
170  using PairT = vtkm::Pair<DT1, DT2>;
171 
172  return PairT(std::forward<T1>(v1), std::forward<T2>(v2));
173 }
174 
175 } // namespace vtkm
176 
177 #endif //vtk_m_Pair_h
vtkm::Pair::FirstType
T1 FirstType
The type of the first object.
Definition: Pair.h:33
vtkm::make_Pair
VTKM_EXEC_CONT vtkm::Pair< typename std::decay< T1 >::type, typename std::decay< T2 >::type > make_Pair(T1 &&v1, T2 &&v2)
Definition: Pair.h:164
vtkm::Pair::Pair
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT Pair(FirstType &&firstSrc, SecondType &&secondSrc) noexcept(noexcept(FirstType{ std::declval< FirstType && >() }, SecondType{ std::declval< SecondType && >() }))
Definition: Pair.h:68
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Pair::Pair
VTKM_EXEC_CONT Pair(const vtkm::Pair< U1, U2 > &src)
Definition: Pair.h:80
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::Pair::Pair
VTKM_EXEC_CONT Pair(const FirstType &firstSrc, const SecondType &secondSrc)
Definition: Pair.h:60
vtkm::Pair::operator==
VTKM_EXEC_CONT bool operator==(const vtkm::Pair< FirstType, SecondType > &other) const
Definition: Pair.h:114
vtkm::Pair::second_type
SecondType second_type
The same as SecondType, but follows the naming convention of std::pair.
Definition: Pair.h:45
vtkm::Pair::operator>
VTKM_EXEC_CONT bool operator>(const vtkm::Pair< FirstType, SecondType > &other) const
Tests ordering on the first object, and then on the second object if the first are equal.
Definition: Pair.h:139
ExportMacros.h
vtkm::operator+
VTKM_EXEC_CONT vtkm::Vec< T, Size > operator+(vtkm::Vec< T, Size > a, const vtkm::Vec< T, Size > &b)
Definition: VecOperators.h:92
vtkm::Pair::SecondType
T2 SecondType
The type of the second object.
Definition: Pair.h:37
vtkm::Pair::Pair
VTKM_EXEC_CONT Pair(std::pair< U1, U2 > &&src) noexcept(noexcept(U1{ std::declval< U1 && >() }, U2{ std::declval< U2 && >() }))
Definition: Pair.h:102
vtkm::Pair::first
FirstType first
The pair's first object.
Definition: Pair.h:50
vtkm::Pair::operator>=
VTKM_EXEC_CONT bool operator>=(const vtkm::Pair< FirstType, SecondType > &other) const
Tests ordering on the first object, and then on the second object if the first are equal.
Definition: Pair.h:151
vtkm::Pair::operator=
vtkm::Pair< FirstType, SecondType > & operator=(const vtkm::Pair< FirstType, SecondType > &src)=default
vtkm::Pair::Pair
VTKM_EXEC_CONT Pair(const std::pair< U1, U2 > &src)
Definition: Pair.h:95
vtkm::Pair::Pair
VTKM_EXEC_CONT Pair(vtkm::Pair< U1, U2 > &&src) noexcept(noexcept(U1{ std::declval< U1 && >() }, U2{ std::declval< U2 && >() }))
Definition: Pair.h:87
vtkm::Pair::first_type
FirstType first_type
The same as FirstType, but follows the naming convention of std::pair.
Definition: Pair.h:41
vtkm::Pair::operator!=
VTKM_EXEC_CONT bool operator!=(const vtkm::Pair< FirstType, SecondType > &other) const
Definition: Pair.h:120
vtkm::Pair::Pair
Pair()=default
vtkm::Pair::operator<=
VTKM_EXEC_CONT bool operator<=(const vtkm::Pair< FirstType, SecondType > &other) const
Tests ordering on the first object, and then on the second object if the first are equal.
Definition: Pair.h:145
vtkm::Pair
A vtkm::Pair is essentially the same as an STL pair object except that the methods (constructors and ...
Definition: Pair.h:29
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53
vtkm::Pair::second
SecondType second
The pair's second object.
Definition: Pair.h:55
vtkm::Pair::operator<
VTKM_EXEC_CONT bool operator<(const vtkm::Pair< FirstType, SecondType > &other) const
Tests ordering on the first object, and then on the second object if the first are equal.
Definition: Pair.h:129