MySQL 8.0.40
Source Code Documentation
Mem_root_array_YY< Element_type > Class Template Reference

A typesafe replacement for DYNAMIC_ARRAY. More...

#include <mem_root_array.h>

Inheritance diagram for Mem_root_array_YY< Element_type >:
[legend]

Public Types

typedef Element_type value_type
 Convenience typedef, same typedef name as std::vector. More...
 
typedef Element_type * iterator
 Random access iterators to value_type and const value_type. More...
 
typedef const Element_type * const_iterator
 

Public Member Functions

void init (MEM_ROOT *root)
 
void init_empty_const ()
 Initialize empty array that we aren't going to grow. More...
 
Element_type * data ()
 
const Element_type * data () const
 
Element_type & at (size_t n)
 
const Element_type & at (size_t n) const
 
Element_type & operator[] (size_t n)
 
const Element_type & operator[] (size_t n) const
 
Element_type & back ()
 
const Element_type & back () const
 
Element_type * begin ()
 Returns a pointer to the first element in the array. More...
 
const Element_type * begin () const
 
Element_type * end ()
 Returns a pointer to the past-the-end element in the array. More...
 
const Element_type * end () const
 
const_iterator cbegin () const
 Returns a constant pointer to the first element in the array. More...
 
const_iterator cend () const
 Returns a constant pointer to the past-the-end element in the array. More...
 
void clear ()
 Erases all of the elements. More...
 
void chop (const size_t pos)
 Chops the tail off the array, erasing all tail elements. More...
 
bool reserve (size_t n)
 Reserves space for array elements. More...
 
bool push_back (const Element_type &element)
 Adds a new element at the end of the array, after its current last element. More...
 
bool push_back (Element_type &&element)
 Adds a new element at the end of the array, after its current last element. More...
 
template<typename... Args>
bool emplace_back (Args &&...args)
 Constructs an element at the back of the array in-place. More...
 
bool push_front (const Element_type &element)
 Adds a new element at the beginning of the array. More...
 
bool push_front (Element_type &&element)
 Adds a new element at the front of the array. More...
 
void pop_back ()
 Removes the last element in the array, effectively reducing the container size by one. More...
 
void resize (size_t n, const value_type &val)
 Resizes the container so that it contains n elements. More...
 
void resize (size_t n)
 Same as resize(size_t, const value_type &val), but default-constructs the new elements. More...
 
iterator erase (const_iterator first, const_iterator last)
 Erase all the elements in the specified range. More...
 
iterator erase (const_iterator position)
 Removes a single element from the array. More...
 
iterator erase (size_t ix)
 Removes a single element from the array. More...
 
iterator insert (const_iterator pos, const Element_type &value)
 Insert an element at a given position. More...
 
size_t erase_value (const value_type &val)
 Removes a single element from the array by value. More...
 
iterator erase (iterator position)
 Removes a single element from the array. More...
 
size_t capacity () const
 
size_t element_size () const
 
bool empty () const
 
size_t size () const
 

Protected Attributes

MEM_ROOTm_root
 
Element_type * m_array
 
size_t m_size
 
size_t m_capacity
 

Static Private Attributes

static constexpr bool has_trivial_destructor
 Is Element_type trivially destructible? If it is, we don't destroy elements when they are removed from the array or when the array is destroyed. More...
 

Detailed Description

template<typename Element_type>
class Mem_root_array_YY< Element_type >

A typesafe replacement for DYNAMIC_ARRAY.

We use MEM_ROOT for allocating storage, rather than the C++ heap. The interface is chosen to be similar to std::vector.

Remarks
Mem_root_array_YY is constructor-less for use in the parser stack of unions. For other needs please use Mem_root_array.
Unlike DYNAMIC_ARRAY, elements are properly copied (rather than memcpy()d) if the underlying array needs to be expanded.
Unless Element_type's destructor is trivial, we destroy objects when they are removed from the array (including when the array object itself is destroyed).
Note that MEM_ROOT has no facility for reusing free space, so don't use this if multiple re-expansions are likely to happen.
Template Parameters
Element_typeThe type of the elements of the container. Elements must be copyable.

Member Typedef Documentation

◆ const_iterator

template<typename Element_type >
typedef const Element_type* Mem_root_array_YY< Element_type >::const_iterator

◆ iterator

template<typename Element_type >
typedef Element_type* Mem_root_array_YY< Element_type >::iterator

Random access iterators to value_type and const value_type.

◆ value_type

template<typename Element_type >
typedef Element_type Mem_root_array_YY< Element_type >::value_type

Convenience typedef, same typedef name as std::vector.

Member Function Documentation

