<array>

Description
Synopsis
Classes
Template functions
Templates

Description

Include the TR1 header <array> to define the container template class array and several supporting templates.

Note:
To enable this header file, you must define the macro __IBMCPP_TR1__ .

Synopsis

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

Classes

array

array

Description
Synopsis
Constructor
array::array
Types
array::const_iterator
array::const_pointer
array::const_reference
array::const_reverse_iterator
array::difference_type
array::iterator
array::pointer
array::reference
array::reverse_iterator
array::size_type
array::value_type
Member functions
array::assign
array::at
array::back
array::begin
array::data
array::empty
array::end
array::front
array::max_size
array::operator[]
array::rbegin
array::rend
array::size
array::swap
Operators
array::operator=
Description

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.

Synopsis
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;
    };
Constructor
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()).

Types
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 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.

array::difference_type

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.

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::pointer

typedef Ty *pointer;

The type describes an object that can serve as a pointer to elements of the 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::reverse_iterator

typedef std::reverse_iterator<iterator> reverse_iterator;

The type describes an object that can server as a reverse iterator for the controlled sequence.

array::size_type

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.

array::value_type

typedef Ty value_type;

The type is a synonym for the template parameter Ty.

Member functions
array::assign

void assign(const Ty& val);

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();
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).

array::data

Ty *data();
const Ty *data() const;

The member functions return the address of the first element in the controlled sequence.

array::empty

bool empty() const;

The member function returns true only if N == 0.

array::end

reference end();
const_reference end() const;

The member functions return a random-access iterator that points just beyond the end of the sequence.

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::max_size

size_type max_size() const;

The member function returns N.

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::rbegin

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.

array::rend

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.

array::size

size_type size() const;

The member function returns N.

array::swap

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.

Operators
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.

Template functions

get
operator!=
operator==
operator<
operator<=
operator>
operator>=
swap

get

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].

operator!=

template<Ty, std::size_t N>
    bool operator!=(
        const array<Ty, N>& left,
        const array<Ty, N>& right);

The template function returns !(left == right).

operator==

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()).

operator<

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()).

operator<=

template<Ty, std::size_t N>
    bool operator<=(
        const array<Ty, N>& left,
        const array<Ty, N>& right);

The template function returns !(right < left).

operator>

template<Ty, std::size_t N>
    bool operator>(
        const array<Ty, N>& left,
        const array<Ty, N>& right);

The template function returns right < left.

operator>=

template<Ty, std::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, std::size_t N>
    void swap(
        array<Ty, N>& left,
        array<Ty, N>& right);

The template function executes left.swap(right).

Templates

tuple_element
tuple_size

tuple_element

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.

tuple_size

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.

Copyright note

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.