/* * Copyright (C) 1996-2024 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_SRC_BASE_RANGE_H #define SQUID_SRC_BASE_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; bool contains(C 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 bool Range::contains(C const &value) const { assert(start <= end); return (start <= value && value <= end); } template S Range::size() const { return (S) (end > start ? end - start : 0); } #endif /* SQUID_SRC_BASE_RANGE_H */