|
Boost : |
From: Dan Gohman (gohmandj_at_[hidden])
Date: 2001-12-09 16:07:17
Here's a class that wraps std::list, acting just like std::list except
using the boost reverse iterators for rbegin and rend. One could wrap
other containers in a similar manner. The primary benefit is that the
boost reverse iterators handle interactions between const and non-const
iterators better, which makes them more convenient.
Would this be a useful thing, or should one just get in the habit of
using make_reverse_iterator all the time? The reverse iteration stuff
arguably doesn't belong in the container classes in the first place, so
maybe the make_reverse_iterator way is better after all.
#include <list>
#include <boost/iterator_adaptors.hpp>
template<class Type, class Alloc = std::allocator<Type> >
class list : public std::list<Type, Alloc> {
private:
typedef std::list<Type, Alloc> parent_type;
public:
typedef boost::reverse_iterator_generator<parent_type::iterator>::type reverse_iterator;
typedef boost::reverse_iterator_generator<parent_type::const_iterator>::type const_reverse_iterator;
list() {}
list(size_type n): parent_type(n) {}
list(size_type n, Type const& t): parent_type(n, t) {}
list(parent_type const& other): parent_type(other) {}
template<class InputIterator> list(InputIterator f, InputIterator l): parent_type(f, l) {}
reverse_iterator rbegin() { return reverse_iterator(parent_type::end()); }
reverse_iterator rend() { return reverse_iterator(parent_type::begin()); }
const_reverse_iterator rbegin() const { return reverse_iterator(parent_type::end()); }
const_reverse_iterator rend() const { return reverse_iterator(parent_type::begin()); }
};
-- Dan Gohman gohmandj_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk