MySQL 9.6.0
Source Code Documentation
mysql::ranges::Collection_interface< Self_tp > Class Template Reference

CRTP base class to provide members of a collection based on an implementation that provides begin/end iterators. More...

#include <collection_interface.h>

Inheritance diagram for mysql::ranges::Collection_interface< Self_tp >:
[legend]

Public Member Functions

constexpr auto cbegin () const
 Return constant iterator to the beginning. More...
 
constexpr auto cend () const
 Return constant iterator to the end. More...
 
constexpr auto rbegin ()
 Return reverse iterator to the beginning. More...
 
constexpr auto rend ()
 Return reverse iterator to the end. More...
 
constexpr auto rbegin () const
 Return const reverse iterator to the beginning. More...
 
constexpr auto rend () const
 Return const reverse iterator to the end. More...
 
constexpr auto crbegin () const
 Return const reverse iterator to the beginning. More...
 
constexpr auto crend () const
 Return const reverse iterator to the end. More...
 
constexpr bool empty () const
 Return true if the range is empty, i.e., begin() == end(). More...
 
constexpr operator bool () const
 Return true if the range is non-empty, i.e., begin() != end(). More...
 
constexpr bool operator! () const
 Return true if the range is empty, i.e., begin() == end(). More...
 
constexpr auto size () const
 Return the number of elements in this view, unsigned (size_t), by computing std::ranges::distance(begin, end) More...
 
constexpr auto ssize () const
 Return the number of elements in this view, signed (ptrdiff_t). More...
 
constexpr decltype(auto) front () const
 Return the first element. More...
 
constexpr decltype(auto) back () const
 Return the last element. Enabled if we have bidirectional iterators. More...
 
constexpr decltype(auto) operator[] (std::ptrdiff_t n)
 Return the n'th element, possibly mutable. More...
 
constexpr decltype(auto) operator[] (std::ptrdiff_t n) const
 Return the n'th element, const. More...
 
constexpr auto * data ()
 Return pointer to underlying contiguous memory. More...
 
constexpr auto * data () const
 Return const pointer to underlying contiguous memory. More...
 

Private Types

using Self_t = Self_tp
 
template<class Range_t >
using Iterator_for = mysql::ranges::Range_iterator_type< Range_t >
 

Private Member Functions

Self_tself ()
 Return reference to the implementation class. More...
 
const Self_tself () const
 Return const reference to the implementation class. More...
 

Detailed Description

template<class Self_tp>
class mysql::ranges::Collection_interface< Self_tp >

CRTP base class to provide members of a collection based on an implementation that provides begin/end iterators.

The implementation must implement either begin() and end(), or begin() const and end() const (or all four). It may also override size() const and empty() const, if that is faster than the default implementations, std::ranges::distance(begin(), end()) and begin()==end().

The collection provides the following functionality:

