|
Boost : |
From: Neal Becker (ndbecker2_at_[hidden])
Date: 2006-05-30 12:38:14
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. It's
quite clear (to me) that this is an important use of the range concept. In
the meantime, here's a workaround:
template<class T>
inline T& lvalue_cast (const T& rvalue) {
return const_cast<T&> (rvalue);
}
template<typename in_t, typename out_t>
void copy (in_t const& in, out_t &out) {}
int main() {
std::vector<int> out (2);
copy (boost::sub_range<std::vector<int> > (out.begin(), out.begin()+2),
lvalue_cast (boost::sub_range<std::vector<int> > (out.begin(),
out.begin()+2)));
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk