16 constexpr static size_t INFINITE = std::numeric_limits<size_t>::max();
19 std::optional<size_t> upperBound;
21 constexpr size_t expectedResultSize(
size_t min = 0)
const {
return std::min(min, upperBound.value_or(lowerBound)); }
23 constexpr SizeHint(
size_t lowerBound = 0, std::optional<size_t> upperBound = {}) : lowerBound(lowerBound), upperBound(upperBound) {}
25 static constexpr std::optional<size_t> upperBoundMax(std::optional<size_t> upperBound1, std::optional<size_t> upperBound2) {
26 if(!upperBound1.has_value() || !upperBound2.has_value()) {
return {}; }
27 return std::max(upperBound1.value(), upperBound2.value());
29 static constexpr std::optional<size_t> upperBoundMin(std::optional<size_t> upperBound1, std::optional<size_t> upperBound2) {
30 if(!upperBound1.has_value()) {
return upperBound2; }
31 if(!upperBound2.has_value()) {
return upperBound1; }
32 return std::min(upperBound1.value(), upperBound2.value());
34 void subtract(
size_t cnt) {
35 lowerBound = (lowerBound > cnt) ? (lowerBound - cnt) : 0;
37 upperBound = (upperBound.value() > cnt) ? (upperBound.value() - cnt) : 0;
41 lowerBound += o.lowerBound;
42 if(upperBound.has_value() && o.upperBound.has_value()) {
43 upperBound = upperBound.value() + o.upperBound.value();
Structure holding the bounds of a CXXIter iterator's estimated length.