template<class InputIterator, class OutputIterator>
OutputIterator copy (InputIterator first, InputIterator last, OutputIterator result)
{
while (first!=last) {
*result = *first;
++result; ++first;
}
return result;
}
// suppose you want to copy list to a vector
// instead of using a for loop, You can use to the std:: algorithm
// to keep the code cleaner
std::list <int> list;
std::vector <int> vector;
/// WARNING ---
/// YOU MUST ALLOCATE ENOUGH SPACE IN THE CONTAINER BEFORE COPY
vector.resize (list.size());
std::copy (list.begin(), list.end(), vector.begin());