Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
zip
Description

Zips sequences together to form a single sequence, whose members are tuples of the members of the component sequences.

Synopsis
template<
    typename Sequence1,
    typename Sequence2,
    ...
    typename SequenceN
    >
typename result_of::zip<Sequence1 const, Sequence2 const, ... SequenceN const>::type
zip(Sequence1 const& seq1, Sequence2 const& seq2, ... SequenceN const& seqN);

Table 1.81. Parameters

Parameter

Requirement

Description

seq1 to seqN

Each sequence is a model of Forward Sequence.

Operation's argument


Expression Semantics
zip(seq1, seq2, ... seqN);

Return type: A model of Forward Sequence.

Semantics: Returns a sequence containing tuples of elements from sequences seq1 to seqN. For example, applying zip to tuples (1, 2, 3) and ('a', 'b', 'c') would return ((1, 'a'),(2, 'b'),(3, 'c'))

Complexity

Constant. Returns a view which is lazily evaluated.

Header
#include <boost/fusion/algorithm/transformation/zip.hpp>
#include <boost/fusion/include/zip.hpp>
Example
vector<int,char> v1(1, 'a');
vector<int,char> v2(2, 'b');
assert(zip(v1, v2) == make_vector(make_vector(1, 2),make_vector('a', 'b'));

PrevUpHomeNext