Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

cons

Description

cons is a simple Forward Sequence. It is a lisp style recursive list structure where car is the head and cdr is the tail: usually another cons structure or nil: the empty list. Fusion's list is built on top of this more primitive data structure. It is more efficient than vector when the target sequence is constructed piecemeal (a data at a time). The runtime cost of access to each element is peculiarly constant (see Recursive Inlined Functions).

Header
#include <boost/fusion/sequence/container/list/cons.hpp>
Synopsis
template <typename Car, typename Cdr = nil>
struct cons;
Template parameters

Parameter Description Default
Car Head type  
Cdr Tail type nil
Model of

Notation

nil
An empty cons
C
A cons type
l, l2
Instances of cons
car
An arbitrary data
cdr
Another cons list
s
A Forward Sequence
N
An Integral Constant
Expression Semantics

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

Expression Semantics
nil() Creates an empty list.
C() Creates a cons with default constructed elements.
C(car) Creates a cons with car head and default constructed tail.
C(car, cdr) Creates a cons with car head and cdr tail.
C(s) Copy constructs a cons from a Forward Sequence, s.
l = s Assigns to a cons, l, from a Forward Sequence, s.
at<N>(l) The Nth element from the beginning of the sequence; see at.

note at<N>(l) is provided for convenience and compatibility with the original Boost.Tuple library, despite cons being a Forward Sequence only (at is supposed to be a Random Access Sequence requirement). The runtime complexity of at is constant (see Recursive Inlined Functions).

Example
cons<int, cons<float> > l(12, cons<float>(5.5f));
std::cout << at<0>(l) << std::endl;
std::cout << at<1>(l) << std::endl;
Copyright © 2001-2005 Joel de Guzman, Dan Marsden

PrevUpHomeNext