utilities  0.0
Classes | Public Types | Public Member Functions | Friends | List of all members
molpro::array< T > Class Template Reference

A template for a container class like std::array<T> but with the following features. More...

#include <memory.h>

Classes

class  MyIterator
 

Public Types

using Iterator = MyIterator< false >
 
using ConstIterator = MyIterator< true >
 
typedef Iterator iterator
 
typedef ConstIterator const_iterator
 
using reverse_iterator = std::reverse_iterator< Iterator >
 
using const_reverse_iterator = std::reverse_iterator< ConstIterator >
 

Public Member Functions

 array (size_t const length=0)
 Construct an array of type T with managed storage. More...
 
 array (size_t const length, const T &value)
 Construct an array of type T with managed storage. More...
 
template<class InputIterator >
 array (InputIterator first, InputIterator last)
 Construct an array of type T with managed storage. More...
 
 array (std::initializer_list< T > il)
 Construct a vector of type T with managed storage. More...
 
 array (T *const buffer, size_t const length)
 Construct an array of type T by attaching to an existing buffer. More...
 
template<std::size_t N>
 array (std::array< T, N > &array)
 Construct an array of type T by attaching to an existing buffer. More...
 
 array (std::vector< T > &array)
 Construct an array of type T by attaching to an existing buffer. More...
 
 array (const array< T > &source)
 array<T> Copy constructor More...
 
array< T > & operator= (const array< T > &copy)
 Copy assignment operator. More...
 
virtual ~array ()
 
T & operator[] (size_t n)
 
const T & operator[] (size_t n) const
 
template<class InputIterator >
void assign (InputIterator first, InputIterator last)
 Assign new contents to the array, replacing its current contents. More...
 
void assign (const T &value)
 Assign new contents to the array, replacing its current contents. More...
 
void assign (size_t n, const T &value)
 Assign new contents to the array, replacing its current contents. More...
 
void assign (std::initializer_list< T > il)
 Assign new contents to the array, replacing its current contents. More...
 
T & at (size_t n)
 
const T & at (size_t n) const
 
T & back () noexcept
 
const T & back () const noexcept
 
bool empty () const noexcept
 
T & front () noexcept
 
const T & front () const noexcept
 
T * data () noexcept
 
const T * data () const noexcept
 
size_t max_size () const noexcept
 
size_t size () const noexcept
 
void swap (array< T > &x)
 Exchange the content of the container by the content of x, which is another object of the same type. More...
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
reverse_iterator rend () noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crend () const noexcept
 
std::string str (int verbosity=1, unsigned int columns=UINT_MAX) const
 Generate a printable representation of the object. More...
 

Friends

void swap (array< T > &a, array< T > &b)
 

Detailed Description

template<typename T = double>
class molpro::array< T >

A template for a container class like std::array<T> but with the following features.

Elements of the array are not constructed at allocation time, for reasons of efficiency, leading to a construction time that is approximately independent of the array size.

Template Parameters
TType of the elements of the array.

Example:

#include "memory.h"
int main() {
memory_initialize(40); // bytes
{
for (size_t i=0; i<arr.size(); i++) arr[i]=100*i;
for (molpro::array<>::iterator el=arr.begin(); el!=arr.end(); el++)
std::cout << "array element "<<*el<<std::endl;
} // arr will release its buffer and be destroyed on going out of scope
int v[]={1,2,3,4,5,6};
{
for (molpro::array<double>::iterator el=arr.begin(); el!=arr.end(); el++)
*el=99;
} // arr is destroyed, but (modified) v survives
std::cout << v[0] << std::endl;
return 0; }
Definition: memory.h:863
A template for a container class like std::array<T> but with the following features.
Definition: memory.h:666
size_t memory_initialize(char *buffer, size_t max)
Definition: memory.h:104

Member Typedef Documentation

◆ const_iterator

template<typename T = double>
typedef ConstIterator molpro::array< T >::const_iterator

◆ const_reverse_iterator

template<typename T = double>
using molpro::array< T >::const_reverse_iterator = std::reverse_iterator<ConstIterator>

◆ ConstIterator

template<typename T = double>
using molpro::array< T >::ConstIterator = MyIterator<true>

◆ Iterator

template<typename T = double>
using molpro::array< T >::Iterator = MyIterator<false>

◆ iterator

template<typename T = double>
typedef Iterator molpro::array< T >::iterator

◆ reverse_iterator

template<typename T = double>
using molpro::array< T >::reverse_iterator = std::reverse_iterator<Iterator>

Constructor & Destructor Documentation

◆ array() [1/8]

template<typename T = double>
molpro::array< T >::array ( size_t const  length = 0)
inlineexplicit

Construct an array of type T with managed storage.

Parameters
lengthThe number of elements of buffer.

◆ array() [2/8]

template<typename T = double>
molpro::array< T >::array ( size_t const  length,
const T &  value 
)
inline

Construct an array of type T with managed storage.

Parameters
lengthThe number of elements of buffer.
valueThe value to assign to all elements of the buffer.

◆ array() [3/8]

template<typename T = double>
template<class InputIterator >
molpro::array< T >::array ( InputIterator  first,
InputIterator  last 
)
inline

Construct an array of type T with managed storage.

Parameters
firstStarting iterator of array to copy
lastEnding iterator of array to copy

◆ array() [4/8]

template<typename T = double>
molpro::array< T >::array ( std::initializer_list< T >  il)
inline

Construct a vector of type T with managed storage.

Parameters
ilInitializer list

◆ array() [5/8]

template<typename T = double>
molpro::array< T >::array ( T *const  buffer,
size_t const  length 
)
inline

Construct an array of type T by attaching to an existing buffer.

Parameters
bufferPointer to an existing array of type T.
lengthThe number of elements of buffer.

