![]() |
MySQL 9.6.0
Source Code Documentation
|
std::optional-like wrapper around an object that is the source for a view: this may hold an object or not; and the wrapped object is owned by this object if the wrapped object's type satisfies std::ranges::view, and not owned otherwise.
More...
#include <view_sources.h>
Public Types | |
| using | Source_t = Source_tp |
| using | Raw_source_t = Raw_view_source< Source_t, owns_source > |
Source_t if owns_source, otherwise Source_t &. More... | |
| using | Optional_source_t = std::conditional_t< owns_source, std::optional< Source_t >, const Source_t * > |
| Internal representation of the source. More... | |
Public Member Functions | |
| Optional_view_source ()=default | |
| Construct an objec that does not hold a source. More... | |
| Optional_view_source (const Source_t &source) | |
| Construct from a const reference to the source. More... | |
| Optional_view_source (const Source_t *source) | |
| Construct from a const pointer to the source. More... | |
| bool | has_object () const |
| Return true if this object holds a source. More... | |
| const Raw_source_t & | get () const |
| Return a copy of the stored object if it is owned; otherwise a reference to it. More... | |
| const Raw_source_t & | reference () const |
| Return a reference to the stored object. More... | |
| const Source_t * | pointer () const |
| Return a pointer to the source if there is one, or nullptr otherwise. More... | |
| const Source_t * | operator-> () const |
| Arrow operator to access members of the source. More... | |
| auto | begin () const |
| Return a valid begin iterator, even if !has_object(). More... | |
| auto | end () const |
| Return a valid end iterator, even if !has_object(). More... | |
Static Public Attributes | |
| static constexpr bool | owns_source = owns_source_tp |
| True if this object owns a copy of its source; false if it holds a reference to its source. More... | |
Static Protected Member Functions | |
| static auto | null_iterator () |
Static Private Member Functions | |
| static decltype(auto) | from_ptr (const Source_t *object) |
Return an Optional_source_t from the given pointer, holding no object if the pointer is nullptr, and holding the pointed-to object otherwise. More... | |
Private Attributes | |
| Optional_source_t | m_source {} |
| The source. More... | |
std::optional-like wrapper around an object that is the source for a view: this may hold an object or not; and the wrapped object is owned by this object if the wrapped object's type satisfies std::ranges::view, and not owned otherwise.
This is meant to be used by member variables of the view class, or the view's iterator class, that need to reference the source.
This intends to prevent dangling references by enforcing the following rule:
"Views and their iterators shall represent sources that are views by-value, and sources that are containers by-reference."
For full justification, see readme.md.
Internally, this class stores a source of type T using a member variable of type std::optional<T> if std::ranges::view<T>, or type const T * otherwise. It provides an API similar to std::optional.
Note that types need to be declared explicitly as views, using either std::ranges::view_base or std::ranges::enable_range.
| Source_tp | The source type. |
| owns_source_tp | Determines if the object owns its source. By default, this is deduced from std::ranges::view<Source_tp>. |
| using mysql::ranges::Optional_view_source< Source_tp, owns_source_tp >::Optional_source_t = std::conditional_t<owns_source, std::optional<Source_t>, const Source_t *> |
Internal representation of the source.
| using mysql::ranges::Optional_view_source< Source_tp, owns_source_tp >::Raw_source_t = Raw_view_source<Source_t, owns_source> |
Source_t if owns_source, otherwise Source_t &.
| using mysql::ranges::Optional_view_source< Source_tp, owns_source_tp >::Source_t = Source_tp |
|
default |
Construct an objec that does not hold a source.
|
inlineexplicit |
Construct from a const reference to the source.
|
inlineexplicit |
Construct from a const pointer to the source.
The source may be nullptr, in which case this object will not hold any sourcd.
|
inline |
Return a valid begin iterator, even if !has_object().
If !has_object(), it is defined that the source is an empty range, so then this function returns the end iterator to a default-constructed source.
This requires std::ranges::common_range<Source_t>, i.e., begin() and end() must return the same type.
|
inline |
Return a valid end iterator, even if !has_object().
If !has_object(), this returns the end iterator to a default-constructed source.
|
inlinestaticprivate |
Return an Optional_source_t from the given pointer, holding no object if the pointer is nullptr, and holding the pointed-to object otherwise.
|
inline |
Return a copy of the stored object if it is owned; otherwise a reference to it.
The behavior is undefined if !has_object().
|
inline |
Return true if this object holds a source.
|
inlinestaticprotected |
|
inline |
Arrow operator to access members of the source.
The behavior is undefined if !has_object().
o.begin() and o.end() instead of o->begin() and o->end().
|
inline |
Return a pointer to the source if there is one, or nullptr otherwise.
Note that the pointer is only valid as long as this object exists.
|
inline |
Return a reference to the stored object.
The behavior is undefined if !has_object(). Note that the reference is only valid as long as this object exists.
|
private |
The source.
|
staticconstexpr |
True if this object owns a copy of its source; false if it holds a reference to its source.