Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

deque

Description

deque is a simple Bidirectional Sequence that supports constant-time insertion and removal of elements at both ends. Like the list and cons, deque is more efficient than vector (especially at compile time) when the target sequence is constructed piecemeal (a data at a time, e.g. when constructing expression templates). Like the list and cons, runtime cost of access to each element is peculiarly constant (see Recursive Inlined Functions).

Element insertion and removal are done by special deque helper classes front_extended_deque and back_extended_deque.

Header
#include <boost/fusion/container/deque.hpp>
#include <boost/fusion/include/deque.hpp>
#include <boost/fusion/container/deque/deque_fwd.hpp>
#include <boost/fusion/include/deque_fwd.hpp>
Synopsis
template <typename ...Elements>
struct deque;

For C++11 compilers, the variadic class interface has no upper bound.

For C++03 compilers, the variadic class interface accepts 0 to FUSION_MAX_DEQUE_SIZE elements, where FUSION_MAX_DEQUE_SIZE is a user definable predefined maximum that defaults to 10. Example:

deque<int, char, double>

You may define the preprocessor constant FUSION_MAX_DEQUE_SIZE before including any Fusion header to change the default. Example:

#define FUSION_MAX_DEQUE_SIZE 20
Template parameters

Parameter

Description

Default

Elements

Element types

Model of

Notation

D

A deque type

d, d2

Instances of deque

e0...en

Heterogeneous values

s

A Forward Sequence

N

An MPL Integral Constant

Expression Semantics

Semantics of an expression is defined only where it differs from, or is not defined in Bidirectional Sequence.

Expression

Semantics

D()

Creates a deque with default constructed elements.

D(e0, e1,... en)

Creates a deque with elements e0...en.

D(s)

Copy constructs a deque from a Forward Sequence, s.

d = s

Assigns to a deque, d, from a Forward Sequence, s.

at<N>(d)

The Nth element from the beginning of the sequence; see at.

[Note] Note

at<N>(d) is provided for convenience, despite deque being a Bidirectional Sequence only (at is supposed to be a Random Access Sequence requirement). The runtime complexity of at is constant (see Recursive Inlined Functions). deque element access utilizes operator overloading with argument dependent lookup (ADL) of the proper element getter function given a static constant index parameter. Interestingly, with modern C++ compilers, this lookup is very fast and rivals recursive template instantiations in compile time-speed, so much so that deque relies on ADL for all element access (indexing) as well as iteration.

Example
deque<int, float> d(12, 5.5f);
std::cout << at_c<0>(d) << std::endl;
std::cout << at_c<1>(d) << std::endl;

PrevUpHomeNext