The interface I chose preserves object lifetimes and prevents inadvertent mutation of temporary objects. Weakening its guarantees is a bad idea.
If you want the proxy to offer either a const or mutable interface *and* you want our proxy to work with BOOST_FOREACH, you should base it on the const-ness or mutability of the object being proxied, not the constness of the proxy itself. Consider:
template<class Range>Now, you can have const and mutable proxied objects like:
struct proxy {
typedef typename range_result_iterator<Range>::type iterator;
typedef typename range_result_iterator<Range>::type const_iterator;
iterator begin() const { return boost::begin(rng_); }
iterator end() const { return boost::end(rng_); }
// etc ...
Range &rng_;
};
// ok, a mutable proxy
proxy< std::vector<int> > p1;
// ok, still a mutable proxy
proxy< std::vector<int> > const p2;
// ok, a const proxy
proxy< std::vector<int> const > p3;
// still a const proxy
proxy< std::vector<int> const > const p4;
Комментариев нет:
Отправить комментарий