3 // Copyright Neil Groves 2009. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/range/
10 #ifndef BOOST_RANGE_ALGORITHM_EXT_OVERWRITE_HPP_INCLUDED
11 #define BOOST_RANGE_ALGORITHM_EXT_OVERWRITE_HPP_INCLUDED
13 #include <boost/range/config.hpp>
14 #include <boost/range/concepts.hpp>
15 #include <boost/range/difference_type.hpp>
16 #include <boost/range/iterator.hpp>
17 #include <boost/range/begin.hpp>
18 #include <boost/range/end.hpp>
19 #include <boost/assert.hpp>
26 template< class SinglePassRange1, class SinglePassRange2 >
27 inline void overwrite( const SinglePassRange1& from, SinglePassRange2& to )
29 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
30 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange2> ));
32 BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type
33 i = boost::begin(from), e = boost::end(from);
35 BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type
36 out = boost::begin(to);
39 BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange2>::type
40 last_out = boost::end(to);
43 for( ; i != e; ++out, ++i )
46 BOOST_ASSERT( out != last_out
47 && "out of bounds in boost::overwrite()" );
53 template< class SinglePassRange1, class SinglePassRange2 >
54 inline void overwrite( const SinglePassRange1& from, const SinglePassRange2& to )
56 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange1> ));
57 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange2> ));
59 BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange1>::type
60 i = boost::begin(from), e = boost::end(from);
62 BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type
63 out = boost::begin(to);
66 BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange2>::type
67 last_out = boost::end(to);
70 for( ; i != e; ++out, ++i )
73 BOOST_ASSERT( out != last_out
74 && "out of bounds in boost::overwrite()" );
81 using range::overwrite;
84 #endif // include guard