[range.h] rename to run.h

This commit is contained in:
Joe Thornber
2013-05-28 11:51:44 +01:00
parent bde2b2b40d
commit 83d6b609eb
6 changed files with 5 additions and 5 deletions

59
persistent-data/run.h Normal file
View File

@ -0,0 +1,59 @@
#ifndef PERSISTENT_DATA_RANGE_H
#define PERSISTENT_DATA_RANGE_H
#include <boost/optional.hpp>
#include <ostream>
//----------------------------------------------------------------
namespace base {
template <typename T>
class range {
public:
typedef boost::optional<T> maybe;
explicit range(maybe begin = maybe(), maybe end = maybe())
: begin_(begin),
end_(end) {
}
bool operator ==(range<T> const &r) const {
return (begin_ == r.begin_ && end_ == r.end_);
}
bool contains(T const &v) const {
if (begin_ && v < *begin_)
return false;
if (end_ && v >= *end_)
return false;
return true;
}
maybe begin_;
maybe end_;
};
template <typename T>
std::ostream &
operator <<(std::ostream &out, range<T> const &r) {
if (r.begin_)
out << "[" << *r.begin_;
else
out << "[-";
out << ", ";
if (r.end_)
out << *r.end_ << "]";
else
out << "-]";
return out;
}
}
//----------------------------------------------------------------
#endif