◆ array() [6/8]

template<typename T = double>
template<std::size_t N>
molpro::array< T >::array ( std::array< T, N > &  array)
inlineexplicit

Construct an array of type T by attaching to an existing buffer.

Parameters
arrayExisting std::array of type T whose buffer will be used.

◆ array() [7/8]

template<typename T = double>
molpro::array< T >::array ( std::vector< T > &  array)
inlineexplicit

Construct an array of type T by attaching to an existing buffer.

Parameters
arrayExisting std::vector of type T whose buffer will be used. Any subsequent external reallocation of array will cause chaos.

◆ array() [8/8]

template<typename T = double>
molpro::array< T >::array ( const array< T > &  source)
inline

array<T> Copy constructor

Parameters
sourceAn existing object. An element-by-element copy is made, i.e. the data buffer is allocated then copied from source.

◆ ~array()

template<typename T = double>
virtual molpro::array< T >::~array ( )
inlinevirtual

Member Function Documentation

◆ assign() [1/4]

template<typename T = double>
void molpro::array< T >::assign ( const T &  value)
inline

Assign new contents to the array, replacing its current contents.

Parameters
valueThe value to set all elements of the array to.

◆ assign() [2/4]

template<typename T = double>
template<class InputIterator >
void molpro::array< T >::assign ( InputIterator  first,
InputIterator  last 
)
inline

Assign new contents to the array, replacing its current contents.

Parameters
firstStarting iterator of array to copy
lastEnding iterator of array to copy

◆ assign() [3/4]

template<typename T = double>
void molpro::array< T >::assign ( size_t  n,
const T &  value 
)
inline

Assign new contents to the array, replacing its current contents.

Parameters
nThe new number of elements
valueThe value to set all elements of the array to.

◆ assign() [4/4]

template<typename T = double>
void molpro::array< T >::assign ( std::initializer_list< T >  il)
inline

Assign new contents to the array, replacing its current contents.

Parameters
ilAn initializer. The array is resized to match the length of il.

◆ at() [1/2]

template<typename T = double>
T& molpro::array< T >::at ( size_t  n)
inline

◆ at() [2/2]

template<typename T = double>
const T& molpro::array< T >::at ( size_t  n) const
inline

◆ back() [1/2]

template<typename T = double>
const T& molpro::array< T >::back ( ) const
inlinenoexcept

◆ back() [2/2]

template<typename T = double>
T& molpro::array< T >::back ( )
inlinenoexcept

◆ begin() [1/2]

template<typename T = double>
const_iterator molpro::array< T >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<typename T = double>
iterator molpro::array< T >::begin ( )
inlinenoexcept

◆ cbegin()

template<typename T = double>
const_iterator molpro::array< T >::cbegin ( ) const
inlinenoexcept

◆ cend()

template<typename T = double>
const_iterator molpro::array< T >::cend ( ) const
inlinenoexcept

◆ crbegin()

template<typename T = double>
const_reverse_iterator molpro::array< T >::crbegin ( ) const
inlinenoexcept

◆ crend()

template<typename T = double>
const_reverse_iterator molpro::array< T >::crend ( ) const
inlinenoexcept

◆ data() [1/2]

template<typename T = double>
const T* molpro::array< T >::data ( ) const
inlinenoexcept

◆ data() [2/2]

template<typename T = double>
T* molpro::array< T >::data ( )
inlinenoexcept

◆ empty()

template<typename T = double>
bool molpro::array< T >::empty ( ) const
inlinenoexcept

◆ end() [1/2]

template<typename T = double>
const_iterator molpro::array< T >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<typename T = double>
iterator molpro::array< T >::end ( )
inlinenoexcept

◆ front() [1/2]

template<typename T = double>
const T& molpro::array< T >::front ( ) const
inlinenoexcept

◆ front() [2/2]

template<typename T = double>
T& molpro::array< T >::front ( )
inlinenoexcept

◆ max_size()

template<typename T = double>
size_t molpro::array< T >::max_size ( ) const
inlinenoexcept

◆ operator=()

template<typename T = double>
array<T>& molpro::array< T >::operator= ( const array< T > &  copy)
inline

Copy assignment operator.

◆ operator[]() [1/2]

template<typename T = double>
T& molpro::array< T >::operator[] ( size_t  n)
inline

◆ operator[]() [2/2]

template<typename T = double>
const T& molpro::array< T >::operator[] ( size_t  n) const
inline

◆ rbegin() [1/2]

template<typename T = double>
const_reverse_iterator molpro::array< T >::rbegin ( ) const
inlinenoexcept

◆ rbegin() [2/2]

template<typename T = double>
reverse_iterator molpro::array< T >::rbegin ( )
inlinenoexcept

◆ rend() [1/2]

template<typename T = double>
const_reverse_iterator molpro::array< T >::rend ( ) const
inlinenoexcept

◆ rend() [2/2]

template<typename T = double>
reverse_iterator molpro::array< T >::rend ( )
inlinenoexcept

◆ size()

template<typename T = double>
size_t molpro::array< T >::size ( ) const
inlinenoexcept

◆ str()

template<typename T = double>
std::string molpro::array< T >::str ( int  verbosity = 1,
unsigned int  columns = UINT_MAX 
) const
inline

Generate a printable representation of the object.

Parameters
verbosityIf zero, express only the length of the object; otherwise, its elements.
columnsIf given, a line wrap will be generated every columns values.
Returns

◆ swap()

template<typename T = double>
void molpro::array< T >::swap ( array< T > &  x)
inline

Exchange the content of the container by the content of x, which is another object of the same type.

Parameters
xAnother array of the same type.

Friends And Related Function Documentation

◆ swap

template<typename T = double>
void swap ( array< T > &  a,
array< T > &  b 
)
friend

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