MongoDB C++ Driver
mongocxx-3.7.0
|
17 #include <type_traits>
19 #include <bsoncxx/stdx/optional.hpp>
21 #include <bsoncxx/config/prelude.hpp>
24 BSONCXX_INLINE_NAMESPACE_BEGIN
29 template <
typename View,
typename Value>
32 using view_type = View;
33 using value_type = Value;
38 static_assert(std::is_constructible<View, Value>::value,
39 "View type must be constructible from a Value");
44 static_assert(std::is_default_constructible<View>::value,
45 "View type must be default constructible");
68 BSONCXX_INLINE
view_or_value(Value&& value) : _value(std::move(value)), _view(*_value) {}
74 : _value(other._value), _view(_value ? *_value : other._view) {}
80 _value = other._value;
81 _view = _value ? *_value : other._view;
91 : _value{std::move(other._value)}, _view(_value ? *_value : std::move(other._view)) {
93 other._value = stdx::nullopt;
101 _value = std::move(other._value);
102 _view = _value ? *_value : std::move(other._view);
103 other._view = View();
104 other._value = stdx::nullopt;
114 return static_cast<bool>(_value);
122 BSONCXX_INLINE
operator View()
const {
131 BSONCXX_INLINE
const View&
view()
const {
136 stdx::optional<Value> _value;
147 template <
typename View,
typename Value>
153 template <
typename View,
typename Value>
156 return !(lhs == rhs);
169 template <
typename View,
typename Value>
171 return lhs.
view() == rhs;
174 template <
typename View,
typename Value>
179 template <
typename View,
typename Value>
180 BSONCXX_INLINE
bool operator!=(
const view_or_value<View, Value>& lhs, View rhs) {
181 return !(lhs == rhs);
184 template <
typename View,
typename Value>
185 BSONCXX_INLINE
bool operator!=(View lhs,
const view_or_value<View, Value>& rhs) {
186 return !(rhs == lhs);
189 template <
typename View,
typename Value>
190 BSONCXX_INLINE
bool operator==(
const view_or_value<View, Value>& lhs,
const Value& rhs) {
191 return lhs.view() == View(rhs);
194 template <
typename View,
typename Value>
195 BSONCXX_INLINE
bool operator==(
const Value& lhs,
const view_or_value<View, Value>& rhs) {
199 template <
typename View,
typename Value>
200 BSONCXX_INLINE
bool operator!=(
const view_or_value<View, Value>& lhs,
const Value& rhs) {
201 return !(lhs == rhs);
204 template <
typename View,
typename Value>
205 BSONCXX_INLINE
bool operator!=(
const Value& lhs,
const view_or_value<View, Value>& rhs) {
206 return !(rhs == lhs);
212 BSONCXX_INLINE_NAMESPACE_END
215 #include <bsoncxx/config/postlude.hpp>
view_or_value()=default
Class View must be constructible from an instance of class Value.
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
Class representing a view-or-value variant type.
Definition: view_or_value.hpp:30
bool operator==(const view_or_value< View, Value > &lhs, const view_or_value< View, Value > &rhs)
Compare view_or_value objects for (in)-equality.
Definition: view_or_value.hpp:148
const View & view() const
Get a View for the type.
Definition: view_or_value.hpp:131
bool is_owning() const noexcept
Return whether or not this view_or_value owns an underlying Value.
Definition: view_or_value.hpp:113
view_or_value(const view_or_value &other)
Construct a view_or_value from a copied view_or_value.
Definition: view_or_value.hpp:73
bool operator==(const view_or_value< View, Value > &lhs, View rhs)
Mixed (in)-equality operators for view_or_value against View or Value types.
Definition: view_or_value.hpp:170
view_or_value(View view)
Construct a view_or_value from a View.
Definition: view_or_value.hpp:60
view_or_value(view_or_value &&other) noexcept
Construct a view_or_value from a moved-in view_or_value.
Definition: view_or_value.hpp:90
view_or_value(Value &&value)
Constructs a view_or_value from a Value type.
Definition: view_or_value.hpp:68
view_or_value & operator=(const view_or_value &other)
Assign to this view_or_value from a copied view_or_value.
Definition: view_or_value.hpp:79
view_or_value & operator=(view_or_value &&other) noexcept
Assign to this view_or_value from a moved-in view_or_value.
Definition: view_or_value.hpp:100