Skip to content
Ned Bingham edited this page Mar 10, 2017 · 22 revisions

std/array.h


template <class value_type> struct array

This structure implements dynamic array.

Member Types

Member Variables

  • value_type *data is a pointer to the data in memory.
  • int count keeps track of the number of elements stored in this array.
  • int capacity keeps track of the number of elements we can store at this location in memory.

Member Functions

Constructor

array()

The default constructor, initializes data to NULL, count to 0 and capacity to 0.

Copy Constructors

array(const value_type &value)
array(const container_type &store)
array(const array<value_type> &store)

Copy the contents of another container into this array.

Range Constructors

array(iterator left, iterator right)
array(const_iterator left, const_iterator right)
array(typename container_type::iterator left, typename container_type::iterator right)
array(typename container_type::const_iterator left, typename container_type::const_iterator right)

copy the elements within the iterator range [left,right) into this array.

Utility

Basic functions necessary for algorithm execution.

int size()

Returns count.

Iterators

begin()

iterator begin()
const_iterator begin() const

Returns an iterator to the first element.

end()

iterator end()
const_iterator end() const

returns an iterator to one after the last element.

rbegin()

iterator rbegin()
const_iterator rbegin() const

returns an iterator to the last element.

rend()

iterator rend()
const_iterator rend() const

returns an iterator to one before the first element.

at(int i)

iterator at(int i)
const_iterator at(int i) const

returns an iterator to the ith element.

Accessors

value_type &front()

Returns the value of the first element.

value_type &back()

Returns the value of the last element.

value_type &get(int i)

Returns the value of the ith element.

value_type *ptr(int i)

Returns a pointer to the ith element.

value_type &operator[](int i)

Returns the value of the ith element.

Slicing

slice<array<value_type> > deref()

wraps this array with a slice. This is particularly useful if an algorithm gives you a container filled with iterators. You can convert it into a slice with a single call to this function.

array<int> idx()

This is orthogonal to deref(). If this container is filled with iterators, it returns the index of each iterator.

slice<array<iterator> > sub(int start, int end)

returns a slice of this container of the elements within the range [start,end).

slice<array<iterator> > sub(int start)

returns a slice of this container of the elements after start.

slice<array<iterator> > sub()

returns a slice of all the elements in this container.

static slice<array<const_iterator> > sub(const_iterator start, const_iterator end)

returns a slice of all the elements within the range [start,end) of a range container.

static slice<array<const_iterator> > sub(iterator start, iterator end)

returns a slice of all the elements within the range [start,end) of a range container.

array<value_type> subcpy(int start, int end)

see above. This returns a copy instead of a slice.

array<value_type> subcpy(int start)

see above. This returns a copy instead of a slice.

array<value_type> subcpy()

see above. This returns a copy instead of a slice.

array<typename container::iterator> sample(container &c)

uses the values of the range container as indices into c. Returns another range container with the indexed value from c.

Modifiers

void swap(range<value_type> &root)

swaps the contents of this range container with another.

range<value_type> &operator=(const range<value_type> &root)

sets the contents of this range container equal the contents of another.

Non-Member Functions

Comparison

range/range

bool operator==(range<value_type1> s1, range<value_type2> s2)
bool operator!=(range<value_type1> s1, range<value_type2> s2)
bool operator<(range<value_type1> s1, range<value_type2> s2)
bool operator>(range<value_type1> s1, range<value_type2> s2)
bool operator<=(range<value_type1> s1, range<value_type2> s2)
bool operator>=(range<value_type1> s1, range<value_type2> s2)

Compares two range containers by comparing start followed by finish.

range/slice

bool operator==(range<value_type1> s1, core::slice<container2> s2)
bool operator!=(range<value_type1> s1, core::slice<container2> s2)
bool operator<(range<value_type1> s1, core::slice<container2> s2)
bool operator>(range<value_type1> s1, core::slice<container2> s2)
bool operator<=(range<value_type1> s1, core::slice<container2> s2)
bool operator>=(range<value_type1> s1, core::slice<container2> s2)
bool operator==(core::slice<container1> s1, range<value_type2> s2)
bool operator!=(core::slice<container1> s1, range<value_type2> s2)
bool operator<(core::slice<container1> s1, range<value_type2> s2)
bool operator>(core::slice<container1> s1, range<value_type2> s2)
bool operator<=(core::slice<container1> s1, range<value_type2> s2)
bool operator>=(core::slice<container1> s1, range<value_type2> s2)

Compares a range container to a generic slice by calling compare().

Examples

#include <std/ascii_stream.h>
#include <std/array.h>

using namespace core;

int main()
{
    array<int> arr = range<int>(0, 10);
    cout << arr << endl;
    return 0;
}

Simple Containers

Standard Containers

Interface Containers

Specialized Containers

Input/Output

Algorithm

Clone this wiki locally