◆ at() [1/2]

template<typename Element_type >
Element_type & Mem_root_array_YY< Element_type >::at ( size_t  n)
inline

◆ at() [2/2]

template<typename Element_type >
const Element_type & Mem_root_array_YY< Element_type >::at ( size_t  n) const
inline

◆ back() [1/2]

template<typename Element_type >
Element_type & Mem_root_array_YY< Element_type >::back ( )
inline

◆ back() [2/2]

template<typename Element_type >
const Element_type & Mem_root_array_YY< Element_type >::back ( ) const
inline

◆ begin() [1/2]

template<typename Element_type >
Element_type * Mem_root_array_YY< Element_type >::begin ( void  )
inline

Returns a pointer to the first element in the array.

◆ begin() [2/2]

template<typename Element_type >
const Element_type * Mem_root_array_YY< Element_type >::begin ( void  ) const
inline

◆ capacity()

template<typename Element_type >
size_t Mem_root_array_YY< Element_type >::capacity ( ) const
inline

◆ cbegin()

template<typename Element_type >
const_iterator Mem_root_array_YY< Element_type >::cbegin ( ) const
inline

Returns a constant pointer to the first element in the array.

◆ cend()

template<typename Element_type >
const_iterator Mem_root_array_YY< Element_type >::cend ( ) const
inline

Returns a constant pointer to the past-the-end element in the array.

◆ chop()

template<typename Element_type >
void Mem_root_array_YY< Element_type >::chop ( const size_t  pos)
inline

Chops the tail off the array, erasing all tail elements.

Parameters
posIndex of first element to erase.

◆ clear()

template<typename Element_type >
void Mem_root_array_YY< Element_type >::clear ( )
inline

Erases all of the elements.

◆ data() [1/2]

template<typename Element_type >
Element_type * Mem_root_array_YY< Element_type >::data ( )
inline

◆ data() [2/2]

template<typename Element_type >
const Element_type * Mem_root_array_YY< Element_type >::data ( ) const
inline

◆ element_size()

template<typename Element_type >
size_t Mem_root_array_YY< Element_type >::element_size ( ) const
inline

◆ emplace_back()

template<typename Element_type >
template<typename... Args>
bool Mem_root_array_YY< Element_type >::emplace_back ( Args &&...  args)
inline

Constructs an element at the back of the array in-place.

Parameters
argsArguments to pass to the constructor.
Returns
true if out-of-memory, false otherwise.

◆ empty()

template<typename Element_type >
bool Mem_root_array_YY< Element_type >::empty ( ) const
inline

◆ end() [1/2]

template<typename Element_type >
Element_type * Mem_root_array_YY< Element_type >::end ( void  )
inline

Returns a pointer to the past-the-end element in the array.

◆ end() [2/2]

template<typename Element_type >
const Element_type * Mem_root_array_YY< Element_type >::end ( void  ) const
inline

◆ erase() [1/4]

template<typename Element_type >
iterator Mem_root_array_YY< Element_type >::erase ( const_iterator  first,
const_iterator  last 
)
inline

Erase all the elements in the specified range.

Parameters
firstiterator that points to the first element to remove
lastiterator that points to the element after the last one to remove
Returns
an iterator to the first element after the removed range

◆ erase() [2/4]

template<typename Element_type >
iterator Mem_root_array_YY< Element_type >::erase ( const_iterator  position)
inline

Removes a single element from the array.

Parameters
positioniterator that points to the element to remove
Returns
an iterator to the first element after the removed range

◆ erase() [3/4]

template<typename Element_type >
iterator Mem_root_array_YY< Element_type >::erase ( iterator  position)
inline

Removes a single element from the array.

The removed element is destroyed. This effectively reduces the container size by one.

This is generally an inefficient operation, since we need to copy elements to fill the "hole" in the array.

We use std::copy to move objects, hence Element_type must be assignable.

◆ erase() [4/4]

template<typename Element_type >
iterator Mem_root_array_YY< Element_type >::erase ( size_t  ix)
inline

Removes a single element from the array.

Parameters
ixzero-based number of the element to remove
Returns
an iterator to the first element after the removed range

◆ erase_value()

template<typename Element_type >
size_t Mem_root_array_YY< Element_type >::erase_value ( const value_type val)
inline

Removes a single element from the array by value.

The removed element is destroyed. This effectively reduces the container size by one. Note that if there are multiple elements having the same value, only the first element is removed.

This is generally an inefficient operation, since we need to copy elements to fill the "hole" in the array.

We use std::copy to move objects, hence Element_type must be assignable.

Return values
numberof elements removed, 0 or 1.

◆ init()

