Viskores  1.0
Pair.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 
19 #ifndef viskores_Pair_h
20 #define viskores_Pair_h
21 
24 
25 #include <iostream>
26 #include <utility>
27 
28 namespace viskores
29 {
30 
36 template <typename T1, typename T2>
37 struct Pair
38 {
41  using FirstType = T1;
42 
45  using SecondType = T2;
46 
50 
54 
59 
64 
65  Pair() = default;
66 
68  Pair(const FirstType& firstSrc, const SecondType& secondSrc)
69  : first(firstSrc)
70  , second(secondSrc)
71  {
72  }
73 
76  Pair(FirstType&& firstSrc,
77  SecondType&& secondSrc) noexcept(noexcept(FirstType{ std::declval<FirstType&&>() },
78  SecondType{ std::declval<SecondType&&>() }))
79  : first(std::move(firstSrc))
80  , second(std::move(secondSrc))
81  {
82  }
83 
84  Pair(const Pair&) = default;
85  Pair(Pair&&) = default;
86 
87  template <typename U1, typename U2>
89  : first(src.first)
90  , second(src.second)
91  {
92  }
93 
94  template <typename U1, typename U2>
96  noexcept(U1{ std::declval<U1&&>() }, U2{ std::declval<U2&&>() }))
97  : first(std::move(src.first))
98  , second(std::move(src.second))
99  {
100  }
101 
102  template <typename U1, typename U2>
103  VISKORES_EXEC_CONT Pair(const std::pair<U1, U2>& src)
104  : first(src.first)
105  , second(src.second)
106  {
107  }
108 
109  template <typename U1, typename U2>
110  VISKORES_EXEC_CONT Pair(std::pair<U1, U2>&& src) noexcept(noexcept(U1{ std::declval<U1&&>() },
111  U2{ std::declval<U2&&>() }))
112  : first(std::move(src.first))
113  , second(std::move(src.second))
114  {
115  }
116 
118  const viskores::Pair<FirstType, SecondType>& src) = default;
120  default;
121 
124  {
125  return ((this->first == other.first) && (this->second == other.second));
126  }
127 
130  {
131  return !(*this == other);
132  }
133 
139  {
140  return ((this->first < other.first) ||
141  (!(other.first < this->first) && (this->second < other.second)));
142  }
143 
149  {
150  return (other < *this);
151  }
152 
158  {
159  return !(other < *this);
160  }
161 
167  {
168  return !(*this < other);
169  }
170 };
171 
175 template <typename T, typename U>
177  const viskores::Pair<T, U>& b)
178 {
179  return viskores::Pair<T, U>(a.first + b.first, a.second + b.second);
180 }
181 
182 template <typename T1, typename T2>
184 make_Pair(T1&& v1, T2&& v2)
185 {
186  using DT1 = typename std::decay<T1>::type;
187  using DT2 = typename std::decay<T2>::type;
188  using PairT = viskores::Pair<DT1, DT2>;
189 
190  return PairT(std::forward<T1>(v1), std::forward<T2>(v2));
191 }
192 
193 } // namespace viskores
194 
195 #endif //viskores_Pair_h
viskores::Pair::FirstType
T1 FirstType
The type of the first object.
Definition: Pair.h:41
viskores::make_Pair
viskores::Pair< typename std::decay< T1 >::type, typename std::decay< T2 >::type > make_Pair(T1 &&v1, T2 &&v2)
Definition: Pair.h:184
viskores::Pair::Pair
Pair(viskores::Pair< U1, U2 > &&src) noexcept(noexcept(U1{ std::declval< U1 && >() }, U2{ std::declval< U2 && >() }))
Definition: Pair.h:95
viskores::Pair::Pair
Pair(std::pair< U1, U2 > &&src) noexcept(noexcept(U1{ std::declval< U1 && >() }, U2{ std::declval< U2 && >() }))
Definition: Pair.h:110
viskores::Pair::operator>=
bool operator>=(const viskores::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:166
viskores::Pair::operator>
bool operator>(const viskores::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:148
VISKORES_SUPPRESS_EXEC_WARNINGS
#define VISKORES_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:61
viskores::operator+
VISKORES_EXEC_CONT viskores::Vec< T, Size > operator+(viskores::Vec< T, Size > a, const viskores::Vec< T, Size > &b)
Definition: VecOperators.h:100
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::Pair::first_type
FirstType first_type
The same as FirstType, but follows the naming convention of std::pair.
Definition: Pair.h:49
viskores::Pair::Pair
Pair(FirstType &&firstSrc, SecondType &&secondSrc) noexcept(noexcept(FirstType{ std::declval< FirstType && >() }, SecondType{ std::declval< SecondType && >() }))
Definition: Pair.h:76
ExportMacros.h
viskores::Pair::second_type
SecondType second_type
The same as SecondType, but follows the naming convention of std::pair.
Definition: Pair.h:53
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::Pair::first
FirstType first
The pair's first object.
Definition: Pair.h:58
Configure.h
viskores::Pair::Pair
Pair(const FirstType &firstSrc, const SecondType &secondSrc)
Definition: Pair.h:68
viskores::Pair::Pair
Pair()=default
viskores::Pair::operator=
viskores::Pair< FirstType, SecondType > & operator=(const viskores::Pair< FirstType, SecondType > &src)=default
viskores::Pair::operator!=
bool operator!=(const viskores::Pair< FirstType, SecondType > &other) const
Definition: Pair.h:129
viskores::Pair
A viskores::Pair is essentially the same as an STL pair object except that the methods (constructors ...
Definition: Pair.h:37
viskores::Pair::Pair
Pair(const viskores::Pair< U1, U2 > &src)
Definition: Pair.h:88
viskores::Pair::Pair
Pair(const std::pair< U1, U2 > &src)
Definition: Pair.h:103
viskores::Pair::operator<
bool operator<(const viskores::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:138
viskores::Pair::second
SecondType second
The pair's second object.
Definition: Pair.h:63
viskores::Pair::operator<=
bool operator<=(const viskores::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:157
viskores::Pair::SecondType
T2 SecondType
The type of the second object.
Definition: Pair.h:45
viskores::Pair::operator==
bool operator==(const viskores::Pair< FirstType, SecondType > &other) const
Definition: Pair.h:123