Polymake Template Library (PTL): pm::Array< E, SharedParams > Class Template Reference
Polymake Template Library (PTL)  4.2
pm::Array< E, SharedParams > Class Template Reference

Container class with constant time random access. More...

Inherits pm::plain_array< Top, E >.

Collaboration diagram for pm::Array< E, SharedParams >:

Public Member Functions

 Array ()
 Create an empty array.
 
 Array (Int n)
 Create an array with n elements, initialized with the default constructor.
 
template<typename E2 >
 Array (Int n, const E2 &init, std::enable_if_t< can_initialize< E2, E >::value, std::nullptr_t >=nullptr)
 Create an array with n elements, initialized with the same value.
 
template<typename Iterator >
 Array (Int n, Iterator &&src, std::enable_if_t< assess_iterator_value< Iterator, can_initialize, E >::value, std::nullptr_t >=nullptr)
 Create an array with n, initialized from a data sequence.
 
Int size () const
 number of elements
 
void clear ()
 truncate to zero size
 
void resize (Int n)
 
void resize (Int n, const E &x)
 Same as above, with explicit element construction.
 
template<typename Iterator , typename = std::enable_if_t<assess_iterator_value<Iterator, can_initialize, E>::value>>
Arrayappend (Int n, Iterator &&src)
 Keep the old elements, add n new elements at the tail, assign them values from the data sequence.
 
template<typename... Containers, typename = std::enable_if_t<isomorphic_to_container_of<mlist<Containers...>, E, allow_conversion>::value, void>>
Arrayappend (const Containers &... src)
 Add new elements at the tail.
 
template<typename E2 >
std::enable_if_t< std::is_convertible< E2, E >::value > fill (const E2 &x)
 Assign x to all elements.
 
void swap (Array &a)
 Swap the contents of two arrays in a most efficient way.
 

Protected Attributes

shared_array< E, typename mtagged_list_add_default< typename mlist_wrap< SharedParams... >::type, AliasHandlerTag< shared_alias_handler > >::type > data
 data array
 

Detailed Description

template<typename E, typename... SharedParams>
class pm::Array< E, SharedParams >

Container class with constant time random access.

Offers practically the same as std::vector. The only significant differences are that the data array is attached via a smart pointer with reference counting, and the set of operations changing the size of the array is reduced to the minimum.

Array inplements STL's "Random Access Container" interface. The element index in the random access method should lie in the valid range, the array does not grow implicitly.

Member Function Documentation

◆ resize()

template<typename E , typename... SharedParams>
void pm::Array< E, SharedParams >::resize ( Int  n)
inline

If n is less than the current array length, delete the trailing elements. If greater, add new elements initialized with the default constructor resp. the copies of the given value x.

Unlike std::vector, Array never allocates extra stock storage. Each resize operation causes the data area reallocation.


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