/* * Copyright (C) 1996-2018 The Squid Software Foundation and contributors * * Squid software is distributed under GPLv2+ license and includes * contributions from numerous individuals and organizations. * Please see the COPYING and CONTRIBUTORS files for details. */ #ifndef SQUID_RANGE_H #define SQUID_RANGE_H #include #include /* represents [start, end) */ template class Range { public: Range (); Range (C start_, C end_); C start; C end; Range intersection (Range const &) const; S size() const; }; template std::ostream& operator << (std::ostream &os, Range const &aRange) { os << "[" << aRange.start << "," << aRange.end << ")"; return os; } template Range::Range () : start(), end() {} template Range::Range (C start_, C end_) : start(start_), end(end_) {} template Range Range::intersection (Range const &rhs) const { Range result (max(start, rhs.start), min(end, rhs.end)); return result; } template S Range::size() const { return (S) (end > start ? end - start : 0); } #endif /* SQUID_RANGE_H */