Simbody
3.6
|
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library (STL) std::vector<T> class, but with some important advantages in performance, and functionality, and binary compatibility. More...
Public Types | |
Typedefs | |
Types required of STL containers, plus index_type which is an extension, and packed_size_type which is an implementation detail. | |
typedef T | value_type |
typedef X | index_type |
typedef T * | pointer |
typedef const T * | const_pointer |
typedef T & | reference |
typedef const T & | const_reference |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef std::reverse_iterator< iterator > | reverse_iterator |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
typedef ArrayIndexTraits< X >::size_type | size_type |
typedef ArrayIndexTraits< X >::difference_type | difference_type |
typedef ArrayIndexPackType< size_type >::packed_size_type | packed_size_type |
Public Types inherited from SimTK::ArrayView_< T, X > | |
typedef T | value_type |
typedef X | index_type |
typedef T * | pointer |
typedef const T * | const_pointer |
typedef T & | reference |
typedef const T & | const_reference |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef std::reverse_iterator< iterator > | reverse_iterator |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
typedef ArrayIndexTraits< X >::size_type | size_type |
typedef ArrayIndexTraits< X >::difference_type | difference_type |
typedef ArrayIndexPackType< size_type >::packed_size_type | packed_size_type |
Public Types inherited from SimTK::ArrayViewConst_< T, X > | |
typedef T | value_type |
The type of object stored in this container. More... | |
typedef X | index_type |
The index type (an extension). More... | |
typedef T * | pointer |
A writable pointer to a value_type. More... | |
typedef const T * | const_pointer |
A const pointer to a value_type. More... | |
typedef T & | reference |
A writable value_type reference. More... | |
typedef const T & | const_reference |
A const value_type reference. More... | |
typedef T * | iterator |
A writable iterator for this container (same as pointer here). More... | |
typedef const T * | const_iterator |
A const iterator for this container (same as const_pointer here). More... | |
typedef std::reverse_iterator< iterator > | reverse_iterator |
A writable reverse iterator for this container. More... | |
typedef std::reverse_iterator< const_iterator > | const_reverse_iterator |
A const reverse iterator for this container. More... | |
typedef ArrayIndexTraits< X >::size_type | size_type |
An integral type suitable for all indices and sizes for this array. More... | |
typedef ArrayIndexTraits< X >::difference_type | difference_type |
A signed integral type that can represent the difference between any two legitimate index values for this array. More... | |
typedef ArrayIndexPackType< size_type >::packed_size_type | packed_size_type |
The integral type we actually use internally to store size_type values. More... | |
Public Member Functions | |
Construction, conversion and destruction | |
A variety of constructors are provided for this class, including all those required by the C++ standard for std::vector implementations, plus additional ones providing smooth conversions between Array_<T> and std::vector<T> objects. | |
Array_ () | |
Default constructor allocates no heap space and is very fast. More... | |
Array_ (size_type n) | |
Construct an array containing n default-constructed elements. More... | |
Array_ (size_type n, const T &initVal) | |
Construct an array containing n elements each set to a copy of the given initial value. More... | |
template<class InputIter > | |
Array_ (const InputIter &first, const InputIter &last1) | |
Construct an Array_<T> from a range [first,last1) of values identified by a pair of iterators. More... | |
template<class T2 > | |
Array_ (const T2 *first, const T2 *last1) | |
Construct an Array_<T> from a range [first,last1) of values identified by a pair of ordinary pointers to elements of type T2 (where T2 might be the same as T but doesn't have to be). More... | |
Array_ (std::initializer_list< T > ilist) | |
Construct an Array_<T> from an std::initializer_list whose elements were convertible to type T, provided that the number of source elements does not exceed the array's max_size(). More... | |
template<class T2 > | |
Array_ (const std::vector< T2 > &v) | |
Construct an Array_<T> by copying from an std::vector<T2>, where T2 may be the same type as T but doesn't have to be. More... | |
Array_ (const Array_ &src) | |
Copy constructor allocates exactly as much memory as is in use in the source (not its capacity) and copy constructs the elements so that T's copy constructor will be called exactly src.size() times. More... | |
Array_ (Array_ &&src) | |
Move constructor swaps in the source and leaves the source default constructed. More... | |
template<class T2 , class X2 > | |
Array_ (const Array_< T2, X2 > &src) | |
Construct this Array_<T,X> as a copy of another Array_<T2,X2> where T2!=T or X2!=X. More... | |
Array_ (T *first, const T *last1, const DontCopy &) | |
Construct an Array_<T> by referencing (sharing) a given range of data [first,last1), without copying that data; better to use the corresponding ArrayView_<T> constructor if you can. More... | |
template<class A > | |
Array_ (std::vector< T, A > &v, const DontCopy &) | |
Construct an Array_<T> by referencing (sharing) the data in an std::vector<T>, without copying the data; better to use the ArrayView_<T> constructor instead if you can. More... | |
~Array_ () | |
The destructor performs a deallocate() operation which may result in element destruction and freeing of heap space; see deallocate() for more information. More... | |
Array_ & | deallocate () |
Empty this array of its contents, returning the array to its default-constructed, all-zero state. More... | |
Assignment methods and operators | |
These methods put new data values in an existing array, but the meaning of assignment is subtly different for resizeable (owner) arrays and fixed (non-owner) arrays. The standard std::vector type is always an owner so the non-owner description here is an extension applying only to Array_. For the normal case of resizeable arrays, assignment does not have an elementwise definition because the source will typically have a different number of elements than the array's current size. So regardless of the actual numbers, assignment in the resizeable case is defined as it is for std::vector: first clear the array by erasing (destructing) all the current elements in the array, then reserve sufficient heap space to hold a copy of the source, then use appropriate constructors of type T (most commonly T's copy constructor T(T)) to initialize each element to be a copy of the corresponding source element. T's assignment operators are never used in this case. For fixed arrays, the source must have the same number of elements as are currently in the array and the meaning is conventional elementwise assignment; that is, an appropriate assignment operator of type T (most commonly T's copy assignment operator T=T) is used to change the value of each existing element. So there are different requirements on the value type T for owner and non-owner assignments to type T2: for owner assignment T must have a constructor T(T2) available; for non-owner assignment, T must have an assignment operator T=T2 available.
| |
void | assign (size_type n, const T &fillValue) |
Set this array to be n copies of the supplied fillValue. More... | |
void | fill (const T &fillValue) |
Assign all current elements of the array to the same fillValue. More... | |
template<class T2 > | |
void | assign (const T2 *first, const T2 *last1) |
Assign to this array to to make it a copy of the elements in range [first,last1) given by ordinary pointers. More... | |
template<class Iter > | |
void | assign (const Iter &first, const Iter &last1) |
Assign this array from a range [first,last1) given by non-pointer iterators. More... | |
Array_ & | operator= (const Array_ &src) |
Copy assignment operator destructs the current contents of this array and then makes it a copy of the source array by repeated calls to the element type's copy constructor. More... | |
Array_ & | operator= (Array_ &&src) |
Move assignment operator swaps the contents of this Array_ with the source Array_. More... | |
template<class T2 , class X2 > | |
Array_ & | operator= (const Array_< T2, X2 > &src) |
This is assignment from a source array whose element type T2 and/or index type X2 are different from this array's T and X. More... | |
template<class T2 , class A > | |
Array_ & | operator= (const std::vector< T2, A > &src) |
This is assignment from a source std::vector<T2>. More... | |
void | swap (Array_ &other) |
This is a specialized algorithm providing constant time exchange of data with another array that has identical element and index types. More... | |
Array_ & | adoptData (T *newData, size_type dataSize, size_type dataCapacity) |
This dangerous extension allows you to supply your own already-allocated heap space for use by this array, which then becomes the owner of the supplied heap space. More... | |
Array_ & | adoptData (T *newData, size_type dataSize) |
A variant of adoptData() that assumes the capacity is the same as the current size. More... | |
Array_ & | shareData (T *newData, size_type dataSize) |
This dangerous extension allows you to make this array handle refer to someone else's data without copying it. More... | |
Array_ & | shareData (T *first, const T *last1) |
Same as shareData(data,size) but uses a pointer range [first,last1) to identify the data to be referenced. More... | |
Size and capacity | |
These methods examine and alter the number of elements (size) or the amount of allocated heap space (capacity) or both. | |
size_type | size () const |
Return the current number of elements stored in this array. More... | |
size_type | max_size () const |
Return the maximum allowable size for this array. More... | |
bool | empty () const |
Return true if there are no elements currently stored in this array. More... | |
size_type | capacity () const |
Return the number of elements this array can currently hold without requiring reallocation. More... | |
void | resize (size_type n) |
Change the size of this Array, preserving all the elements that will still fit, and default constructing any new elements that are added. More... | |
void | resize (size_type n, const T &initVal) |
Change the size of this array, preserving all the elements that will still fit, and initializing any new elements that are added by repeatedly copy- constructing from the supplied value. More... | |
void | reserve (size_type n) |
Ensure that this array has enough allocated capacity to hold the indicated number of elements. More... | |
void | shrink_to_fit () |
Request that the capacity of this array be reduced to the minimum necessary to hold the number of elements currently in use. More... | |
size_type | allocated () const |
Return the amount of heap space owned by this array; this is the same as capacity() for owner arrays but is zero for non-owners. More... | |
bool | isOwner () const |
Does this array own the data to which it refers? If not, it can't be resized, and the destructor will not free any heap space nor call any element destructors. More... | |
Iterators | |
These methods deal in iterators, which are STL generalized pointers. For this class, iterators are just ordinary pointers to T, and you may depend on that. By necessity, reverse iterators can't be just pointers; however, they contain an ordinary iterator (i.e. a pointer) that can be obtained by calling the reverse iterator's base() method. | |
const T * | cbegin () const |
Return a const pointer to the first element of this array if any, otherwise cend(), which may be null (0) in that case but does not have to be. More... | |
const T * | begin () const |
The const version of begin() is the same as cbegin(). More... | |
T * | begin () |
Return a writable pointer to the first element of this array if any, otherwise end(). More... | |
const T * | cend () const |
Return a const pointer to what would be the element just after the last one in the array; this may be null (0) if there are no elements but doesn't have to be. More... | |
const T * | end () const |
The const version of end() is the same as cend(). More... | |
T * | end () |
Return a writable pointer to what would be the element just after the last one in this array. More... | |
const_reverse_iterator | crbegin () const |
Return a const reverse iterator pointing to the last element in the array or crend() if the array is empty. More... | |
const_reverse_iterator | rbegin () const |
The const version of rbegin() is the same as crbegin(). More... | |
reverse_iterator | rbegin () |
Return a writable reverse iterator pointing to the last element in the array or rend() if the array is empty. More... | |
const_reverse_iterator | crend () const |
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array. More... | |
const_reverse_iterator | rend () const |
The const version of rend() is the same as crend(). More... | |
reverse_iterator | rend () |
Return a writable past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array. More... | |
const T * | cdata () const |
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) if the array is empty. More... | |
const T * | data () const |
The const version of the data() method is identical to cdata(). More... | |
T * | data () |
Return a writable pointer to the first allocated element of the array, or a null pointer if no space is associated with the array. More... | |
Element access | |
These methods provide read and write access to individual elements, or groups of elements, that are currently present in the array. | |
const T & | operator[] (index_type i) const |
Select an element by its index, returning a const reference. More... | |
T & | operator[] (index_type i) |
Select an element by its index, returning a writable (lvalue) reference. More... | |
const T & | at (index_type i) const |
Same as operator[] but always range-checked, even in a Release build. More... | |
T & | at (index_type i) |
Same as operator[] but always range-checked, even in a Release build. More... | |
const T & | getElt (index_type i) const |
Same as the const form of operator[]; exists to provide a non-operator method for element access in case that's needed. More... | |
T & | updElt (index_type i) |
Same as the non-const form of operator[]; exists to provide a non-operator method for element access in case that's needed. More... | |
const T & | front () const |
Return a const reference to the first element in this array, which must not be empty. More... | |
T & | front () |
Return a writable reference to the first element in this array, which must not be empty. More... | |
const T & | back () const |
Return a const reference to the last element in this array, which must not be empty. More... | |
T & | back () |
Return a writable reference to the last element in this array, which must not be empty. More... | |
ArrayViewConst_< T, X > | operator() (index_type index, size_type length) const |
Select a subrange of this const array by starting index and length, and return a ArrayViewConst_ referencing that data without copying it. More... | |
ArrayViewConst_< T, X > | getSubArray (index_type index, size_type length) const |
Same as const form of operator()(index,length); exists to provide non-operator access to that functionality in case it is needed. More... | |
ArrayView_< T, X > | operator() (index_type index, size_type length) |
Select a subrange of this array by starting index and length, and return an ArrayView_ referencing that data without copying it. More... | |
ArrayView_< T, X > | updSubArray (index_type index, size_type length) |
Same as non-const operator()(index,length); exists to provide non-operator access to that functionality in case it is needed. More... | |
Public Member Functions inherited from SimTK::ArrayView_< T, X > | |
ArrayView_ () | |
Default constructor allocates no heap space and is very fast. More... | |
ArrayView_ (const ArrayView_ &src) | |
Copy constructor is shallow. More... | |
ArrayView_ (T *first, const T *last1) | |
Construct from a range of writable memory. More... | |
template<class A > | |
ArrayView_ (std::vector< T, A > &v) | |
Construct to reference memory owned by a writable std::vector. More... | |
operator const Array_< T, X > & () const | |
Implicit conversion of const ArrayView_ to const Array_& (zero cost). More... | |
operator Array_< T, X > & () | |
Implicit conversion of non-const ArrayView_ to Array_& (zero cost). More... | |
void | disconnect () |
Forward to base class disconnect() method – clears the handle without doing anything to the data. More... | |
~ArrayView_ () | |
The destructor just disconnects the array view handle from its data; see ArrayViewConst_<T,X>::disconnect() for more information. More... | |
ArrayView_ & | operator= (const ArrayView_ &src) |
Copy assignment; source must be the same size as this array. More... | |
template<class T2 , class X2 > | |
ArrayView_ & | operator= (const ArrayViewConst_< T2, X2 > &src) |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible. More... | |
template<class T2 , class X2 > | |
ArrayView_ & | operator= (const ArrayView_< T2, X2 > &src) |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible. More... | |
template<class T2 , class X2 > | |
ArrayView_ & | operator= (const Array_< T2, X2 > &src) |
Assignment from any other array object is allowed as long as the number of elements matches and the types are assignment compatible. More... | |
template<class T2 , class A2 > | |
ArrayView_ & | operator= (const std::vector< T2, A2 > &src) |
Assignment from any std::vector object is allowed as long as the number of elements matches and the types are assignment compatible. More... | |
ArrayView_ & | operator= (const T &fillValue) |
Fill assignment – all elements are set to fillValue. More... | |
ArrayView_ & | fill (const T &fillValue) |
Assign the supplied fill value to each element of this array, using T's copy assignment operator for each element. More... | |
void | assign (size_type n, const T &fillValue) |
This is the same as fill() but has the usual std::vector signature for compatibility; it will only work if the given number of elements is the same as this array's (fixed) size. More... | |
template<class T2 > | |
void | assign (const T2 *first, const T2 *last1) |
Assign to this array to make it a copy of the elements in range [first,last1) given by ordinary pointers, provided that the range is the same size as the array. More... | |
template<class Iter > | |
void | assign (const Iter &first, const Iter &last1) |
Assign to this array to make it a copy of the elements in range [first,last1) given by non-pointer iterators (the pointer case is handled with a specialized assign() variant). More... | |
const T & | operator[] (index_type i) const |
Select an element by its index, returning a const reference. More... | |
T & | operator[] (index_type i) |
Select an element by its index, returning a writable (lvalue) reference. More... | |
const T & | at (index_type i) const |
Same as operator[] but always range-checked, even in a Release build. More... | |
T & | at (index_type i) |
Same as operator[] but always range-checked, even in a Release build. More... | |
const T & | getElt (index_type i) const |
Same as the const form of operator[]; exists to provide a non-operator method for element access in case that's needed. More... | |
T & | updElt (index_type i) |
Same as the non-const form of operator[]; exists to provide a non-operator method for element access in case that's needed. More... | |
const T & | front () const |
Return a const reference to the first element in this array, which must not be empty. More... | |
T & | front () |
Return a writable reference to the first element in this array, which must not be empty. More... | |
const T & | back () const |
Return a const reference to the last element in this array, which must not be empty. More... | |
T & | back () |
Return a writable reference to the last element in this array, which must not be empty. More... | |
ArrayView_ | operator() (index_type index, size_type length) |
Select a contiguous subarray of the elements of this array and create another ArrayView_ that refers only to those element (without copying). More... | |
ArrayView_ | updSubArray (index_type index, size_type length) |
Same as non-const operator()(index,length); exists to provide non-operator access to that functionality in case it is needed. More... | |
const T * | cbegin () const |
Return a const pointer to the first element of this array if any, otherwise end(), which may be null (0) in that case but does not have to be. More... | |
const T * | begin () const |
The const version of begin() is the same as cbegin(). More... | |
T * | begin () |
Return a writable pointer to the first element of this array if any, otherwise end(). More... | |
const T * | cend () const |
Return a const pointer to what would be the element just after the last one in the array; this may be null (0) if there are no elements but doesn't have to be. More... | |
const T * | end () const |
The const version of end() is the same as cend(). More... | |
T * | end () |
Return a writable pointer to what would be the element just after the last one in this array. More... | |
const_reverse_iterator | crbegin () const |
Return a const reverse iterator pointing to the last element in the array or crend() if the array is empty. More... | |
const_reverse_iterator | rbegin () const |
The const version of rbegin() is the same as crbegin(). More... | |
reverse_iterator | rbegin () |
Return a writable reverse iterator pointing to the last element in the array or rend() if the array is empty. More... | |
const_reverse_iterator | crend () const |
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array. More... | |
const_reverse_iterator | rend () const |
The const version of rend() is the same as crend(). More... | |
reverse_iterator | rend () |
Return a writable past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array. More... | |
const T * | cdata () const |
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) if the array is empty. More... | |
const T * | data () const |
The const version of the data() method is identical to cdata(). More... | |
T * | data () |
Return a writable pointer to the first allocated element of the array, or a null pointer if no space is associated with the array. More... | |
size_type | size () const |
size_type | max_size () const |
bool | empty () const |
size_type | capacity () const |
size_type | allocated () const |
bool | isOwner () const |
Public Member Functions inherited from SimTK::ArrayViewConst_< T, X > | |
ArrayViewConst_ () | |
Default constructor allocates no heap space and is very fast. More... | |
ArrayViewConst_ (const ArrayViewConst_ &src) | |
Copy constructor is shallow; the constructed const array object will be referencing the original source data. More... | |
ArrayViewConst_ (const T *first, const T *last1) | |
Construct an ArrayViewConst_<T> by referencing (sharing) a given range of const data [first,last1), without copying that data. More... | |
template<class A > | |
ArrayViewConst_ (const std::vector< T, A > &src) | |
Construct a ArrayViewConst_<T> by referencing (sharing) the data in a const std::vector<T>, without copying the data; this is also an implicit conversion. More... | |
operator const ArrayView_< T, X > & () const | |
This is an implicit conversion to const ArrayView_<T,X>&, which is harmless since the const result won't permit writing on the elements. More... | |
operator const Array_< T, X > & () const | |
This is an implicit conversion to const Array_<T,X>&, which is harmless since the const result can't be used to write on or resize the data. More... | |
void | disconnect () |
Disconnect this array handle from any data to which it refers, restoring it to the condition it would be in if it had just been default-constructed. More... | |
~ArrayViewConst_ () | |
The destructor just disconnects the array view handle from its data; see disconnect() for more information. More... | |
size_type | size () const |
Return the current number of elements stored in this array. More... | |
size_type | max_size () const |
Return the maximum allowable size for this array. More... | |
bool | empty () const |
Return true if there are no elements currently stored in this array. More... | |
size_type | capacity () const |
Return the number of elements this array can currently hold without requiring reallocation. More... | |
size_type | allocated () const |
Return the amount of heap space owned by this array; this is the same as capacity() for owner arrays but is zero for non-owners. More... | |
bool | isOwner () const |
Does this array own the data to which it refers? If not, it can't be resized, and the destructor will not free any heap space nor call any element destructors. More... | |
const T & | operator[] (index_type i) const |
Select an element by its index, returning a const reference. More... | |
const T & | at (index_type i) const |
Same as operator[] but always range-checked, even in a Release build. More... | |
const T & | getElt (index_type i) const |
Same as the const form of operator[]; exists to provide a non-operator method for element access in case that's needed. More... | |
const T & | front () const |
Return a const reference to the first element in this array, which must not be empty (we'll check in a Debug build but not Release). More... | |
const T & | back () const |
Return a const reference to the last element in this array, which must not be empty (we'll check in a Debug build but not Release). More... | |
ArrayViewConst_ | operator() (index_type index, size_type length) const |
Select a contiguous subarray of the elements of this array and create another ArrayViewConst_ that refers only to those element (without copying). More... | |
ArrayViewConst_ | getSubArray (index_type index, size_type length) const |
Same as const form of operator()(index,length); exists to provide non-operator access to that functionality in case it is needed. More... | |
const T * | cbegin () const |
Return a const pointer to the first element of this array if any, otherwise cend(), which may be null (0) in that case but does not have to be. More... | |
const T * | cend () const |
Return a const pointer to what would be the element just after the last one in the array; this may be null (0) if there are no elements but doesn't have to be. More... | |
const T * | begin () const |
The const version of begin() is the same as cbegin(). More... | |
const T * | end () const |
The const version of end() is the same as cend(). More... | |
const_reverse_iterator | crbegin () const |
Return a const reverse iterator pointing to the last element in the array or crend() if the array is empty. More... | |
const_reverse_iterator | crend () const |
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array. More... | |
const_reverse_iterator | rbegin () const |
The const version of rbegin() is the same as crbegin(). More... | |
const_reverse_iterator | rend () const |
The const version of rend() is the same as crend(). More... | |
const T * | cdata () const |
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) if the array is empty. More... | |
const T * | data () const |
The const version of the data() method is identical to cdata(). More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T , class X > | |
void | swap (SimTK::Array_< T, X > &a1, SimTK::Array_< T, X > &a2) |
This is a specialization of the STL std::swap() algorithm which uses the constant time built-in swap() member of the Array_ class. More... | |
template<class T , class X > | |
Xml::Element | toXmlElement (const Array_< T, X > &thing, const std::string &name="") |
Partial specialization for XML serialization of Array_ objects. More... | |
Array_<T> serialization and I/O | |
These methods are at namespace scope but are logically part of the Array classes. These deal with reading and writing Arrays from and to streams, which places an additional requirement on the element type T: the element must support the same operation you are trying to do on the Array as a whole. | |
template<class T , class X > | |
void | writeUnformatted (std::ostream &o, const Array_< T, X > &v) |
Specialize writeUnformatted() for Array_<E,X> to delegate to element type E, with spaces separating the elements. More... | |
template<class T , class X > | |
void | writeFormatted (std::ostream &o, const Array_< T, X > &v) |
Specialize writeFormatted() for Array_<E,X> to delegate to element type E, with surrounding parentheses and commas separating the elements. More... | |
template<class T , class X > | |
std::ostream & | operator<< (std::ostream &o, const ArrayViewConst_< T, X > &a) |
Output a human readable representation of an array to an std::ostream (like std::cout). More... | |
template<class T , class X > | |
bool | readUnformatted (std::istream &in, Array_< T, X > &v) |
Specialization of readUnformatted() for variable-length Array_<T,X>; continues reading whitespace-separated tokens until error or eof. More... | |
template<class T , class X > | |
bool | readFormatted (std::istream &in, Array_< T, X > &v) |
Specialization of readFormatted() for variable-length Array_<T,X>; uses readArrayFromStream() to consume an appropriately-formatted array until error, closing parenthesis or bracket, or eof. More... | |
template<class T , class X > | |
static std::istream & | readArrayFromStream (std::istream &in, Array_< T, X > &out) |
Read in an Array_<T> from a stream, as a sequence of space-separated or comma-separated values optionally surrounded by parentheses (), square brackets [], or curly braces {}. More... | |
template<class T , class X > | |
static std::istream & | fillArrayFromStream (std::istream &in, Array_< T, X > &out) |
Read in a fixed number of elements from a stream into an Array. More... | |
template<class T , class X > | |
std::istream & | operator>> (std::istream &in, Array_< T, X > &out) |
Read an Array_<T> from a stream as a sequence of space- or comma-separated values of type T, optionally delimited by parentheses, brackets, or braces. More... | |
Comparison operators | |
template<class T1 , class X1 , class T2 , class X2 > | |
bool | operator== (const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2) |
Two Array_ objects are equal if and only if they are the same size() and each element compares equal using an operator T1==T2. More... | |
template<class T1 , class X1 , class T2 , class X2 > | |
bool | operator!= (const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2) |
The not equal operator is implemented using the equal operator. More... | |
template<class T1 , class X1 , class T2 , class X2 > | |
bool | operator< (const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2) |
Array_ objects are ordered lexicographically; that is, by first differing element or by length if there are no differing elements up to the length of the shorter array (in which case the shorter one is "less than" the longer). More... | |
template<class T1 , class X1 , class T2 , class X2 > | |
bool | operator>= (const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2) |
The greater than or equal operator is implemented using the less than operator. More... | |
template<class T1 , class X1 , class T2 , class X2 > | |
bool | operator> (const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2) |
The greater than operator is implemented by using less than with the arguments reversed, meaning the elements must have working comparison operators of the form T2==T1 and T2<T1. More... | |
template<class T1 , class X1 , class T2 , class X2 > | |
bool | operator<= (const ArrayViewConst_< T1, X1 > &a1, const ArrayViewConst_< T2, X2 > &a2) |
The less than or equal operator is implemented using the greater than operator. More... | |
template<class T1 , class X1 , class T2 , class A2 > | |
bool | operator== (const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2) |
An Array_<T1> and an std::vector<T2> are equal if and only if they are the same size() and each element compares equal using an operator T1==T2. More... | |
template<class T1 , class A1 , class T2 , class X2 > | |
bool | operator== (const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2) |
An std::vector<T1> and an Array_<T2> are equal if and only if they are the same size() and each element compares equal using an operator T2==T1. More... | |
template<class T1 , class X1 , class T2 , class A2 > | |
bool | operator!= (const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2) |
The not equal operator is implemented using the equal operator. More... | |
template<class T1 , class A1 , class T2 , class X2 > | |
bool | operator!= (const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2) |
The not equal operator is implemented using the equal operator. More... | |
template<class T1 , class X1 , class T2 , class A2 > | |
bool | operator< (const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2) |
An Array_<T1> and std::vector<T2> are ordered lexicographically; that is, by first differing element or by length if there are no differing elements up to the length of the shorter container (in which case the shorter one is "less than" the longer). More... | |
template<class T1 , class A1 , class T2 , class X2 > | |
bool | operator< (const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2) |
An std::vector<T1> and Array_<T2> are ordered lexicographically; that is, by first differing element or by length if there are no differing elements up to the length of the shorter container (in which case the shorter one is "less than" the longer). More... | |
template<class T1 , class X1 , class T2 , class A2 > | |
bool | operator>= (const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2) |
The greater than or equal operator is implemented using the less than operator. More... | |
template<class T1 , class A1 , class T2 , class X2 > | |
bool | operator>= (const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2) |
The greater than or equal operator is implemented using the less than operator. More... | |
template<class T1 , class X1 , class T2 , class A2 > | |
bool | operator> (const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2) |
The greater than operator is implemented by using less than with the arguments reversed, meaning the elements must have working comparison operators of the form T2==T1 and T2<T1. More... | |
template<class T1 , class A1 , class T2 , class X2 > | |
bool | operator> (const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2) |
The greater than operator is implemented by using less than with the arguments reversed, meaning the elements must have working comparison operators of the form T2==T1 and T2<T1. More... | |
template<class T1 , class X1 , class T2 , class A2 > | |
bool | operator<= (const ArrayViewConst_< T1, X1 > &a1, const std::vector< T2, A2 > &v2) |
The less than or equal operator is implemented using the greater than operator. More... | |
template<class T1 , class A1 , class T2 , class X2 > | |
bool | operator<= (const std::vector< T1, A1 > &v1, const ArrayViewConst_< T2, X2 > &a2) |
The less than or equal operator is implemented using the greater than operator. More... | |
Related Functions inherited from SimTK::ArrayView_< T, X > | |
template<class T , class X > | |
Xml::Element | toXmlElement (const ArrayView_< T, X > &thing, const std::string &name="") |
Partial specialization for XML serialization of ArrayView_ objects. More... | |
template<class T , class X > | |
bool | readUnformatted (std::istream &in, ArrayView_< T, X > &v) |
Specialization of readUnformatted() for fixed-length ArrayView_<T,X>; reads whitespace-separated tokens until the expected number have been read. More... | |
template<class T , class X > | |
bool | readFormatted (std::istream &in, ArrayView_< T, X > &v) |
Specialization of readFormatted() for fixed-length ArrayView_<T,X>; uses fillArrayViewFromStream() to consume an appropriately-formatted fixed-size array. More... | |
template<class T , class X > | |
static std::istream & | fillArrayViewFromStream (std::istream &in, ArrayView_< T, X > &out) |
Read in a fixed number of elements from a stream into an ArrayView. More... | |
template<class T , class X > | |
std::istream & | operator>> (std::istream &in, ArrayView_< T, X > &out) |
Read a (fixed size n) ArrayView_<T> from a stream as a sequence of space- or comma-separated values of type T, optionally delimited by parentheses, square brackets, or curly braces. More... | |
Related Functions inherited from SimTK::ArrayViewConst_< T, X > | |
template<class T , class X > | |
Xml::Element | toXmlElement (const ArrayViewConst_< T, X > &thing, const std::string &name="") |
Partial specialization for XML serialization of ArrayViewConst_ objects. More... | |
Element insertion and removal | |
These are methods that change the number of elements in the array by insertion or erasure. | |
void | push_back (const T &value) |
This method increases the size of the Array by one element at the end and initializes that element by copy constructing it from the given value. More... | |
void | push_back (T &&value) |
This is the move form of push_back(), taking an rvalue reference rather than an lvalue reference. More... | |
template<class... Args> | |
void | emplace_back (Args &&... args) |
This is similar to push_back() but rather than copying, it constructs the element in place at the end of the array. More... | |
void | push_back () |
(Deprecated, use emplace_back() instead) This is a non-standard version of push_back() that increases the size of the array by one default-constructed element at the end. More... | |
T * | raw_push_back () |
(Deprecated, use emplace_back() instead) This dangerous non-standard method increases the Array's size by one element at the end but doesn't perform any construction so the memory is filled with garbage. More... | |
void | pop_back () |
Remove the last element from this array, which must not be empty. More... | |
T * | erase (T *first, const T *last1) |
Erase elements in range [first,last1), packing in any later elements into the newly-available space and reducing the array's size by the number of elements erased. More... | |
T * | erase (T *p) |
Erase just one element, moving all subsequent elements down one slot and reducing the array's size by one. More... | |
T * | eraseFast (T *p) |
Be careful with this non-standard extension; it erases one element and then moves the last one in its place which changes the element order from what it was before (unlike the standard erase() method). More... | |
void | clear () |
Erase all the elements currently in this array without changing the capacity; equivalent to erase(begin(),end()) but a little faster. More... | |
T * | insert (T *p, size_type n, const T &value) |
Insert n copies of a given value at a particular location within this array, moving all following elements up by n positions. More... | |
T * | insert (T *p, const T &value) |
Insert a new element at a given location within this array, initializing it to a copy of a given value and moving all following elements up one position. More... | |
template<class... Args> | |
T * | emplace (T *p, Args &&... args) |
Insert a new element at a given location within this array, by invoking T's constructor whose signature matches the supplied arguments. More... | |
template<class T2 > | |
T * | insert (T *p, const T2 *first, const T2 *last1) |
Insert elements in a range [first,last1) into this array at a given position p, moving all following elements up by n=(last1-first) positions. More... | |
template<class Iter > | |
T * | insert (T *p, const Iter &first, const Iter &last1) |
Insert elements in a range [first,last1) where the range is given by non-pointer iterators. More... | |
The Array_<T> container class is a plug-compatible replacement for the C++ standard template library (STL) std::vector<T> class, but with some important advantages in performance, and functionality, and binary compatibility.
T | The type of object to be stored in this container. |
X | The type to be used for indexing this container, with default unsigned (not size_t). Any integral type may be used, as well as user types that satisfy the requirements discussed with class ArrayIndexTraits. |
_SECURE_SCL
breaks binary compatibility with other code built with the same compiler but without the flag. In contrast the performance of this Array_<T> class on any platform is indistinguishable from what you would get by managing your own heap-allocated arrays. 64 bit compilers vary on how well they handle 32 bit integers though, so in some cases the default index type (32 bit unsigned) won't be as fast as if you use a 64 bit unsigned type as does std::vector.typedef T SimTK::Array_< T, X >::value_type |
typedef X SimTK::Array_< T, X >::index_type |
typedef T* SimTK::Array_< T, X >::pointer |
typedef const T* SimTK::Array_< T, X >::const_pointer |
typedef T& SimTK::Array_< T, X >::reference |
typedef const T& SimTK::Array_< T, X >::const_reference |
typedef T* SimTK::Array_< T, X >::iterator |
typedef const T* SimTK::Array_< T, X >::const_iterator |
typedef std::reverse_iterator<iterator> SimTK::Array_< T, X >::reverse_iterator |
typedef std::reverse_iterator<const_iterator> SimTK::Array_< T, X >::const_reverse_iterator |
typedef ArrayIndexTraits<X>::size_type SimTK::Array_< T, X >::size_type |
typedef ArrayIndexTraits<X>::difference_type SimTK::Array_< T, X >::difference_type |
typedef ArrayIndexPackType<size_type>::packed_size_type SimTK::Array_< T, X >::packed_size_type |
|
inline |
Default constructor allocates no heap space and is very fast.
|
inlineexplicit |
Construct an array containing n default-constructed elements.
T's default constructor (if any) is called exactly n times. If n is zero no heap space will be allocated; although in that case it is preferable to use the default constructor if you can since that will be somewhat faster.
|
inline |
Construct an array containing n elements each set to a copy of the given initial value.
T's copy constructor will be called exactly n times. If n is zero no space will be allocated.
|
inline |
Construct an Array_<T> from a range [first,last1) of values identified by a pair of iterators.
|
inline |
Construct an Array_<T> from a range [first,last1) of values identified by a pair of ordinary pointers to elements of type T2 (where T2 might be the same as T but doesn't have to be).
This is templatized so can be used with any source type T2 which is either T or implicitly convertible to T, provided that the number of source elements does not exceed the array's max_size().
|
inline |
Construct an Array_<T> from an std::initializer_list whose elements were convertible to type T, provided that the number of source elements does not exceed the array's max_size().
Note that this constructor is not explicit
, so a suitable std::initializer_list will implicitly convert to an Array_<T>.
|
inlineexplicit |
Construct an Array_<T> by copying from an std::vector<T2>, where T2 may be the same type as T but doesn't have to be.
This will work as long as the size of the vector does not exceed the array's max_size(), and provided there is a working T(T2) conversion constructor.
|
inline |
Copy constructor allocates exactly as much memory as is in use in the source (not its capacity) and copy constructs the elements so that T's copy constructor will be called exactly src.size() times.
If the source is empty, no heap space will be allocated.
|
inline |
Move constructor swaps in the source and leaves the source default constructed.
|
inline |
Construct this Array_<T,X> as a copy of another Array_<T2,X2> where T2!=T or X2!=X.
This will work as long as the source is not larger than will fit here, and as long as the source element type T2 is assignment compatible with this array's element type T. One of T's constructors will be called exactly src.size() times; the particular constructor is whichever one best matches T(T2).
|
inline |
Construct an Array_<T> by referencing (sharing) a given range of data [first,last1), without copying that data; better to use the corresponding ArrayView_<T> constructor if you can.
This is very fast but can be dangerous – it is most useful for argument passing where the array handle will be discarded immediately after use. Note that this is available only if you have write access to the data because there is no way to construct a non-writable array. This will work as long as the size of the data does not exceed the array's max_size. The resulting array object is not resizeable but can be used to read and write elements of the original data. The array is invalid if the original data is destructed or resized, but there is no way for the array class to detect that.
|
inline |
Construct an Array_<T> by referencing (sharing) the data in an std::vector<T>, without copying the data; better to use the ArrayView_<T> constructor instead if you can.
This is very fast but can be dangerous – it is most useful for argument passing where the array handle will be discarded immediately after use. Note that this is available only if you have write access to the std::vector because there is no way to construct a non-writable array. This will work as long as the size of the vector does not exceed the array's max_size. The resulting array object is not resizeable but can be used to read and write elements of the original std::vector. The array is invalid if the original std::vector is destructed or resized.
|
inline |
The destructor performs a deallocate() operation which may result in element destruction and freeing of heap space; see deallocate() for more information.
|
inline |
Empty this array of its contents, returning the array to its default-constructed, all-zero state.
If this array is the owner of its data, the destructor (if any) is called for each data element and the array's allocated heap space is freed. If it is a non-owner the array handle is cleaned out using disconnect() but the referenced data is untouched.
|
inline |
Set this array to be n copies of the supplied fillValue.
Note that this serves to allow fill from an object whose type T2 is different from T, as long as there is a constructor T(T2) that works since that can be invoked (implicitly or explicitly) to convert the T2 object to type T prior to the call. If this is a non-owner array then n must be the same as the current size(); consider using the fill() method instead.
[in] | n | The number of elements to be in the result. |
[in] | fillValue | The value to which to initialize each element. |
|
inline |
Assign all current elements of the array to the same fillValue.
This is similar to assign(size(),fillValue) but the semantics are subtly different. Here we use repeated application of T's copy assignment operator T=fillValue, whereas the assign() semantics are to first destruct all the existing elements, then allocate if necessary, then use the copy constructor to initialize the new elements. Note that you can use this to fill from a source type T2 that is different from T as long as there exists a suitable constructor T(T2) that can be used to create the type T fillValue from the original T2 source.
[in] | fillValue | The value to which all existing elements are set. |
|
inline |
Assign to this array to to make it a copy of the elements in range [first,last1) given by ordinary pointers.
It is not allowed for this range to include any of the elements currently in the array. The source elements can be of a type T2 that may be the same or different than this array's element type T as long as there is a working constructor T(T2) (for owner arrays) or a working assignment operator T=T2 (for non-owner arrays). Note that although the source arguments are pointers, those may be iterators for some container depending on implementation details of the container. Specifically, any Array_<T2>::iterator or const_iterator is an ordinary pointer.
[in] | first | A pointer to the first source element to be copied. |
[in] | last1 | A pointer to one element past the last source element. |
|
inline |
Assign this array from a range [first,last1) given by non-pointer iterators.
See the assign(first,last1) method with pointer arguments for a relevant discussion.
[in] | first | An iterator pointing to the first source element to be copied. |
[in] | last1 | A iterator pointing one element past the last source element. |
|
inline |
Copy assignment operator destructs the current contents of this array and then makes it a copy of the source array by repeated calls to the element type's copy constructor.
At most one reallocation of heap space occurs that may result in this array having a larger or smaller capacity, although of course it will be at least as large as the source.
|
inline |
|
inline |
This is assignment from a source array whose element type T2 and/or index type X2 are different from this array's T and X.
This will work as long as this array can accommodate all the elements in the source and T2 is assignment compatible with T. See discussion for the copy assignment operator for more information.
|
inline |
This is assignment from a source std::vector<T2>.
This will work as long as this array can accommodate all the elements in the source and T2 is assignment compatible with T. See discussion for the copy assignment operator for more information.
|
inline |
This is a specialized algorithm providing constant time exchange of data with another array that has identical element and index types.
This is much faster than using the default std::swap() algorithm on the arrays since that would involve O(n) copying operations; we provide a specialization for std::swap() that uses the method here instead. This method makes no calls to any constructors or destructors. This is allowable even for non-owner arrays; the non-owner attribute will follow the non-owned data.
|
inline |
This dangerous extension allows you to supply your own already-allocated heap space for use by this array, which then becomes the owner of the supplied heap space.
Any memory currently associated with the array is deallocated; see deallocate() for more information.
|
inline |
A variant of adoptData() that assumes the capacity is the same as the current size.
|
inline |
This dangerous extension allows you to make this array handle refer to someone else's data without copying it.
Any memory currently associated with the array is deallocated; see deallocate() for more information. This method makes the array a fixed-size, non-owner array that cannot be reallocated, and no element destruction nor heap deallocation will occur when the handle is subsequently destructed or deallocated.
|
inline |
Same as shareData(data,size) but uses a pointer range [first,last1) to identify the data to be referenced.
|
inline |
Return the current number of elements stored in this array.
|
inline |
Return the maximum allowable size for this array.
|
inline |
|
inline |
Return the number of elements this array can currently hold without requiring reallocation.
The value returned by capacity() is always greater than or equal to size(), even if the data is not owned by this array in which case we have capacity() == size() and the array is not reallocatable.
|
inline |
Change the size of this Array, preserving all the elements that will still fit, and default constructing any new elements that are added.
This is not allowed for non-owner arrays unless the requested size is the same as the current size.
|
inline |
Change the size of this array, preserving all the elements that will still fit, and initializing any new elements that are added by repeatedly copy- constructing from the supplied value.
This is not allowed for non-owner arrays unless the requested size is the same as the current size.
|
inline |
Ensure that this array has enough allocated capacity to hold the indicated number of elements.
No heap reallocation will occur after this until the array is grown beyond this capacity, meaning that adding elements will not invalidate any iterators or element addresses until that point. This method will never reduce the capacity of the array. It is OK to call this on a non-owner array as long as you are not asking for an increase in capacity.
|
inline |
Request that the capacity of this array be reduced to the minimum necessary to hold the number of elements currently in use.
In practice no shrinkage will occur if the current size is just slightly too big, unless the current size is exactly zero in which case we guarantee to deallocate all heap space associated with this array leaving a null data pointer and begin()==end()==0, exactly as though the array had just been default-constructed. Otherwise you can check capacity() afterwards to see what happened. If the capacity() is reduced by this method, then all the elements will have been moved to new locations so existing iterators and references into the array will become invalid.
|
inline |
Return the amount of heap space owned by this array; this is the same as capacity() for owner arrays but is zero for non-owners.
|
inline |
Does this array own the data to which it refers? If not, it can't be resized, and the destructor will not free any heap space nor call any element destructors.
If the array does not refer to any data it is considered to be an owner and it is resizeable.
|
inline |
|
inline |
|
inline |
|
inline |
Return a const pointer to what would be the element just after the last one in the array; this may be null (0) if there are no elements but doesn't have to be.
This method is from the C++11 standard; there is also an overloaded end() from the original standard that returns a const pointer.
|
inline |
|
inline |
|
inline |
Return a const reverse iterator pointing to the last element in the array or crend() if the array is empty.
|
inline |
|
inline |
Return a writable reverse iterator pointing to the last element in the array or rend() if the array is empty.
|
inline |
Return the past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array.
You cannot dereference this iterator.
|
inline |
|
inline |
Return a writable past-the-end reverse iterator that tests equal to a reverse iterator that has been incremented past the front of the array.
You cannot dereference this iterator.
|
inline |
Return a const pointer to the first element of the array, or possibly (but not necessarily) null (0) if the array is empty.
|
inline |
|
inline |
Return a writable pointer to the first allocated element of the array, or a null pointer if no space is associated with the array.
|
inline |
Select an element by its index, returning a const reference.
Note that only a value of the Array's templatized index type is allowed (default is unsigned). This will be range-checked in a Debug build but not in Release.
|
inline |
Select an element by its index, returning a writable (lvalue) reference.
Note that only a value of the Array's templatized index type is allowed (default is unsigned). This will be range-checked in a Debug build but not in Release.
|
inline |
Same as operator[] but always range-checked, even in a Release build.
|
inline |
Same as operator[] but always range-checked, even in a Release build.
|
inline |
Same as the const form of operator[]; exists to provide a non-operator method for element access in case that's needed.
|
inline |
Same as the non-const form of operator[]; exists to provide a non-operator method for element access in case that's needed.
|
inline |
Return a const reference to the first element in this array, which must not be empty.
|
inline |
Return a writable reference to the first element in this array, which must not be empty.
|
inline |
Return a const reference to the last element in this array, which must not be empty.
|
inline |
Return a writable reference to the last element in this array, which must not be empty.
|
inline |
Select a subrange of this const array by starting index and length, and return a ArrayViewConst_ referencing that data without copying it.
|
inline |
Same as const form of operator()(index,length); exists to provide non-operator access to that functionality in case it is needed.
|
inline |
Select a subrange of this array by starting index and length, and return an ArrayView_ referencing that data without copying it.
|
inline |
Same as non-const operator()(index,length); exists to provide non-operator access to that functionality in case it is needed.
|
inline |
This method increases the size of the Array by one element at the end and initializes that element by copy constructing it from the given value.
If capacity() > size(), that's all that will happen. If capacity()==size(), there is no room for another element so we'll allocate more space and move all the elements there. A reference to the just-inserted element can be obtained using the back() method after the call to push_back().
[in] | value | An object of type T from which the new element is copy-constructed. |
|
inline |
This is the move form of push_back(), taking an rvalue reference rather than an lvalue reference.
See the other signature for information, with move-construction instead of copy-construction (reallocation is the same in either case).
|
inline |
This is similar to push_back() but rather than copying, it constructs the element in place at the end of the array.
To do that it invokes the constructor of T whose signature matches the supplied argument pack. This has the same effect as push_back(T(Args...))
would have but avoids the extra copy that would be required. Reallocation is handled the same as for push_back().
|
inline |
(Deprecated, use emplace_back() instead) This is a non-standard version of push_back() that increases the size of the array by one default-constructed element at the end.
This avoids having to default-construct the argument to the standard push_back(value) method which then has to copy-construct or move-construct it into the array. By carefully avoiding reallocation and using this form of push_back() you can use the Array_<T> class to hold objects of type T even if T has no copy or move constructor, which is prohibited by the standard std::vector<T> definition.
|
inline |
(Deprecated, use emplace_back() instead) This dangerous non-standard method increases the Array's size by one element at the end but doesn't perform any construction so the memory is filled with garbage.
You must immediately construct into this space, using code like:
This is a substantial performance improvement when the element type is something complicated since the constructor is called once and not copied; it can also be used for objects that have neither default nor copy constructors.
|
inline |
Remove the last element from this array, which must not be empty.
The element is destructed, not returned. The array's size() is reduced by one.
|
inline |
Erase elements in range [first,last1), packing in any later elements into the newly-available space and reducing the array's size by the number of elements erased.
Capacity is unchanged. If the range is empty nothing happens.
first | Points to the first element that will be erased. |
last1 | Points one element past the last element to be erased. |
|
inline |
Erase just one element, moving all subsequent elements down one slot and reducing the array's size by one.
This is equivalent to erase(p,p+1) but faster; that means p cannot be end() because end()+1 is not defined. Capacity is unchanged.
p | Points to the element that will be erased; p cannot be end(). |
|
inline |
Be careful with this non-standard extension; it erases one element and then moves the last one in its place which changes the element order from what it was before (unlike the standard erase() method).
This avoids having to compress the elements so this runs in constant time: the element is destructed; then if it wasn't the last element the move constructor is used to move the last element into the vacated space, and the destructor is called to clear the last element. The size is reduced by 1 but the capacity does not change.
p | Points to the element that will be erased; p cannot be end(). |
|
inline |
|
inline |
Insert n copies of a given value at a particular location within this array, moving all following elements up by n positions.
[in] | p | Where to insert the new elements. This must be an iterator (pointer) that is valid for this array, that is, begin() <= p <= end(). |
[in] | n | How many copies of the given value to insert. Nothing happens if n is zero. |
[in] | value | A value of the element type that is copied into the newly-created elements using T's copy constructor. |
|
inline |
Insert a new element at a given location within this array, initializing it to a copy of a given value and moving all following elements up one position.
This is identical to insert(p,1,value) but slightly faster; see that method for full documentation.
|
inline |
Insert a new element at a given location within this array, by invoking T's constructor whose signature matches the supplied arguments.
All following elements are moved up one position. This is identical in effect to insert(p,T(Args...))
but avoids the extra copy that would be required in that case.
|
inline |
Insert elements in a range [first,last1) into this array at a given position p, moving all following elements up by n=(last1-first) positions.
This variant of insert() takes iterators which are ordinary pointers, although the source elements do not have to be of type T as long as there is a constructor T(T2) that works.
[in] | p | Where to insert the new elements. This must be an iterator (pointer) that is valid for this array, that is, begin() <= p <= end(). |
[in] | first | This is a pointer to the first element of the source to be copied. |
[in] | last1 | This points one element past the last element of the source to be copied. |
|
inline |
Insert elements in a range [first,last1) where the range is given by non-pointer iterators.
|
related |
Specialize writeUnformatted() for Array_<E,X> to delegate to element type E, with spaces separating the elements.
|
related |
Specialize writeFormatted() for Array_<E,X> to delegate to element type E, with surrounding parentheses and commas separating the elements.
|
related |
Output a human readable representation of an array to an std::ostream (like std::cout).
The format is ( elements ) where elements is a comma-separated list of the Array's contents output by invoking the "<<" operator on the elements. This function will not compile if the element type does not support the "<<" operator. No newline is issued before or after the output.
|
related |
Specialization of readUnformatted() for variable-length Array_<T,X>; continues reading whitespace-separated tokens until error or eof.
|
related |
Specialization of readFormatted() for variable-length Array_<T,X>; uses readArrayFromStream() to consume an appropriately-formatted array until error, closing parenthesis or bracket, or eof.
|
related |
Read in an Array_<T> from a stream, as a sequence of space-separated or comma-separated values optionally surrounded by parentheses (), square brackets [], or curly braces {}.
We will continue to read elements of type T from the stream until we find a reason to stop, using type T's stream extraction operator>>() to read in each element and resizing the Array as necessary. If the data is bracketed, we'll read until we hit the closing bracket. If it is not bracketed, we'll read until we hit eof() or get an error such as the element extractor setting the stream's fail bit due to bad formatting. On successful return, the stream will be positioned right after the final read-in element or terminating bracket, and the stream's status will be good() or eof(). We will not consume trailing whitespace after bracketed elements; that means the stream might actually be empty even if we don't return eof(). If you want to know whether there is anything else in the stream, follow this call with the STL whitespace skipper std::ws() like this:
A compilation error will occur if you try to use this method on an Array_<T> for a type T for which there is no stream extraction operator>>().
|
related |
Read in a fixed number of elements from a stream into an Array.
We expect to read in exactly size() elements of type T, using type T's stream extraction operator>>(). This will stop reading when we've read size() elements, or set the fail bit in the stream if we run out of elements or if any element's extract operator sets the fail bit. On successful return, all size() elements will have been set, the stream will be positioned right after the final read-in element or terminating bracket, and the stream's status will be good() or eof(). We will not consume trailing whitespace after reading all the elements; that means the stream might actually be empty even if we don't return eof(). If you want to know whether there is anything else in the stream, follow this call with std::ws() like this:
A compilation error will occur if you try to use this method on an Array_<T> for a type T for which there is no stream extraction operator>>().
|
related |
Read an Array_<T> from a stream as a sequence of space- or comma-separated values of type T, optionally delimited by parentheses, brackets, or braces.
The Array_<T> may be an owner (variable size) or a view (fixed size n). In the case of an owner, we'll read all the elements in brackets or until eof if there are no brackets. In the case of a view, there must be exactly n elements in brackets, or if there are no brackets we'll consume exactly n elements and then stop. Each element is read in with its own operator ">>" so this won't work if no such operator is defined for type T.
|
related |
|
related |
The not equal operator is implemented using the equal operator.
|
related |
Array_ objects are ordered lexicographically; that is, by first differing element or by length if there are no differing elements up to the length of the shorter array (in which case the shorter one is "less than" the longer).
This depends on T1==T2 and T1<T2 operators working.
|
related |
The greater than or equal operator is implemented using the less than operator.
|
related |
The greater than operator is implemented by using less than with the arguments reversed, meaning the elements must have working comparison operators of the form T2==T1 and T2<T1.
|
related |
The less than or equal operator is implemented using the greater than operator.
|
related |
An Array_<T1> and an std::vector<T2> are equal if and only if they are the same size() and each element compares equal using an operator T1==T2.
|
related |
An std::vector<T1> and an Array_<T2> are equal if and only if they are the same size() and each element compares equal using an operator T2==T1.
|
related |
The not equal operator is implemented using the equal operator.
|
related |
The not equal operator is implemented using the equal operator.
|
related |
An Array_<T1> and std::vector<T2> are ordered lexicographically; that is, by first differing element or by length if there are no differing elements up to the length of the shorter container (in which case the shorter one is "less than" the longer).
This depends on having working element operators T1==T2 and T1<T2.
|
related |
An std::vector<T1> and Array_<T2> are ordered lexicographically; that is, by first differing element or by length if there are no differing elements up to the length of the shorter container (in which case the shorter one is "less than" the longer).
This depends on having working element operators T1==T2 and T1<T2.
|
related |
The greater than or equal operator is implemented using the less than operator.
|
related |
The greater than or equal operator is implemented using the less than operator.
|
related |
The greater than operator is implemented by using less than with the arguments reversed, meaning the elements must have working comparison operators of the form T2==T1 and T2<T1.
|
related |
The greater than operator is implemented by using less than with the arguments reversed, meaning the elements must have working comparison operators of the form T2==T1 and T2<T1.
|
related |
The less than or equal operator is implemented using the greater than operator.
|
related |
The less than or equal operator is implemented using the greater than operator.
|
related |
|
related |
Partial specialization for XML serialization of Array_ objects.
The result is a single element with tag word <Array>
with the given name (if any) and a version number as attributes. Then each entry is a subelement, as produced by type T's toXmlElement()
method.