Skip to content

Commit 5bb06a3

Browse files
CXX-739 Add comparison operators to bsoncxx::view_or_value
1 parent c8a76db commit 5bb06a3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/bsoncxx/view_or_value.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ class view_or_value {
127127
View _view;
128128
};
129129

130+
///
131+
/// Compare view_or_value objects.
132+
///
133+
134+
template <typename View, typename Value>
135+
BSONCXX_INLINE bool operator==(const view_or_value<View, Value>& lhs,
136+
const view_or_value<View, Value>& rhs) {
137+
return lhs.view() == rhs.view();
138+
}
139+
140+
template <typename View, typename Value>
141+
BSONCXX_INLINE bool operator!=(const view_or_value<View, Value>& lhs,
142+
const view_or_value<View, Value>& rhs) {
143+
return !(lhs == rhs);
144+
}
145+
130146
///
131147
/// Equality operators for comparison with plain Views.
132148
///
@@ -151,6 +167,30 @@ BSONCXX_INLINE bool operator!=(View lhs, const view_or_value<View, Value>& rhs)
151167
return !(rhs == lhs);
152168
}
153169

170+
///
171+
/// Equality operators for comparison with plain Values.
172+
///
173+
174+
template <typename View, typename Value>
175+
BSONCXX_INLINE bool operator==(const view_or_value<View, Value>& lhs, const Value& rhs) {
176+
return lhs.view() == View(rhs);
177+
}
178+
179+
template <typename View, typename Value>
180+
BSONCXX_INLINE bool operator==(const Value& lhs, const view_or_value<View, Value>& rhs) {
181+
return rhs == lhs;
182+
}
183+
184+
template <typename View, typename Value>
185+
BSONCXX_INLINE bool operator!=(const view_or_value<View, Value>& lhs, const Value& rhs) {
186+
return !(lhs == rhs);
187+
}
188+
189+
template <typename View, typename Value>
190+
BSONCXX_INLINE bool operator!=(const Value& lhs, const view_or_value<View, Value>& rhs) {
191+
return !(rhs == lhs);
192+
}
193+
154194
BSONCXX_INLINE_NAMESPACE_END
155195
} // namespace bsoncxx
156196

0 commit comments

Comments
 (0)