![]() |
MySQL 9.6.0
Source Code Documentation
|
Wrapper around an object that is the source for a view: 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 | Source_ref_t = std::conditional_t< owns_source, Source_t, const Source_t * > |
| Internal representation of the source. More... | |
Public Member Functions | |
| View_source ()=default | |
| Default-construct an object. More... | |
| View_source (const Source_t &source) | |
| Construct from a const reference to the 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 Source_t & | reference () const |
| Return a reference to the stored object. More... | |
| const Source_t * | operator-> () const |
| Arrow operator to access members of the source. More... | |
| auto | begin () const |
| Return begin iterator to the source. More... | |
| auto | end () const |
| Return end iterator to the source. 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 Private Member Functions | |
| static decltype(auto) | from_ref (const Source_t &object) |
Return an Source_ref_t from the given pointer, holding no object if the pointer is nullptr, and holding the pointed-to object otherwise. More... | |
Private Attributes | |
| Source_ref_t | m_source {} |
| The source. More... | |
Wrapper around an object that is the source for a view: 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 T if std::ranges::view<T>, or type const T * otherwise. It provides an API similar to std::optional, except this object is not optional.
This object is default-constructible if T is default-constructible (although the default-constructed object is in a singular state and can't be used for anything else than as the target of an assignment operation). If default-constructibility is not important, you may use Raw_view_source instead.
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::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::View_source< Source_tp, owns_source_tp >::Source_ref_t = std::conditional_t<owns_source, Source_t, const Source_t *> |
Internal representation of the source.
| using mysql::ranges::View_source< Source_tp, owns_source_tp >::Source_t = Source_tp |
|
default |
Default-construct an object.
If the source is not owned, this holds a nullptr internally, so then the only things you can do with the object is assign to it.
|
inlineexplicit |
Construct from a const reference to the source.
|
inline |
Return begin iterator to the source.
The behavior is undefined for default-constructed objects.
x.begin() is equivalent to x->begin(); this function is provided for API compatibility with Optional_view_source.
|
inline |
Return end iterator to the source.
The behavior is undefined for default-constructed non-owning objects.
x.end() is equivalent to x->end(); this function is provided for API compatibility with Optional_view_source.
|
inlinestaticprivate |
Return an Source_ref_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 for default-constructed objects.
|
inline |
Arrow operator to access members of the source.
The behavior is undefined for default-constructed objects.
o.begin() and o.end() instead of o->begin() and o->end().
|
inline |
Return a reference to the stored object.
The behavior is undefined for default-constructed objects. 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.