LAL: Linear Arrangement Library 24.10.00
A library focused on algorithms on linear arrangements of graphs.
Loading...
Searching...
No Matches
lal::detail::array< T > Struct Template Reference

Wrapper of a C array for automatic deallocation of memory. More...

#include <array.hpp>

Public Member Functions

 array () noexcept=default
 Default constructor.
 
 array (std::initializer_list< T > l) noexcept
 Constructor from initializer_list.
 
 array (const std::size_t n) noexcept
 Constructor with size.
 
 array (const std::size_t n, const T &v) noexcept
 Constructor with size.
 
 array (const array &d) noexcept
 Copy constructor.
 
arrayoperator= (const array &d) noexcept
 Copy assignment operator.
 
 array (array &&d) noexcept
 Move constructor.
 
arrayoperator= (array &&d) noexcept
 Move assignment operator.
 
 ~array () noexcept
 Destructor.
 
bool operator== (const array &d) const noexcept
 Comparison of equal data arrays.
 
void clear () noexcept
 Clear the contents of the array.
 
void resize (const std::size_t new_size) noexcept
 Resize the array.
 
void resize (const std::size_t new_size, const T &v) noexcept
 Resize-initialize the array.
 
std::size_t size () const noexcept
 Size of the array.
 
T & operator[] (const std::size_t i) noexcept
 Element at position i.
 
const T & operator[] (const std::size_t i) const noexcept
 Element at position i.
 
T & first () noexcept
 Non-constant reference to the first element in the array.
 
const T & first () const noexcept
 Constant reference to the first element in the array.
 
T & back () noexcept
 Non-constant reference to the last element in the array.
 
const T & back () const noexcept
 Constant reference to the first element in the array.
 
void fill (const T &v) noexcept
 Assign the same value to every element in the data.
 
T * at (const std::size_t i) noexcept
 Pointer at a specific location of the array.
 
T const * at (const std::size_t i) const noexcept
 Pointer at a specific location of the array.
 
T * begin () noexcept
 Non-constant raw pointer to first element.
 
T * end () noexcept
 Non-constant raw pointer to last+1 element.
 
T const * begin () const noexcept
 Constant raw pointer to first element.
 
T const * end () const noexcept
 Constant raw pointer to last+1 element.
 

Protected Attributes

T * m_data = nullptr
 Pointer to the memory allocated by this array.
 
std::size_t m_size = 0
 The size of this array in number of elements.
 

Private Member Functions

void alloc_data () noexcept
 

Detailed Description

template<typename T>
struct lal::detail::array< T >

Wrapper of a C array for automatic deallocation of memory.

Automatically manage deallocation of memory via destructors.

Constructor & Destructor Documentation

◆ array() [1/2]

template<typename T >
lal::detail::array< T >::array ( const std::size_t n)
inlinenoexcept

Constructor with size.

Parameters
nSize.

◆ array() [2/2]

template<typename T >
lal::detail::array< T >::array ( const std::size_t n,
const T & v )
inlinenoexcept

Constructor with size.

Parameters
nSize.
vValue to initialize the array with.

Member Function Documentation

◆ alloc_data()

template<typename T >
void lal::detail::array< T >::alloc_data ( )
inlineprivatenoexcept

Allocate memory for array m_data only when m_size is greater than 0.

◆ at() [1/2]

template<typename T >
T const * lal::detail::array< T >::at ( const std::size_t i) const
inlinenodiscardnoexcept

Pointer at a specific location of the array.

Parameters
iPosition.
Returns
A constant raw pointer.

◆ at() [2/2]

template<typename T >
T * lal::detail::array< T >::at ( const std::size_t i)
inlinenodiscardnoexcept

Pointer at a specific location of the array.

Parameters
iPosition.
Returns
A non-constant raw pointer.

◆ operator[]() [1/2]

template<typename T >
const T & lal::detail::array< T >::operator[] ( const std::size_t i) const
inlinenodiscardnoexcept

Element at position i.

Same as std::vector::operator[]

Returns
A constant reference to the i-th element.

◆ operator[]() [2/2]

template<typename T >
T & lal::detail::array< T >::operator[] ( const std::size_t i)
inlinenodiscardnoexcept

Element at position i.

Same as std::vector::operator[]

Returns
A non-constant reference to the i-th element.

◆ resize() [1/2]

template<typename T >
void lal::detail::array< T >::resize ( const std::size_t new_size)
inlinenoexcept

Resize the array.

Does nothing if new_size is the same as the current size.

Parameters
new_sizeThe new size of the array.

◆ resize() [2/2]

template<typename T >
void lal::detail::array< T >::resize ( const std::size_t new_size,
const T & v )
inlinenoexcept

Resize-initialize the array.

Resizes and initializes the array in the same function.

Parameters
new_sizeNew size of the array.
vValue to initialize the array with.

◆ size()

template<typename T >
std::size_t lal::detail::array< T >::size ( ) const
inlinenodiscardnoexcept

Size of the array.

Imitate the vector::size() method.

Returns
The size of the array.

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