memory
joint_array< T > Class Template Reference

Detailed Description

template<typename T>
class foonathan::memory::joint_array< T >

A zero overhead dynamic array using joint memory.

If you use, e.g. std::vector with joint_allocator, this has a slight additional overhead. This type is joint memory aware and has no overhead.

It has a dynamic, but fixed size, it cannot grow after it has been created.

Typedefs

using value_type
 
using iterator
 
using const_iterator
 

Member Functions

template<typename JointType>
 joint_array (std::size_t size, joint_type< JointType > &j)
 
template<typename JointType>
 joint_array (std::size_t size, const value_type &val, joint_type< JointType > &j)
 
template<typename JointType>
 joint_array (std::initializer_list< value_type > ilist, joint_type< JointType > &j)
 
template<typename InIter, typename JointType, typename = decltype(*std::declval<InIter&>()++)>
 joint_array (InIter begin, InIter end, joint_type< JointType > &j)
 
 joint_array (const joint_array &)=delete
 
template<typename JointType>
 joint_array (const joint_array &other, joint_type< JointType > &j)
 
 joint_array (joint_array &&)=delete
 
template<typename JointType>
 joint_array (joint_array &&other, joint_type< JointType > &j)
 
 ~joint_array () noexcept
 
joint_arrayoperator= (const joint_array &)=delete
 
joint_arrayoperator= (joint_array &&)=delete
 
std::size_t size () const noexcept
 
bool empty () const noexcept
 
value_type & operator[] (std::size_t i) noexcept
 
const value_type & operator[] (std::size_t i) const noexcept
 
value_type * data () noexcept
 
const value_type * data () const noexcept
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 

Constructors

◆ joint_array() [1/6]

template<typename T>
template<typename JointType>
joint_array ( std::size_t size,
joint_type< JointType > & j )
Effects:
Creates with size default-constructed objects using the specified joint memory.
Throws:
out_of_fixed_memory if size is too big and anything thrown by Ts constructor. If an allocation is thrown, the memory will be released directly.

◆ joint_array() [2/6]

template<typename T>
template<typename JointType>
joint_array ( std::size_t size,
const value_type & val,
joint_type< JointType > & j )
Effects:
Creates with size copies of val using the specified joint memory.
Throws:
out_of_fixed_memory if size is too big and anything thrown by Ts constructor. If an allocation is thrown, the memory will be released directly.

◆ joint_array() [3/6]

template<typename T>
template<typename JointType>
joint_array ( std::initializer_list< value_type > ilist,
joint_type< JointType > & j )
Effects:
Creates with the copies of the objects in the initializer list using the specified joint memory.
Throws:
out_of_fixed_memory if the size is too big and anything thrown by Ts constructor. If an allocation is thrown, the memory will be released directly.

◆ joint_array() [4/6]

template<typename T>
template<typename InIter, typename JointType, typename = decltype(*std::declval<InIter&>()++)>
joint_array ( InIter begin,
InIter end,
joint_type< JointType > & j )
Effects:
Creates it by forwarding each element of the range to Ts constructor using the specified joint memory.
Throws:
out_of_fixed_memory if the size is too big and anything thrown by Ts constructor. If an allocation is thrown, the memory will be released directly.

◆ joint_array() [5/6]

template<typename T>
template<typename JointType>
joint_array ( const joint_array< T > & other,
joint_type< JointType > & j )
Effects:
Copy constructs each element from other into the storage of the specified joint memory.
Throws:
out_of_fixed_memory if the size is too big and anything thrown by Ts constructor. If an allocation is thrown, the memory will be released directly.

◆ joint_array() [6/6]

template<typename T>
template<typename JointType>
joint_array ( joint_array< T > && other,
joint_type< JointType > & j )
Effects:
Move constructs each element from other into the storage of the specified joint memory.
Throws:
out_of_fixed_memory if the size is too big and anything thrown by Ts constructor. If an allocation is thrown, the memory will be released directly.

◆ ~joint_array()

template<typename T>
~joint_array ( )
noexcept
Effects:
Destroys all objects, but does not release the storage.

Member Functions

◆ operator[]() [1/2]

template<typename T>
value_type & operator[] ( std::size_t i)
noexcept
Returns:
A reference to the ith object.
Requires:
i < size().

◆ operator[]() [2/2]

template<typename T>
const value_type & operator[] ( std::size_t i) const
noexcept
Returns:
A reference to the ith object.
Requires:
i < size().

◆ data() [1/2]

template<typename T>
value_type * data ( )
noexcept
Returns:
A pointer to the first object. It points to contiguous memory and can be used to access the objects directly.

◆ data() [2/2]

template<typename T>
const value_type * data ( ) const
noexcept
Returns:
A pointer to the first object. It points to contiguous memory and can be used to access the objects directly.

◆ begin() [1/2]

template<typename T>
iterator begin ( )
noexcept
Returns:
A random access iterator to the first element.

◆ begin() [2/2]

template<typename T>
const_iterator begin ( ) const
noexcept
Returns:
A random access iterator to the first element.

◆ end() [1/2]

template<typename T>
iterator end ( )
noexcept
Returns:
A random access iterator one past the last element.

◆ end() [2/2]

template<typename T>
const_iterator end ( ) const
noexcept
Returns:
A random access iterator one past the last element.

◆ size()

template<typename T>
std::size_t size ( ) const
noexcept
Returns:
The number of elements in the array.

◆ empty()

template<typename T>
bool empty ( ) const
noexcept
Returns:
true if the array is empty, false otherwise.