|
Boost : |
From: nbecker_at_[hidden]
Date: 2002-02-18 09:55:50
I'd like to see something like this added as well:
------------ring.hpp
#ifndef RING_HPP
#define RING_HPP
#include "cycle_iterator.hpp"
template<class Container>
class Ring {
public:
typedef typename Container::value_type value_type;
Ring (int size) :
c (size),
i (boost::make_cycle_iterator (c.begin(), c.end()))
{}
void Advance (int d) {
i += d;
}
value_type& operator[] (int offset) {
return *(i+offset);
}
const value_type& operator[] (int offset) const {
return *(i+offset);
}
private:
Container c;
boost::cycle_iterator_generator<typename Container::iterator>::type i;
};
-------TestRing.cc
#include "ring.hpp"
#include <vector>
#include <iostream>
int main() {
Ring<std::vector<int> > r (10);
for (int i = 0; i < 10; i++)
r[i] = i;
r.Advance (-1);
for (int i = 0; i < 10; i++)
std::cout << r[i] << ' ' ;
std::cout << '\n';
r.Advance (2);
for (int i = 0; i < 10; i++)
std::cout << r[i] << ' ' ;
std::cout << '\n';
}
#endif
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk