<array>
[added with C++11]
array
· get
· operator!==
· operator==
· operator<
· operator<=
· operator>
· operator>=
· swap
· tuple_element
· tuple_size
Include the TR1
header <array>
to define the container
template class array
and several supporting templates.
Beginning with C++11,
some functions declared in this header
use constexpr
to signal that they are treated as
compile-time constants.
namespace std { template<class Ty, size_t N> class array; // TEMPLATE FUNCTIONS template<class Ty, size_t N> bool operator==( const array<Ty, N>& left, const array<Ty, N>& right); template<class Ty, size_t N> bool operator!=( const array<Ty, N>& left, const array<Ty, N>& right); template<class Ty, size_t N> bool operator<( const array<Ty, N>& left, const array<Ty, N>& right); template<class Ty, size_t N> bool operator<=( const array<Ty, N>& left, const array<Ty, N>& right); template<class Ty, size_t N> bool operator>( const array<Ty, N>& left, const array<Ty, N>& right); template<class Ty, size_t N> bool operator>=( const array<Ty, N>& left, const array<Ty, N>& right); template<class Ty, size_t N> void swap( array<Ty, N>& left, array<Ty, N>& right) noexcept(noexcept(swap(left.swap(right)))); // tuple-LIKE INTERFACE template<int Idx, class T, size_t N> RI& get(array<T, N>& arr) noexcept; template<int Idx, class T, size_t N> const RI& get(const array<T, N>& arr) noexcept; template<int Idx, class T, size_t N> RI&& get(array<T, N>&& arr); template<int Idx, class T, size_t N> class tuple_element<Idx, array<T, N> >; template<class T, size_t N> class tuple_size<array<T, N> >; namespace tr1 { using std::array; using std::get; [added with C++11] using std::tuple_element; using std::tuple_size; } // namespace tr1 } // namespace std
array
array
· assign
· at
· back
· begin
· cbegin
· cend
· const_iterator
· const_pointer
· const_reference
· const_reverse_iterator
· crbegin
· crend
· data
· difference_type
· empty
· end
· fill
· front
· iterator
· max_size
· operator=
· operator[]
· pointer
· rbegin
· reference
· rend
· reverse_iterator
· size
· size_type
· swap
· value_type
template<class Ty, size_t N> class array { public: // NESTED TYPES typedef size_t size_type; typedef 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 reverse_iterator<iterator> reverse_iterator; typedef reverse_iterator<const_iterator> const_reverse_iterator; // CONSTRUCTORS (exposition only) array(); array(const array& right); // MODIFICATION void assign(const Ty& val); [removed with C++11] void fill(const Ty& val); [added with C++11] array& operator=(const array& right); // exposition only void swap(array& right) noexcept(noexcept(swap(declval<Ty&>(), declval<Ty&>()))); // ITERATORS iterator begin() noexcept; const_iterator begin() const noexcept; iterator end() noexcept; const_iterator end() const noexcept; reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept; reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept; const_iterator cbegin() const noexcept; [added with C++11] const_iterator cend() const noexcept; [added with C++11] const_reverse_iterator crbegin() const noexcept; [added with C++11] const_reverse_iterator crend() const noexcept; [added with C++11] // SIZE QUERIES constexpr size_type size() const noexcept; constexpr size_type max_size() const noexcept; constexpr bool empty() const noexcept; // 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() noexcept; const Ty *data() const noexcept; };
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.
array::array
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())
.
array::assign
void assign(const Ty& val); [removed with C++11]
The member function replaces the sequence controlled by *this
with a repetition of N
elements of value val
.
array::at
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
.
array::back
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.
array::begin
iterator begin() noexcept; const_iterator begin() const noexcept;
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).
array::cbegin
const_iterator cbegin() const noexcept; [added with C++11]
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).
array::cend
const_iterator cend() const noexcept; [added with C++11]
The member functions return a random-access iterator that points just beyond the end of the sequence.
array::const_iterator
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
.
array::const_pointer
typedef const Ty *const_pointer;
The type describes an object that can serve as a constant pointer to elements of the sequence.
array::const_reference
typedef const Ty& const_reference;
The type describes an object that can serve as a constant reference to an element of the controlled sequence.
array::const_reverse_iterator
typedef reverse_iterator<const_iterator> const_reverse_iterator;
The type describes an object that can server as a constant reverse iterator for the controlled sequence.
array::crbegin
const_reverse_iterator crbegin() const noexcept; [added with C++11]
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.
array::crend
const_reverse_iterator crend() const noexcept; [added with C++11]
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.
array::data
Ty *data() noexcept; const Ty *data() const noexcept;
The member functions return the address of the first element in the controlled sequence.
array::difference_type
typedef 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 ptrdiff_t
.
array::empty
constexpr bool empty() const noexcept;
The member function returns true only if N == 0
.
array::end
iterator end() noexcept; const_iterator end() const noexcept;
The member functions return a random-access iterator that points just beyond the end of the sequence.
array::fill
void fill(const Ty& val); [added with C++11]
The member function replaces the sequence controlled by *this
with a repetition of N
elements of value val
.
array::front
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.
array::iterator
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
.
array::max_size
constexpr size_type max_size() const noexcept;
The member function returns N
.
array::operator=
array& operator=(const array& right);
The operator assigns each element of right
to
the corresponding element of the controlled sequence.
It returns *this
.
array::operator[]
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.
array::pointer
typedef Ty *pointer;
The type describes an object that can serve as a pointer to elements of the sequence.
array::rbegin
reverse_iterator rbegin() noexcept; const_reverse_iterator rbegin() const noexcept;
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.
array::reference
typedef Ty& reference;
The type describes an object that can serve as a reference to an element of the controlled sequence.
array::rend
reverse_iterator rend() noexcept; const_reverse_iterator rend() const noexcept;
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.
array::reverse_iterator
typedef reverse_iterator<iterator> reverse_iterator;
The type describes an object that can server as a reverse iterator for the controlled sequence.
array::size
constexpr size_type size() const noexcept;
The member function returns N
.
array::size_type
typedef 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 size_t
.
array::swap
void swap(array& right) noexcept(noexcept(swap(declval<Ty&>(), declval<Ty&>())));
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::value_type
typedef Ty value_type;
The type is a synonym for the template parameter Ty
.
get
template<int Idx, class T, size_t N> RI& get(array<T, N>& arr) noexcept; template<int Idx, class T, size_t N> const RI& get(const array<T, N>& arr) noexcept; template<int Idx, class T, size_t N> RI&& get(array<T, N>&& arr);
The template functions return a reference to arr[Idx]
.
operator!=
template<Ty, size_t N> bool operator!=( const array<Ty, N>& left, const array<Ty, N>& right);
The template function returns !(left == right)
.
operator==
template<Ty, 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())
.
operator<
template<Ty, 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())
.
operator<=
template<Ty, size_t N> bool operator<=( const array<Ty, N>& left, const array<Ty, N>& right);
The template function returns !(right < left)
.
operator>
template<Ty, size_t N> bool operator>( const array<Ty, N>& left, const array<Ty, N>& right);
The template function returns right < left
.
operator>=
template<Ty, size_t N> bool operator>=( const array<Ty, N>& left, const array<Ty, N>& right);
The template function returns !(left < right)
.
swap
template<class Ty, size_t N> void swap( array<Ty, N>& left, array<Ty, N>& right) noexcept(noexcept(swap(left.swap(right))));
The template function executes left.swap(right)
.
tuple_element
template<int Idx, class T, size_t N> class tuple_elementIdx, <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
.
tuple_size
template<class T, 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.
See also the Table of Contents and the Index.
Copyright © 1992-2013 by Dinkumware, Ltd. All rights reserved.