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 an old version of boost. Click here for the latest version's documentation home page.

[Home]copy

Synopsis

template<
      typename Sequence
    , typename State
    , typename BinaryOp
    >
struct copy
{
    typedef unspecified type;
};

Description

copy is, in fact, just another name for fold. It was introduced for symmetry with copy_if [1], and because it's a nice name for one of the typical fold applications, that is, copying the content of one sequence into another - see the example below.

Definition

#include "boost/mpl/copy.hpp"

Parameters

 Parameter  Requirement  Description  
SequenceA model of SequenceA sequence to iterate.
StateA typeThe initial state for the first BinaryOp application.
BinaryOpA model of [Lambda Function]The operation to be executed on forward traversal.

Expression semantics

 Expression  Expression type  Precondition  Semantics  Postcondition 
typedef copy<Sequence,T,Op>::type s;A typeEquivalent to typedef fold< Sequence,T,Op >::type s;.

Complexity

Linear. Exactly size<Sequence>::type::value applications of BinaryOp.

Example

typedef vector_c<int,0,1,2,3,4,5,6,7,8,9> numbers;
typedef copy<
      range_c<int,10,20>
    , numbers
    , push_back<_,_>
    >::type result;

BOOST_STATIC_ASSERT(size<result>::value == 20); BOOST_STATIC_ASSERT((equal< result,range_c<int,0,20> >::type::value));

Notes

[1] In case if you wonder why copy_if, in its turn, wasn't just called fold_if, - something that would allow to eliminate the family of copy algorithms completely - these two have quite different semantics.

See also

Algorithms, copy_if, copy_backward, copy_backward_if, fold, fold_backward


Table of Contents
Last edited May 20, 2003 1:36 am