begin(); // from the implementation
begin() const; // from the implementation
end(); // from the implementation
end() const; // from the implementation
cbegin() const; // begin() const
cend() const; // end() const
front() const; // *begin()
size() const; // (size_t)std::ranges::distance(begin(), end())
ssize() const; // (ptrdiff_t)size()
empty() const; // begin() == end()
operator!() const; // empty()
operator bool() const; // !empty()
// If the iterators are bidirectional:
rbegin(); // make_reverse_iterator(end())
rbegin() const; // make_reverse_iterator(end())
rend(); // make_reverse_iterator(begin())
rend() const; // make_reverse_iterator(begin())
rcbegin() const; // make_reverse_iterator(end())
rcend() const; // make_reverse_iterator(begin())
back() const; // *std::ranges::prev(end())
// If the iterators are random_access:
operator[](size_t n); // begin()[n]
operator[](size_t n) const; // begin()[n]
// If the iterators are contiguous:
data(); // &*begin()
data() const; // &*begin()
constexpr auto * data()
Return pointer to underlying contiguous memory.
Definition: collection_interface.h:189
constexpr auto cend() const
Return constant iterator to the end.
Definition: collection_interface.h:100
constexpr auto rend()
Return reverse iterator to the end.
Definition: collection_interface.h:108
constexpr bool operator!() const
Return true if the range is empty, i.e., begin() == end().
Definition: collection_interface.h:141
constexpr auto ssize() const
Return the number of elements in this view, signed (ptrdiff_t).
Definition: collection_interface.h:153
constexpr auto size() const
Return the number of elements in this view, unsigned (size_t), by computing std::ranges::distance(beg...
Definition: collection_interface.h:145
constexpr decltype(auto) operator[](std::ptrdiff_t n)
Return the n'th element, possibly mutable.
Definition: collection_interface.h:173
constexpr decltype(auto) back() const
Return the last element. Enabled if we have bidirectional iterators.
Definition: collection_interface.h:161
constexpr decltype(auto) front() const
Return the first element.
Definition: collection_interface.h:156
constexpr auto cbegin() const
Return constant iterator to the beginning.
Definition: collection_interface.h:97
constexpr bool empty() const
Return true if the range is empty, i.e., begin() == end().
Definition: collection_interface.h:133
constexpr auto rbegin()
Return reverse iterator to the beginning.
Definition: collection_interface.h:103
const char * begin(const char *const c)
Definition: base64.h:44
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
int n
Definition: xcom_base.cc:509

This is similar to the C++20 feature std::ranges::view_interface. However, not all compilers we build on as of 2025 had implemented view_interface even in C++20 mode. Also, cbegin and cend are C++23 features, and rbegin/rend/rcbegin/rcend/ssize are non-standard.

Despite the similarity with std::ranges::view_interface, we avoid word "view" because C++ defines that to be objects for which copy and move is cheap (https://en.cppreference.com/w/cpp/ranges/view), whereas this class is usable for anything that provides iterators, cheap-copyable or not.

Member Typedef Documentation

◆ Iterator_for

template<class Self_tp >
template<class Range_t >
using mysql::ranges::Collection_interface< Self_tp >::Iterator_for = mysql::ranges::Range_iterator_type<Range_t>
private

◆ Self_t

template<class Self_tp >
using mysql::ranges::Collection_interface< Self_tp >::Self_t = Self_tp
private

Member Function Documentation

◆ back()

template<class Self_tp >
constexpr decltype(auto) mysql::ranges::Collection_interface< Self_tp >::back ( ) const
inlineconstexpr

Return the last element. Enabled if we have bidirectional iterators.

◆ cbegin()

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::cbegin ( ) const
inlineconstexpr

Return constant iterator to the beginning.

◆ cend()

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::cend ( ) const
inlineconstexpr

Return constant iterator to the end.

◆ crbegin()

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::crbegin ( ) const
inlineconstexpr

Return const reverse iterator to the beginning.

◆ crend()

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::crend ( ) const
inlineconstexpr

Return const reverse iterator to the end.

◆ data() [1/2]

template<class Self_tp >
constexpr auto * mysql::ranges::Collection_interface< Self_tp >::data ( )
inlineconstexpr

Return pointer to underlying contiguous memory.

Enabled if we have contiguous iterators.

◆ data() [2/2]

template<class Self_tp >
constexpr auto * mysql::ranges::Collection_interface< Self_tp >::data ( ) const
inlineconstexpr

Return const pointer to underlying contiguous memory.

Enabled if we have contiguous iterators.

◆ empty()

template<class Self_tp >
constexpr bool mysql::ranges::Collection_interface< Self_tp >::empty ( ) const
inlineconstexpr

Return true if the range is empty, i.e., begin() == end().

◆ front()

template<class Self_tp >
constexpr decltype(auto) mysql::ranges::Collection_interface< Self_tp >::front ( ) const
inlineconstexpr

Return the first element.

◆ operator bool()

template<class Self_tp >
constexpr mysql::ranges::Collection_interface< Self_tp >::operator bool ( ) const
inlineexplicitconstexpr

Return true if the range is non-empty, i.e., begin() != end().

◆ operator!()

template<class Self_tp >
constexpr bool mysql::ranges::Collection_interface< Self_tp >::operator! ( ) const
inlineconstexpr

Return true if the range is empty, i.e., begin() == end().

◆ operator[]() [1/2]

template<class Self_tp >
constexpr decltype(auto) mysql::ranges::Collection_interface< Self_tp >::operator[] ( std::ptrdiff_t  n)
inlineconstexpr

Return the n'th element, possibly mutable.

Enabled if we have random access iterators.

◆ operator[]() [2/2]

template<class Self_tp >
constexpr decltype(auto) mysql::ranges::Collection_interface< Self_tp >::operator[] ( std::ptrdiff_t  n) const
inlineconstexpr

Return the n'th element, const.

Enabled if we have random access iterators.

◆ rbegin() [1/2]

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::rbegin ( )
inlineconstexpr

Return reverse iterator to the beginning.

◆ rbegin() [2/2]

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::rbegin ( ) const
inlineconstexpr

Return const reverse iterator to the beginning.

◆ rend() [1/2]

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::rend ( )
inlineconstexpr

Return reverse iterator to the end.

◆ rend() [2/2]

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::rend ( ) const
inlineconstexpr

Return const reverse iterator to the end.

◆ self() [1/2]

template<class Self_tp >
Self_t & mysql::ranges::Collection_interface< Self_tp >::self ( )
inlineprivate

Return reference to the implementation class.

◆ self() [2/2]

template<class Self_tp >
const Self_t & mysql::ranges::Collection_interface< Self_tp >::self ( ) const
inlineprivate

Return const reference to the implementation class.

◆ size()

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::size ( ) const
inlineconstexpr

Return the number of elements in this view, unsigned (size_t), by computing std::ranges::distance(begin, end)

◆ ssize()

template<class Self_tp >
constexpr auto mysql::ranges::Collection_interface< Self_tp >::ssize ( ) const
inlineconstexpr

Return the number of elements in this view, signed (ptrdiff_t).


The documentation for this class was generated from the following file: