Molassembler  3.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Pair.h
Go to the documentation of this file.
1 
11 #ifndef INLCUDE_MOLASSEMBLER_TEMPLE_PAIR_H
12 #define INLCUDE_MOLASSEMBLER_TEMPLE_PAIR_H
13 
15 
16 #include <utility>
17 
18 namespace Scine {
19 namespace Molassembler {
20 namespace Temple {
21 
26 template<typename T, typename U>
27 struct Pair {
30  T first;
31  U second;
33 
36  constexpr Pair() : first(T {}), second (U {}) {}
37 
39  constexpr Pair(const T& passFirst, const U& passSecond)
40  : first(passFirst), second(passSecond)
41  {}
42 
44  constexpr Pair(T&& passFirst, U&& passSecond)
45  : first(passFirst), second(passSecond)
46  {}
48 
52  constexpr Pair(const Pair& other)
53  : first(other.first), second(other.second) {}
55  constexpr Pair(Pair&& other) noexcept
56  : first(std::move(other.first)), second(std::move(other.second)) {}
58  constexpr Pair& operator = (const Pair& other) {
59  first = other.first;
60  second = other.second;
61 
62  return *this;
63  }
65  constexpr Pair& operator = (Pair&& other) noexcept {
66  first = std::move(other.first);
67  second = std::move(other.second);
68 
69  return *this;
70  }
71  ~Pair() = default;
73 
77  PURITY_WEAK constexpr bool operator < (const Pair& other) const {
78  if(first > other.first) {
79  return false;
80  }
81 
82  if(first == other.first) {
83  return second < other.second;
84  }
85 
86  return true;
87  }
88 
90  PURITY_WEAK constexpr bool operator > (const Pair& other) const {
91  return (other < *this);
92  }
93 
95  PURITY_WEAK constexpr bool operator == (const Pair& other) const {
96  return (
97  first == other.first
98  && second == other.second
99  );
100  }
101 
103  PURITY_WEAK constexpr bool operator != (const Pair& other) const {
104  return !(*this == other);
105  }
107 };
108 
109 } // namespace Temple
110 } // namespace Molassembler
111 } // namespace Scine
112 
113 #endif
~Pair()=default
Copy constructor.
#define PURITY_WEAK
Definition: Preprocessor.h:36
Heterogeneous pair type.
Definition: Pair.h:27
constexpr Pair & operator=(const Pair &other)
Copy assignment.
Definition: Pair.h:58
PURITY_WEAK constexpr bool operator<(const Pair &other) const
Lexicographical comparison.
Definition: Pair.h:77
Defines a set of useful preprocessor macros.
constexpr Pair()
Value constructor by copy.
Definition: Pair.h:36
PURITY_WEAK constexpr bool operator>(const Pair &other) const
Lexicographical comparison.
Definition: Pair.h:90
constexpr Pair(T &&passFirst, U &&passSecond)
Value constructor by move.
Definition: Pair.h:44
PURITY_WEAK constexpr bool operator!=(const Pair &other) const
Lexicographical comparison.
Definition: Pair.h:103
constexpr Pair(Pair &&other) noexcept
Move constructor.
Definition: Pair.h:55
constexpr Pair(const Pair &other)
Copy constructor.
Definition: Pair.h:52
constexpr Pair(const T &passFirst, const U &passSecond)
Value constructor by copy.
Definition: Pair.h:39
PURITY_WEAK constexpr bool operator==(const Pair &other) const
Lexicographical comparison.
Definition: Pair.h:95