Ice 3.7 C++11 API Reference
Comparable.h
Go to the documentation of this file.
1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4 
5 #ifndef ICE_COMPARABLE_H
6 #define ICE_COMPARABLE_H
7 
8 #include <functional>
9 
10 namespace Ice
11 {
12 
19 template<typename T, typename U>
20 inline bool targetEqualTo(const T& lhs, const U& rhs)
21 {
22  if(lhs && rhs)
23  {
24  return *lhs == *rhs;
25  }
26  else
27  {
28  return !lhs && !rhs;
29  }
30 }
31 
38 template<typename T, typename U>
39 inline bool targetLess(const T& lhs, const U& rhs)
40 {
41  if(lhs && rhs)
42  {
43  return *lhs < *rhs;
44  }
45  else
46  {
47  return !lhs && rhs;
48  }
49 }
50 
57 template<typename T, typename U>
58 inline bool targetGreater(const T& lhs, const U& rhs)
59 {
60  return targetLess(rhs, lhs);
61 }
62 
69 template<typename T, typename U>
70 inline bool targetLessEqual(const T& lhs, const U& rhs)
71 {
72  return !targetGreater(lhs, rhs);
73 }
74 
81 template<typename T, typename U>
82 inline bool targetGreaterEqual(const T& lhs, const U& rhs)
83 {
84  return !targetLess(lhs, rhs);
85 }
86 
93 template<typename T, typename U>
94 inline bool targetNotEqualTo(const T& lhs, const U& rhs)
95 {
96  return !targetEqualTo(lhs, rhs);
97 }
98 
99 #ifdef ICE_CPP11_MAPPING
100 
105 template<typename T, template<typename> class Compare>
107 {
112  bool operator()(const T& lhs, const T& rhs) const
113  {
114  if(lhs && rhs)
115  {
116  return Compare<typename T::element_type>()(*lhs, *rhs);
117  }
118  else
119  {
120  return Compare<bool>()(static_cast<const bool>(lhs), static_cast<const bool>(rhs));
121  }
122  }
123 };
124 
125 //
126 // Relational operators for generated structs and classes
127 //
128 
135 template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
136 bool operator<(const C& lhs, const C& rhs)
137 {
138  return lhs.ice_tuple() < rhs.ice_tuple();
139 }
140 
147 template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
148 bool operator<=(const C& lhs, const C& rhs)
149 {
150  return lhs.ice_tuple() <= rhs.ice_tuple();
151 }
152 
159 template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
160 bool operator>(const C& lhs, const C& rhs)
161 {
162  return lhs.ice_tuple() > rhs.ice_tuple();
163 }
164 
171 template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
172 bool operator>=(const C& lhs, const C& rhs)
173 {
174  return lhs.ice_tuple() >= rhs.ice_tuple();
175 }
176 
183 template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
184 bool operator==(const C& lhs, const C& rhs)
185 {
186  return lhs.ice_tuple() == rhs.ice_tuple();
187 }
188 
195 template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
196 bool operator!=(const C& lhs, const C& rhs)
197 {
198  return lhs.ice_tuple() != rhs.ice_tuple();
199 }
200 
201 #endif
202 
203 }
204 
205 #endif
Ice::operator!=
bool operator!=(const C &lhs, const C &rhs)
Relational operator for generated structs and classes.
Definition: Comparable.h:196
Ice::TargetCompare::operator()
bool operator()(const T &lhs, const T &rhs) const
Executes the functor to compare the contents of two smart pointers.
Definition: Comparable.h:112
Ice::targetLessEqual
bool targetLessEqual(const T &lhs, const U &rhs)
Compares the contents of two smart pointers.
Definition: Comparable.h:70
Ice::operator==
bool operator==(const C &lhs, const C &rhs)
Relational operator for generated structs and classes.
Definition: Comparable.h:184
Ice::targetNotEqualTo
bool targetNotEqualTo(const T &lhs, const U &rhs)
Compares the contents of two smart pointers.
Definition: Comparable.h:94
Ice::TargetCompare
Functor class that compares the contents of two smart pointers of the given type using the given comp...
Definition: Comparable.h:107
Ice::operator<=
bool operator<=(const C &lhs, const C &rhs)
Relational operator for generated structs and classes.
Definition: Comparable.h:148
Ice::targetLess
bool targetLess(const T &lhs, const U &rhs)
Compares the contents of two smart pointers.
Definition: Comparable.h:39
Ice::operator>=
bool operator>=(const C &lhs, const C &rhs)
Relational operator for generated structs and classes.
Definition: Comparable.h:172
Ice::operator<
bool operator<(const C &lhs, const C &rhs)
Relational operator for generated structs and classes.
Definition: Comparable.h:136
Ice::targetEqualTo
bool targetEqualTo(const T &lhs, const U &rhs)
Compares the contents of two smart pointers.
Definition: Comparable.h:20
Ice::operator>
bool operator>(const C &lhs, const C &rhs)
Relational operator for generated structs and classes.
Definition: Comparable.h:160
Ice
Definition: BuiltinSequences.h:56
Ice::targetGreaterEqual
bool targetGreaterEqual(const T &lhs, const U &rhs)
Compares the contents of two smart pointers.
Definition: Comparable.h:82
Ice::targetGreater
bool targetGreater(const T &lhs, const U &rhs)
Compares the contents of two smart pointers.
Definition: Comparable.h:58