From 6ece3a7e5985e4bf5ff1f8eb9d0680647d00c4c6 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Mon, 9 Feb 2004 09:04:52 -0500 Subject: [PATCH] random fixes base/range.hh: Add a constructor that takes the beginning and end as arguments size returns T not a bool quick make_range() function that is a shortcut for making a range kinda like make_pair() quick formatting fix --HG-- extra : convert_revision : 94b1d462710e6fb55e72e1da2ad8c46993af1ef7 --- base/range.hh | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/base/range.hh b/base/range.hh index 34bd34136..d72aa9755 100644 --- a/base/range.hh +++ b/base/range.hh @@ -62,6 +62,10 @@ struct Range invalidate(); } + Range(T first, T second) + : start(first), end(second) + {} + template Range(const Range &r) : start(r.start), end(r.end) @@ -100,11 +104,18 @@ struct Range } void invalidate() { start = 0; end = 0; } - bool size() const { return end - start; } + T size() const { return end - start; } bool valid() const { return start < end; } }; -template +template +inline Range +make_range(T start, T end) +{ + return Range(start, end); +} + +template inline std::ostream & operator<<(std::ostream &o, const Range &r) { @@ -124,7 +135,7 @@ operator<<(std::ostream &o, const Range &r) * @param range2 is a range. * @return if range1 and range2 are identical. */ -template +template inline bool operator==(const Range &range1, const Range &range2) { @@ -137,7 +148,7 @@ operator==(const Range &range1, const Range &range2) * @param range2 is a range. * @return if range1 and range2 are not identical. */ -template +template inline bool operator!=(const Range &range1, const Range &range2) { @@ -150,7 +161,7 @@ operator!=(const Range &range1, const Range &range2) * @param range2 is a range. * @return if range1 is less than range2 and does not overlap range1. */ -template +template inline bool operator<(const Range &range1, const Range &range2) { @@ -164,7 +175,7 @@ operator<(const Range &range1, const Range &range2) * @return if range1 is less than range2. range1 may overlap range2, * but not extend beyond the end of range2. */ -template +template inline bool operator<=(const Range &range1, const Range &range2) { @@ -177,7 +188,7 @@ operator<=(const Range &range1, const Range &range2) * @param range2 is a range. * @return if range1 is greater than range2 and does not overlap range2. */ -template +template inline bool operator>(const Range &range1, const Range &range2) { @@ -191,7 +202,7 @@ operator>(const Range &range1, const Range &range2) * @return if range1 is greater than range2. range1 may overlap range2, * but not extend beyond the beginning of range2. */ -template +template inline bool operator>=(const Range &range1, const Range &range2) { @@ -209,7 +220,7 @@ operator>=(const Range &range1, const Range &range2) * @param range range compared against. * @return indicates that position pos is within the range. */ -template +template inline bool operator==(const T &pos, const Range &range) { @@ -222,7 +233,7 @@ operator==(const T &pos, const Range &range) * @param range range compared against. * @return indicates that position pos is not within the range. */ -template +template inline bool operator!=(const T &pos, const Range &range) { @@ -235,7 +246,7 @@ operator!=(const T &pos, const Range &range) * @param range range compared against. * @return indicates that position pos is below the range. */ -template +template inline bool operator<(const T &pos, const Range &range) { @@ -248,7 +259,7 @@ operator<(const T &pos, const Range &range) * @param range range compared against. * @return indicates that position pos is below or in the range. */ -template +template inline bool operator<=(const T &pos, const Range &range) { @@ -261,7 +272,7 @@ operator<=(const T &pos, const Range &range) * @param range range compared against. * @return indicates that position pos is above the range. */ -template +template inline bool operator>(const T &pos, const Range &range) { @@ -274,7 +285,7 @@ operator>(const T &pos, const Range &range) * @param range range compared against. * @return indicates that position pos is above or in the range. */ -template +template inline bool operator>=(const T &pos, const Range &range) { @@ -292,7 +303,7 @@ operator>=(const T &pos, const Range &range) * @param pos position compared to the range. * @return indicates that position pos is within the range. */ -template +template inline bool operator==(const Range &range, const U &pos) { @@ -305,7 +316,7 @@ operator==(const Range &range, const U &pos) * @param pos position compared to the range. * @return indicates that position pos is not within the range. */ -template +template inline bool operator!=(const Range &range, const U &pos) { @@ -318,7 +329,7 @@ operator!=(const Range &range, const U &pos) * @param pos position compared to the range. * @return indicates that position pos is above the range. */ -template +template inline bool operator<(const Range &range, const U &pos) { @@ -331,7 +342,7 @@ operator<(const Range &range, const U &pos) * @param pos position compared to the range. * @return indicates that position pos is above or in the range. */ -template +template inline bool operator<=(const Range &range, const U &pos) { @@ -344,7 +355,7 @@ operator<=(const Range &range, const U &pos) * @param pos position compared to the range. * 'range > pos' indicates that position pos is below the range. */ -template +template inline bool operator>(const Range &range, const U &pos) { @@ -357,7 +368,7 @@ operator>(const Range &range, const U &pos) * @param pos position compared to the range. * 'range >= pos' indicates that position pos is below or in the range. */ -template +template inline bool operator>=(const Range &range, const U &pos) { -- 2.30.2