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)},
92 _view(_value ? *_value : std::move(other._view)) {
94 other._value = stdx::nullopt;
102 _value = std::move(other._value);
103 _view = _value ? *_value : std::move(other._view);
104 other._view = View();
105 other._value = stdx::nullopt;
115 return static_cast<bool>(_value);
123 BSONCXX_INLINE
operator View()
const {
132 BSONCXX_INLINE
const View&
view()
const {
137 stdx::optional<Value> _value;
148 template <
typename View,
typename Value>
154 template <
typename View,
typename Value>
157 return !(lhs == rhs);
170 template <
typename View,
typename Value>
172 return lhs.
view() == rhs;
175 template <
typename View,
typename Value>
180 template <
typename View,
typename Value>
182 return !(lhs == rhs);
185 template <
typename View,
typename Value>
187 return !(rhs == lhs);
190 template <
typename View,
typename Value>
192 return lhs.
view() == View(rhs);
195 template <
typename View,
typename Value>
200 template <
typename View,
typename Value>
202 return !(lhs == rhs);
205 template <
typename View,
typename Value>
207 return !(rhs == lhs);
213 BSONCXX_INLINE_NAMESPACE_END
216 #include <bsoncxx/config/postlude.hpp> const View & view() const
Get a View for the type.
Definition: view_or_value.hpp:132
view_or_value(Value &&value)
Constructs a view_or_value from a Value type.
Definition: view_or_value.hpp:68
Definition: error_code.hpp:117
view_or_value()=default
Class View must be constructible from an instance of class Value.
view_or_value(View view)
Construct a view_or_value from a View.
Definition: view_or_value.hpp:60
Class representing a view-or-value variant type.
Definition: view_or_value.hpp:30
bool is_owning() const noexcept
Return whether or not this view_or_value owns an underlying Value.
Definition: view_or_value.hpp:114
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:149
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:171
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 & operator=(view_or_value &&other) noexcept
Assign to this view_or_value from a moved-in view_or_value.
Definition: view_or_value.hpp:101
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(const view_or_value &other)
Construct a view_or_value from a copied view_or_value.
Definition: view_or_value.hpp:73
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24