Include the TR1 header <array> to define the container template class array and several supporting templates.
namespace std {
namespace tr1 {
template<class Ty, std::size_t N>
class array;
// TEMPLATE FUNCTIONS
template<class Ty, std::size_t N>
bool operator==(
const array<Ty, N>& left,
const array<Ty, N>& right);
template<class Ty, std::size_t N>
bool operator!=(
const array<Ty, N>& left,
const array<Ty, N>& right);
template<class Ty, std::size_t N>
bool operator<(
const array<Ty, N>& left,
const array<Ty, N>& right);
template<class Ty, std::size_t N>
bool operator<=(
const array<Ty, N>& left,
const array<Ty, N>& right);
template<class Ty, std::size_t N>
bool operator>(
const array<Ty, N>& left,
const array<Ty, N>& right);
template<class Ty, std::size_t N>
bool operator>=(
const array<Ty, N>& left,
const array<Ty, N>& right);
template<class Ty, std::size_t N>
void swap(
array<Ty, N>& left,
array<Ty, N>& right);
// tuple-LIKE INTERFACE
template<int Idx, class T, std::size_t N>
RI get(array<T, N>&);
template<int Idx, class T, std::size_t N>
const RI get(const array<T, N>&);
template<int Idx, class T, std::size_t N>
class tuple_element<Idx, array<T, N> >;
template<class T, std::size_t N>
class tuple_size<array<T, N> >;
} // namespace tr1
} // namespace std
The template class describes an object that controls a sequence of length N of elements of type Ty. The sequence is stored as an array of Ty, contained in the array<Ty, N> object.
The type has a default constructor array() and a default assignment operator operator=, and satisfies the requirements for an aggregate. Thus, objects of type array<Ty, N> can be initialized with an aggregate initializer. For example:
array<int, 4> ai = { 1, 2, 3 };
creates the object ai which holds four integer values, initializes the first three elements to the values 1, 2, and 3 respectively, and initializes the fourth element to 0.
template<class Ty, std::size_t N>
class array {
public:
// NESTED TYPES
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef Ty& reference;
typedef const Ty& const_reference;
typedef Ty *pointer;
typedef const Ty *const_pointer;
typedef T0 iterator;
typedef T1 const_iterator;
typedef Ty value_type;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
// CONSTRUCTORS (exposition only)
array();
array(const array& right);
// MODIFICATION
void assign(const Ty& val);
array& operator=(const array& right); // exposition only
void swap(array& right);
// ITERATORS
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
// SIZE QUERIES
size_type size() const;
size_type max_size() const;
bool empty() const;
// ELEMENT ACCESS
reference at(size_type off);
const_reference at(size_type off) const;
reference operator[](size_type off);
const_reference operator[](size_type off) const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
Ty *data();
const Ty *data() const;
};
array(); array(const array& right);
The first constructor leaves the controlled sequence uninitialized (or default initialized). The second constructor initializes the controlled sequence with the sequence [right.begin(), right.end()).
typedef T1 const_iterator;
The type describes an object that can server as a constant random-access iterator for the controlled sequence. It is described here as a synonym for the implementation-specific type T1.
typedef const Ty *const_pointer;
The type describes an object that can serve as a constant pointer to elements of the sequence.
typedef const Ty& const_reference;
The type describes an object that can serve as a constant reference to an element of the controlled sequence.
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
The type describes an object that can server as a constant reverse iterator for the controlled sequence.
typedef std::ptrdiff_t difference_type;
The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence. It is a synonym for the type std::ptrdiff_t.
typedef T0 iterator;
The type describes an object that can server as a random-access iterator for the controlled sequence. It is described here as a synonym for the implementation-specific type T0.
typedef Ty *pointer;
The type describes an object that can serve as a pointer to elements of the sequence.
typedef Ty& reference;
The type describes an object that can serve as a reference to an element of the controlled sequence.
typedef std::reverse_iterator<iterator> reverse_iterator;
The type describes an object that can server as a reverse iterator for the controlled sequence.
typedef std::size_t size_type;
The unsigned integer type describes an object that can represent the length of any controlled sequence. It is a synonym for the type std::size_t.
typedef Ty value_type;
The type is a synonym for the template parameter Ty.
void assign(const Ty& val);
The member function replaces the sequence controlled by *this with a repetition of N elements of value val.
reference at(size_type off); const_reference at(size_type off) const;
The member functions return a reference to the element of the controlled sequence at position off. If that position is invalid, the function throws an object of class out_of_range.
reference back(); const_reference back() const;
The member functions return a reference to the last element of the controlled sequence, which must be non-empty.
iterator begin(); const_iterator begin() const;
The member functions return a random-access iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).
Ty *data(); const Ty *data() const;
The member functions return the address of the first element in the controlled sequence.
bool empty() const;
The member function returns true only if N == 0.
reference end(); const_reference end() const;
The member functions return a random-access iterator that points just beyond the end of the sequence.
reference front(); const_reference front() const;
The member functions return a reference to the first element of the controlled sequence, which must be non-empty.
size_type max_size() const;
The member function returns N.
reference operator[](size_type off); const_reference operator[](size_type off) const;
The member functions return a reference to the element of the controlled sequence at position off. If that position is invalid, the behavior is undefined.
reverse_iterator rbegin(); const_reverse_iterator rbegin() const;
The member functions return a reverse iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence.
reverse_iterator rend(); const_reverse_iterator rend() const;
The member functions return a reverse iterator that points at the first element of the sequence (or just beyond the end of an empty sequence)). Hence, it designates the end of the reverse sequence.
size_type size() const;
The member function returns N.
void swap(array& right);
The member function swaps the controlled sequences between *this and right. It performs a number of element assignments and constructor calls proportional to N.
array& operator=(const array& right);
The operator assigns each element of right to the corresponding element of the controlled sequence. It returns *this.
template<int Idx, class T, std::size_t N>
T& get(array<T, N>& arr);
template<int Idx, class T, std::size_t N>
const T& get(const array<T, N>& arr);
The template functions return a reference to arr[Idx].
template<Ty, std::size_t N>
bool operator!=(
const array<Ty, N>& left,
const array<Ty, N>& right);
The template function returns !(left == right).
template<Ty, std::size_t N>
bool operator==(
const array<Ty, N>& left,
const array<Ty, N>& right);
The template function overloads operator== to compare two objects of template class array. The function returns equal(left.begin(), left.end(), right.begin()).
template<Ty, std::size_t N>
bool operator<(
const array<Ty, N>& left,
const array<Ty, N>& right);
The template function overloads operator< to compare two objects of template class array. The function returns lexicographical_compare(left.begin(), left.end(), right.begin()).
template<Ty, std::size_t N>
bool operator<=(
const array<Ty, N>& left,
const array<Ty, N>& right);
The template function returns !(right < left).
template<Ty, std::size_t N>
bool operator>(
const array<Ty, N>& left,
const array<Ty, N>& right);
The template function returns right < left.
template<Ty, std::size_t N>
bool operator>=(
const array<Ty, N>& left,
const array<Ty, N>& right);
The template function returns !(left < right).
template<class Ty, std::size_t N>
void swap(
array<Ty, N>& left,
array<Ty, N>& right);
The template function executes left.swap(right).
template<int Idx, class T, std::size_t N>
class tuple_element<Idx, array<T, N> > {
typedef T type;
};
The template is a specialization of the template class tuple_element. It has a nested typedef type that is a synonym for the type of the Idx element of the array.
template<class T, std::size_t N>
class tuple_size<array<T, N> > {
static const unsigned value = N;
};
The template is a specialization of the template class tuple_size. It has a member value that is an integral constant expression whose value is N, the size of the array.
Certain materials included or referred to in this document are copyright P.J. Plauger and/or Dinkumware, Ltd. or are based on materials that are copyright P.J. Plauger and/or Dinkumware, Ltd.
Notwithstanding the meta-data for this document, copyright information for this document is as follows:
Copyright © IBM Corp. 1999, 2010. & Copyright © P.J. Plauger and/or Dinkumware, Ltd. 1992-2006.