template<typename Element_type >
void Mem_root_array_YY< Element_type >::init ( MEM_ROOT root)
inline

◆ init_empty_const()

template<typename Element_type >
void Mem_root_array_YY< Element_type >::init_empty_const ( )
inline

Initialize empty array that we aren't going to grow.

◆ insert()

template<typename Element_type >
iterator Mem_root_array_YY< Element_type >::insert ( const_iterator  pos,
const Element_type &  value 
)
inline

Insert an element at a given position.

Parameters
posthe new element is inserted before the element at this position
valuethe value of the new element
Returns
an iterator that points to the inserted element

◆ operator[]() [1/2]

template<typename Element_type >
Element_type & Mem_root_array_YY< Element_type >::operator[] ( size_t  n)
inline

◆ operator[]() [2/2]

template<typename Element_type >
const Element_type & Mem_root_array_YY< Element_type >::operator[] ( size_t  n) const
inline

◆ pop_back()

template<typename Element_type >
void Mem_root_array_YY< Element_type >::pop_back ( )
inline

Removes the last element in the array, effectively reducing the container size by one.

This destroys the removed element.

◆ push_back() [1/2]

template<typename Element_type >
bool Mem_root_array_YY< Element_type >::push_back ( const Element_type &  element)
inline

Adds a new element at the end of the array, after its current last element.

The content of this new element is initialized to a copy of the input argument.

Parameters
elementObject to copy.
Return values
trueif out-of-memory, false otherwise.

◆ push_back() [2/2]

template<typename Element_type >
bool Mem_root_array_YY< Element_type >::push_back ( Element_type &&  element)
inline

Adds a new element at the end of the array, after its current last element.

The content of this new element is initialized by moving the input element.

Parameters
elementObject to move.
Return values
trueif out-of-memory, false otherwise.

◆ push_front() [1/2]

template<typename Element_type >
bool Mem_root_array_YY< Element_type >::push_front ( const Element_type &  element)
inline

Adds a new element at the beginning of the array.

The content of this new element is initialized to a copy of the input argument.

Parameters
elementObject to copy.
Return values
trueif out-of-memory, false otherwise.

◆ push_front() [2/2]

template<typename Element_type >
bool Mem_root_array_YY< Element_type >::push_front ( Element_type &&  element)
inline

Adds a new element at the front of the array.

The content of this new element is initialized by moving the input element.

Parameters
elementObject to move.
Return values
trueif out-of-memory, false otherwise.

◆ reserve()

template<typename Element_type >
bool Mem_root_array_YY< Element_type >::reserve ( size_t  n)
inline

Reserves space for array elements.

Copies over existing elements, in case we are re-expanding the array.

Parameters
nnumber of elements.
Return values
trueif out-of-memory, false otherwise.

◆ resize() [1/2]

template<typename Element_type >
void Mem_root_array_YY< Element_type >::resize ( size_t  n)
inline

Same as resize(size_t, const value_type &val), but default-constructs the new elements.

This allows one to resize containers even if value_type is not copy-constructible.

◆ resize() [2/2]

template<typename Element_type >
void Mem_root_array_YY< Element_type >::resize ( size_t  n,
const value_type val 
)
inline

Resizes the container so that it contains n elements.

If n is smaller than the current container size, the content is reduced to its first n elements, removing those beyond (and destroying them).

If n is greater than the current container size, the content is expanded by inserting at the end as many elements as needed to reach a size of n. If val is specified, the new elements are initialized as copies of val, otherwise, they are value-initialized.

If n is also greater than the current container capacity, an automatic reallocation of the allocated storage space takes place.

Notice that this function changes the actual content of the container by inserting or erasing elements from it.

◆ size()

template<typename Element_type >
size_t Mem_root_array_YY< Element_type >::size ( ) const
inline

Member Data Documentation

◆ has_trivial_destructor

template<typename Element_type >
constexpr bool Mem_root_array_YY< Element_type >::has_trivial_destructor
staticconstexprprivate
Initial value:
=
std::is_trivially_destructible<Element_type>::value

Is Element_type trivially destructible? If it is, we don't destroy elements when they are removed from the array or when the array is destroyed.

◆ m_array

template<typename Element_type >
Element_type* Mem_root_array_YY< Element_type >::m_array
protected

◆ m_capacity

template<typename Element_type >
size_t Mem_root_array_YY< Element_type >::m_capacity
protected

◆ m_root

template<typename Element_type >
MEM_ROOT* Mem_root_array_YY< Element_type >::m_root
protected

◆ m_size

template<typename Element_type >
size_t Mem_root_array_YY< Element_type >::m_size
protected

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