
Thorsten Ottosen wrote:
Neal Becker wrote:
Thorsten Ottosen wrote:
Neal Becker wrote:
#include <boost/range.hpp> #include <vector>
template<typename in_t, typename out_t> void copy (in_t const& in, out_t &out) {}
What makes you think you can bind a temporary to an non-const reference (out)?
Yeah, same old problem. I think the c+ standard should be changed.
Well, && will help some.
It's quite clear (to me) that this is an important use of the range concept.
I think the algorothm is wrong in this case. I would go for
template< class SinglePassRange, class WritableForwardRange > void overwrite( const SinglePassRange&, WriteForwardRange& );
template< class SinglePassRange, class WritableForwardRange > void overwrite( const SinglePassRange&, const WriteForwardRange& );
Did you mean something like this? --------------------------- #include <boost/range.hpp> #include <algorithm> #include <vector> template<typename in_t, typename out_t> void copy (in_t const& in, out_t const& out) { std::copy (boost::begin (in), boost::end (in), boost::begin (out)); } int main() { std::vector<int> out (2); copy (boost::sub_range<std::vector<int> > (out.begin(), out.begin()+2), boost::sub_range<std::vector<int> > (out.begin(), out.begin()+2)); } ----------------------------- Doesn't work, of course. The call to '::copy' now matches but this doesn't solve the basic problem: g++ -o wrap.x86_64/test.os -c -g -DNDEBUG -DBOOST_DISABLE_THREADS -O3 -ftree-vectorize -ffast-math -fstrict-aliasing -Wall -fPIC -Isrc -I/usr/local/src/boost.cvs -I/usr/include/python2.4 -Isrc-fixed -Isrc wrap/test.cc /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_algobase.h: In function '_OI std::__copy_aux(_II, _II, _OI) [with _II = const int*, _OI = const int*]': /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_algobase.h:354: instantiated from 'static _OI std::__copy_normal<true, true>::copy_n(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >, _OI = __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >]' /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_algobase.h:387: instantiated from '_OutputIterator std::copy(_InputIterator, _InputIterator, _OutputIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >, _OutputIterator = __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >]' wrap/test.cc:12: instantiated from 'void copy(const in_t&, const out_t&) [with in_t = boost::sub_range<std::vector<int, std::allocator<int> > >, out_t = boost::sub_range<std::vector<int, std::allocator<int> > >]' wrap/test.cc:20: instantiated from here /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_algobase.h:317: error: no matching function for call to 'std::__copy<true, std::random_access_iterator_tag>::copy(const int*&, const int*&, const int*&)'