Skip to content
Ned Bingham edited this page Mar 23, 2017 · 7 revisions

std/list.h


template <class value_type>
struct list

This structure implements doubly linked list.

Member Types

Member Variables

  • end_item left, right defines the bounds of this linked list.

Member Functions

Constructor

list()

The default constructor, connects left to right to initialize an empty list.

list(const value_type &c)
list(const container &c)
list(const list<value_type> &c)

Copy the contents of another container into this list.

list(iterator left, iterator right)
list(const_iterator left, const_iterator right)
list(container::iterator left, container::iterator right)
list(container::const_iterator left, container::const_iterator right)

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

Utility

static list<value_type> values(int n, ...) initializes and returns a list given n values.

int size() Returns the size by traversing the list and counting up the elements. If you need a constant-time size function, you should use an index_list instead.

Iterators

iterator begin()
const_iterator begin() const

Returns an iterator to the first element.

iterator end()
const_iterator end() const

returns an iterator to one after the last element.

iterator rbegin()
const_iterator rbegin() const

returns an iterator to the last element.

iterator rend()
const_iterator rend() const

returns an iterator to one before the first element.

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

returns an iterator to the ith element. This is done by traversal in O(i) time so should be used sparingly.

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. This is done by traversal in O(i) time so should be used sparingly.

value_type *ptr(int i) Returns a pointer to the ith element. This is done by traversal in O(i) time so should be used sparingly.

value_type &operator[](int i) Returns the value of the ith element. This is done by traversal in O(i) time so should be used sparingly

Slicing

slice<list<value_type> > deref()

wraps this list 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.

list<int> idx()

If this container is filled with iterators, it returns the index of each iterator.

slice<range<iterator> > sub(int start, int end)
slice<range<const_iterator> > sub(int start, int end) const
list<value_type> subcpy(int start, int end) const

returns a slice or copy of the elements within the range [start,end).

slice<range<iterator> > sub(int start)
slice<range<const_iterator> > sub(int start) const
list<value_type> subcpy(int start) const

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

slice<range<iterator> > sub()
slice<range<const_iterator> > sub() const
list<value_type> subcpy()

returns a slice or copy of all the elements in this container.

static slice<range<const_iterator> > sub(iterator start, iterator end)
static slice<range<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.

list<container::iterator> sample(container &c)
list<container::const_iterator> sample(const container &c)

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

Modifiers

static void drop(iterator start, iterator end)

This deletes a range of list iterators from its parent container.

void drop(int start, int end)

This deletes a range of elements from this list from start to end.

void drop_back(int n = 1)
void drop_front(int n = 1)

deletes n elements from the beginning or end of the list.

static list<value_type> pop(iterator start, iterator end)

removes a range of elements from its parent list and places them in a new list which is then returned to the user. This is done in constant time with no memory allocations.

list<value_type> pop(int start, int end)

removes a range of elements from this list and places them in a new list which is then returned to the user.

list<value_type> pop_back(int n = 1)
list<value_type> pop_front(int n = 1)

removes n elements from the front or back of this list and places them in a new list which is then returned to the user.

void push_back(value_type v)
void push_front(value_type v)

place a new element on the front or back of the list.

void append_back(const container &c)
void append_front(const container &c)

place all of the elements in c on the front or back of the list.

static void replace(iterator start, iterator end, value_type v)
static void replace(iterator start, iterator end, const container &c)

replace the elements in the range [start,end) in their parent container with either the value v or all of the elements in the container c.

void replace(int start, int end, value_type v)
void replace(int start, int end, const container &c)

replace the elements in the range [start,end) in this list with either the value v or all of the elements in the container c.

void replace_back(int n, const value_type &v)
void replace_back(int n, const container &c)
void replace_front(int n, const value_type &v)
void replace_front(int n, const container &c)

replace the first or last n elements of this list with either the value v or all of the elements in the container c.

void swap(list<value_type> &lst)

swaps the contents of this container with another.

void resize(int n, const value_type &v = value_type())

resize the container to a count of n elements, adding elements of v on the back or deleting elements from the back if necessary.

void clear()
void release()

clear all of the elements out of the list.

list<value_type> &operator=(const container &c)
list<value_type> &operator=(const list<value_type> &c)

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

end_item* get_item(iterator i)
end_item* get_item(const_iterator i)

these are protected functions used by derived classes to access the underlying link structure.

Non-Member Functions

Arithmetic

list<value_type> &operator<<(list<value_type> &os, const container &c)
list<value_type> &operator<<(list<value_type> &os, const value_type &v)

insert either the value v or all of the elements of the container c onto the end of the list.

list<value_type> operator+(const list<value_type> &os, const container &c)
list<value_type> operator+(const list<value_type> &os, const value_type &v)

combine the elements of two containers and return the result. This doesn't affect either container.

Comparison

bool operator==(list<value_type1> a1, list<value_type2> a2)
bool operator!=(list<value_type1> a1, list<value_type2> a2)
bool operator<(list<value_type1> a1, list<value_type2> a2)
bool operator>(list<value_type1> a1, list<value_type2> a2)
bool operator<=(list<value_type1> a1, list<value_type2> a2)
bool operator>=(list<value_type1> a1, list<value_type2> a2)

Compares two lists by comparing each element from the beginning until a difference is found.

bool operator==(list<value_type1> a1, core::slice<container2> a2)
bool operator!=(list<value_type1> a1, core::slice<container2> a2)
bool operator<(list<value_type1> a1, core::slice<container2> a2)
bool operator>(list<value_type1> a1, core::slice<container2> a2)
bool operator<=(list<value_type1> a1, core::slice<container2> a2)
bool operator>=(list<value_type1> a1, core::slice<container2> a2)
bool operator==(core::slice<container1> a1, list<value_type2> a2)
bool operator!=(core::slice<container1> a1, list<value_type2> a2)
bool operator<(core::slice<container1> a1, list<value_type2> a2)
bool operator>(core::slice<container1> a1, list<value_type2> a2)
bool operator<=(core::slice<container1> a1, list<value_type2> a2)
bool operator>=(core::slice<container1> a1, list<value_type2> a2)

Compares an list to a generic slice by comparing each element from the beginning until a difference is found.

bool operator==(list<value_type1> a1, range<value_type2> a2)
bool operator!=(list<value_type1> a1, range<value_type2> a2)
bool operator<(list<value_type1> a1, range<value_type2> a2)
bool operator>(list<value_type1> a1, range<value_type2> a2)
bool operator<=(list<value_type1> a1, range<value_type2> a2)
bool operator>=(list<value_type1> a1, range<value_type2> a2)
bool operator==(range<value_type1> a1, list<value_type2> a2)
bool operator!=(range<value_type1> a1, list<value_type2> a2)
bool operator<(range<value_type1> a1, list<value_type2> a2)
bool operator>(range<value_type1> a1, list<value_type2> a2)
bool operator<=(range<value_type1> a1, list<value_type2> a2)
bool operator>=(range<value_type1> a1, list<value_type2> a2)

Compares an list to a range by comparing each element from the beginning until a difference is found.

Examples

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

using namespace core;

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

Simple Containers

Standard Containers

Interface Containers

Specialized Containers

Input/Output

Algorithm

Clone this wiki locally