# 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
--- | --- | ---
`Sequence` | A model of Sequence | A sequence to iterate.
`State` | A type | The initial state for the first `BinaryOp` application.
`BinaryOp` | A 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 type |  | Equivalent 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>
        , push_back<_,_>
        , numbers
        >::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 July 19, 2002 2:10 am