C++

'std::equal_range' Is Not a Member of 'std' Fix

std::equal_range lives in one header, <algorithm> - and on this library version almost no ordinary file rescues it by accident: in the sweep probed here only <functional> and <chrono> pull the name in on the side, and the textbook combination of <iostream> and <vector> does not. The error therefore surfaces in textbook files as well as lean ones, and in the sweep probed here it splits by compile result only two ways - the plain error, with no suggestion tail, no note lines, and no help lines in any probed failing context, or one of those two transitive rescues - with no link-failure shape behind any probed header. This guide pins down both outcomes, which probed headers cause each one, and the one include that fixes the error by specification.

Written December 1, 2026 · Tested with GCC 13.3.0 · 19 min read

By the end of this guide
  • The error: the include is missing, in a lean file
  • A neighboring header does not rescue it: only &lt;utility&gt;
  • The textbook version fails too - plainly, with no suggestion
  • Neighboring headers: which ones fail, which ones rescue it

Written December 1, 2026

Tested with GCC 13.3.0

What this guide is

std::equal_range is a function template defined in the header <algorithm>, since C++98. It takes a range [first, last), which needs only to be partitioned with respect to value and is usually sorted, and a value, and returns a std::pair of iterators bracketing every element equivalent to value: the first member is the first element not ordered before value - the std::lower_bound result - and the second member is the first element ordered after value - the std::upper_bound result - or last for either member if no such element exists. The default overload orders by operator< (by std::less{} since C++20); a second overload takes a comparator comp and orders by comp instead. Both overloads are constexpr since C++20, and each makes at most 2log2(N)+O(1) comparisons for a range of N elements. Where the two bounds agree, the value is absent and the pair marks the position where it would sit; where they differ, every element between them is equivalent to the value.

Because the template lives in one specific header, 'equal_range' is not a member of 'std' has one common cause:

  • The #include <algorithm> line is missing, and no other header in the file pulls the name in transitively. For this error, in the contexts probed here, GCC prints no note naming <algorithm>, no suggestion on the error line, no note lines, and no help lines, so the fix has to come from knowing the name's home, not from reading a diagnostic tail. The neighboring names probed here - std::lower_bound, std::upper_bound, and std::binary_search, all in the same header - are silent the same way in the same lean context, as the neighboring-names section shows.

What makes this error worth separating from its relatives is the shape of the sweep behind it. In the sweep probed here the outcome splits by compile result only two ways - the plain compile error, or a transitive rescue - and the rescue side is unusually small: only two probed headers besides <algorithm> itself rescue this name. The error is also plainer than its closest sibling's: std::upper_bound, probed in its own guide, picks up a did you mean 'lower_bound'? suggestion in eleven probed contexts, while among the probed headers here std::equal_range picks up no suggestion anywhere, not even in the textbook file. The older siblings in this family - std::lower_bound, std::upper_bound, std::sort, and std::find - have their own guides and are linked at the end, not re-taught here.

The error: the include is missing, in a lean file

This program searches a sorted array for the elements equal to 5 with std::equal_range and checks that the returned pair spans 2 elements, but includes only <limits>:

C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    auto r = std::equal_range(a, a + 6, 5);
    return r.second - r.first == 2 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:4:19: error: 'equal_range' is not a member of 'std'
    4 |     auto r = std::equal_range(a, a + 6, 5);
      |                   ^~~~~~~~~~~

That is the whole output: one error, no suggestion on the error line, no note lines, no help lines. The same program with no include at all fails the same way:

C++
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    auto r = std::equal_range(a, a + 6, 5);
    return r.second - r.first == 2 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:19: error: 'equal_range' is not a member of 'std'
    3 |     auto r = std::equal_range(a, a + 6, 5);
      |                   ^~~~~~~~~~~

A neighboring header does not rescue it: only <utility>

A reader coming from the std::swap error might reach for <utility> first - and for this name there is a second reason to try it, since <utility> is the header that declares the std::pair this function returns. In the program probed here it changes nothing - the same plain error, at the same position:

C++
#include <utility>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    auto r = std::equal_range(a, a + 6, 5);
    return r.second - r.first == 2 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 u_utility.cpp -o u_utility_prog
u_utility.cpp: In function 'int main()':
u_utility.cpp:4:19: error: 'equal_range' is not a member of 'std'
    4 |     auto r = std::equal_range(a, a + 6, 5);
      |                   ^~~~~~~~~~~

That is expected once the homes are separated: <utility> declares std::swap and std::pair, and std::equal_range is not one of its names. The return type's header does not declare the function that returns it, and the fix below is <algorithm>, not the swap fix.

The textbook version fails too - plainly, with no suggestion

The version most often written first - search a vector and print both bounds around the elements equal to 5, with std::cout - gets the same error, without <algorithm>:

C++
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 4, 5, 5, 6};
    auto r = std::equal_range(v.begin(), v.end(), 5);
    std::cout << (r.first - v.begin()) << " " << (r.second - v.begin()) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:19: error: 'equal_range' is not a member of 'std'
    5 |     auto r = std::equal_range(v.begin(), v.end(), 5);
      |                   ^~~~~~~~~~~

What happened: on this library version, neither <vector> nor <iostream> pulls this name in transitively, so the call fails in a textbook file just as it does in a lean one. The error is also exactly as plain here as in the lean file: there is no did you mean tail on the error line, no note lines, and no help lines. That is a real contrast with the sibling error - in the same textbook context, std::upper_bound gets a did you mean 'lower_bound'? suggestion, because that neighboring name is visible there - while among the probed headers no context gives std::equal_range any suggestion at all. Do not wait for a suggestion to point the way: the fix for the name the program means is the include below. In the sweep probed here, the only headers that rescue std::equal_range are <functional> and <chrono>, besides <algorithm> itself, and that rescue is a property of this library version, not a rule of the language. A program that uses std::equal_range includes <algorithm>, whether or not it happens to compile without it.

Neighboring headers: which ones fail, which ones rescue it

In a sweep where each header below was compiled as the only header in a program that searches a sorted array for the elements equal to 5 and returns whether the returned pair starts at index 3 and ends at index 5, the outcome splits by compile result two ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines - and these headers fail with the plain is not a member of 'std' error, with no suggestion, no note, and no help:

  • <limits>
  • <cstring>
  • <cstdint>
  • <cstddef>
  • <initializer_list>
  • <version>
  • <climits>
  • <cctype>
  • <new>
  • <typeinfo>
  • <type_traits>
  • <compare>
  • <concepts>
  • <ratio>
  • <bit>
  • <optional>
  • <numeric>
  • <tuple>
  • <mutex>
  • <exception>
  • <utility>
  • <vector>
  • <string>
  • <iostream>
  • <memory>
  • <array>
  • <map>
  • <set>
  • <thread>
  • <stdexcept>
  • <iterator>
  • <system_error>

A file with no include at all fails the same way. And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:

  • <algorithm>
  • <functional>
  • <chrono>

Two contrasts with the neighboring sweeps are worth holding on to. First, the split here is two-way: in the sweep probed here, every failing sole header fails at compile time with the plain error - each one was also compiled to an object file on its own, and that step failed the same way - so the declared-but-not-defined link failure that std::swap produces behind five headers has no counterpart for this name in the probed set. Second, there is no suggestion class in this sweep at all: the eleven headers that add a did you mean 'lower_bound'? tail to the std::upper_bound error - <vector>, <string>, <iostream>, <memory>, <array>, <map>, <set>, <thread>, <stdexcept>, <iterator>, and <system_error> - fail plainly here, exactly like <limits> does. The rescue list, though, matches the short lists in this family: <algorithm> - the home header - is on this list by definition, not by transitivity, and every other rescue on that list is this library version's behavior, not a guarantee.

The fix

Add the header:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 4, 5, 5, 6};
    auto r = std::equal_range(v.begin(), v.end(), 5);
    std::cout << (r.first - v.begin()) << " " << (r.second - v.begin()) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
3 5

One include, <algorithm>, declares the template. In the sorted vector 1, 2, 4, 5, 5, 6 the two copies of 5 sit at indexes 3 and 4, so the returned pair runs from index 3 to index 5 and the program prints 3 5.

The fixed programs: both bounds across the range

With <algorithm> added, std::equal_range answers for values below, inside, and above the range. In the same sorted vector, the pair for 0 is 0 0 - both bounds at the front, the value absent - the pair for 2 is 1 2, the pair for 5 is 3 5 - bracketing both copies of 5 - and the pair for 6 is 5 6:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 4, 5, 5, 6};
    for (int x : {0, 2, 5, 6}) { auto r = std::equal_range(v.begin(), v.end(), x); std::cout << (r.first - v.begin()) << " " << (r.second - v.begin()) << " "; }
    std::cout << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 i_cases.cpp -o i_cases_prog
$ ./i_cases_prog
0 0 1 2 3 5 5 6 

Dereferencing the first member gives the first equal element itself, the distance between the members counts the equal elements, and a search for an absent value returns an empty pair - its two members equal. The first element equal to 5 is 5, the pair for 5 spans 2 elements, and the pair for 3 is empty - printed as 1, for true:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 4, 5, 5, 6};
    auto r = std::equal_range(v.begin(), v.end(), 5);
    auto e = std::equal_range(v.begin(), v.end(), 3);
    std::cout << *r.first << " " << (r.second - r.first) << " " << (e.first == e.second) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_values.cpp -o k_values_prog
$ ./k_values_prog
5 2 1

The comparator overload orders by the comparator instead of operator<. With std::greater<int> the range is written in descending order - 6, 5, 5, 4, 2, 1 - and the pair for 5 under that reversed ordering runs from index 1 to index 3, past both copies of 5, while the pair for the absent value 3 is the empty pair at index 4:

C++
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {6, 5, 5, 4, 2, 1};
    auto r = std::equal_range(v.begin(), v.end(), 5, std::greater<int>());
    auto s = std::equal_range(v.begin(), v.end(), 3, std::greater<int>());
    std::cout << (r.first - v.begin()) << " " << (r.second - v.begin()) << " " << (s.first - v.begin()) << " " << (s.second - v.begin()) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_comp.cpp -o j_comp_prog
$ ./j_comp_prog
1 3 4 4

The neighboring names: same header, same silence

The binary-search names that std::equal_range combines share its home header and its silence. std::lower_bound - the function template defined in <algorithm> that returns an iterator to the first element not less than the value, and the source of this function's first member - gets its own error, again with no header note:

C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    return std::lower_bound(a, a + 6, 5) - a == 3 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 b_lower.cpp -o b_lower_prog
b_lower.cpp: In function 'int main()':
b_lower.cpp:4:17: error: 'lower_bound' is not a member of 'std'
    4 |     return std::lower_bound(a, a + 6, 5) - a == 3 ? 0 : 1;
      |                 ^~~~~~~~~~~

std::upper_bound - the function template defined in <algorithm> that returns an iterator to the first element greater than the value, and the source of this function's second member - fails the same way:

C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    return std::upper_bound(a, a + 6, 5) - a == 5 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 c_upper.cpp -o c_upper_prog
c_upper.cpp: In function 'int main()':
c_upper.cpp:4:17: error: 'upper_bound' is not a member of 'std'
    4 |     return std::upper_bound(a, a + 6, 5) - a == 5 ? 0 : 1;
      |                 ^~~~~~~~~~~

std::binary_search - the function template defined in <algorithm> that reports whether an element equal to the value is present - fails the same way:

C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    return std::binary_search(a, a + 6, 5) ? 0 : 1;
}
Terminal
$ g++ -std=c++20 d_binary.cpp -o d_binary_prog
d_binary.cpp: In function 'int main()':
d_binary.cpp:4:17: error: 'binary_search' is not a member of 'std'
    4 |     return std::binary_search(a, a + 6, 5) ? 0 : 1;
      |                 ^~~~~~~~~~~~~

One contrast is worth holding on to: in the lean programs here, equal_range, lower_bound, upper_bound, and binary_search all get no note and no suggestion. Do not read the absence of a diagnostic tail as a puzzle to solve - in this probed set the tail is simply absent for this header's names in this context, and the fix comes from the names' home, <algorithm>.

The neighboring names, fixed

And the neighboring names work under the same one added header: std::lower_bound for 5 sits at index 3, std::upper_bound for 5 sits at index 5 - the two members of the pair this guide's function returns - std::binary_search reports 5 present - printed as 1 - and 3 absent - printed as 0:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 4, 5, 5, 6};
    std::cout << std::lower_bound(v.begin(), v.end(), 5) - v.begin() << " " << std::upper_bound(v.begin(), v.end(), 5) - v.begin() << " " << std::binary_search(v.begin(), v.end(), 5) << " " << std::binary_search(v.begin(), v.end(), 3) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_neighbors_fixed.cpp -o k_neighbors_fixed_prog
$ ./k_neighbors_fixed_prog
3 5 1 0

Since C++20 the same <algorithm> header also declares std::ranges::equal_range, the ranges form of the same search. With <algorithm> included it takes the range itself instead of an iterator pair and returns a subrange running from index 3 to index 5 for the value 5; in the lean context - only <limits> included - it fails with its own wording, 'std::ranges' has not been declared, because the namespace itself is not declared there:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 4, 5, 5, 6};
    auto r = std::ranges::equal_range(v, 5);
    std::cout << (r.begin() - v.begin()) << " " << (r.end() - v.begin()) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
3 5
C++
#include <limits>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    auto r = std::ranges::equal_range(a, 5);
    return r.end() - r.begin() == 2 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 r2_ranges_lean.cpp -o r2_ranges_lean_prog
r2_ranges_lean.cpp: In function 'int main()':
r2_ranges_lean.cpp:4:19: error: 'std::ranges' has not been declared
    4 |     auto r = std::ranges::equal_range(a, 5);
      |                   ^~~~~~

A different wording - and a case where the qualifier is not needed

Including <algorithm> is not the only half of the name - but for this function the unqualified form behaves two ways, and which one a program gets depends on its arguments. This program includes the header, drops the std:: qualifier, and passes raw pointers into a C array:

C++
#include <algorithm>
int main() {
    int a[] = {1, 2, 4, 5, 5, 6};
    auto r = equal_range(a, a + 6, 5);
    return r.second - r.first == 2 ? 0 : 1;
}
Terminal
$ g++ -std=c++20 g2_unqualified_ptr.cpp -o g2_unqualified_ptr_prog
g2_unqualified_ptr.cpp: In function 'int main()':
g2_unqualified_ptr.cpp:4:14: error: 'equal_range' was not declared in this scope
    4 |     auto r = equal_range(a, a + 6, 5);
      |              ^~~~~~~~~~~
g2_unqualified_ptr.cpp:4:14: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:61,
                 from g2_unqualified_ptr.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:2202:5: note:   'std::equal_range'
 2202 |     equal_range(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:2195:37: note:   'std::ranges::equal_range'
 2195 |   inline constexpr __equal_range_fn equal_range{};
      |                                     ^~~~~~~~~~~

That wording - was not declared in this scope - is a different defect with a different fix: the header is present, the qualifier is not, and raw pointers belong to no namespace, so no lookup finds the name. Here the suggestions do name the right names - the first points at std::equal_range itself, in the internal header the transcript names, and the second at std::ranges::equal_range. Qualify the name as std::equal_range; adding includes does not bring the name out of namespace std.

The same unqualified call with std::vector iterators as its arguments behaves differently - it compiles and runs, printing 3 5:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {1, 2, 4, 5, 5, 6};
    auto r = equal_range(v.begin(), v.end(), 5);
    std::cout << (r.first - v.begin()) << " " << (r.second - v.begin()) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 g_unqualified.cpp -o g_unqualified_prog
$ ./g_unqualified_prog
3 5

What happened: the iterators belong to namespace std, so argument-dependent lookup finds std::equal_range from the arguments themselves, even without the qualifier. That is a property of the argument types, not a style to rely on: the same call over raw pointers fails, as the transcript above shows. Write the qualifier either way.

The exact rule

  • std::equal_range is declared by #include <algorithm>, and by no other header by rule. In the sweep probed here, <limits>, <cstring>, <cstdint>, <cstddef>, <initializer_list>, <version>, <climits>, <cctype>, <new>, <typeinfo>, <type_traits>, <compare>, <concepts>, <ratio>, <bit>, <optional>, <numeric>, <tuple>, <mutex>, <exception>, <utility>, <vector>, <string>, <iostream>, <memory>, <array>, <map>, <set>, <thread>, <stdexcept>, <iterator>, and <system_error> do not declare it, and neither does a file with no include at all.
  • 'equal_range' is not a member of 'std' means the <algorithm> include is missing and nothing else in the file pulled the name in - and, in the contexts probed here, GCC prints no note naming <algorithm>, no suggestion on the error line, no note lines, and no help lines under it, in the textbook context as well as the lean ones.
  • In the sweep probed here, the split by compile result is two-way: a sole header either fails with that plain compile error or rescues the program. Each failing sole header also failed when compiled to an object file on its own, so the probed set contains no declared-but-not-defined link-failure shape for this name.
  • In the sweep probed here, only two headers besides <algorithm> rescue std::equal_range transitively - <functional> and <chrono> - so a file whose only include is one of those compiles and runs the call without <algorithm>. That is this library version's behavior, not a guarantee - in the probed set, those headers are not required to pull std::equal_range in.
  • std::lower_bound, std::upper_bound, and std::binary_search are declared by the same #include <algorithm>: in the programs shown here, which include only <limits> beside the use, each gets its own is not a member of 'std' error when that include is missing, with no header note.
  • std::ranges::equal_range is declared by the same #include <algorithm> since C++20: with the include it searches the range passed to it, and in the lean context probed here it gets the error 'std::ranges' has not been declared when that include is missing.
  • 'equal_range' was not declared in this scope for an unqualified equal_range use over raw pointers is a different defect: qualify the name as std::equal_range - the include alone does not bring the name out of namespace std. The same unqualified use over std::vector iterators compiles in the program probed here through argument-dependent lookup; qualify the name there too, so the call does not depend on its argument types.

The fixes, ranked

  • First, check the include list of the file that names std::equal_range. If <algorithm> is not there, add it - that is the fix in the common case, and it holds whether the file failed at compile time or happened to compile before through a transitive rescue.
  • Second, do not wait for a diagnostic tail to name the fix. In the contexts probed here this error carries no suggestion, no note, and no help - take the fix from the name the program means and its home header, <algorithm>.
  • Third, do not reach for <utility> because the error sentence looks like the std::swap error, and do not expect it to help because this function returns a std::pair. In the program probed here, <utility> as the only include fails with the same plain error - the return type's header does not declare the function.
  • Fourth, do not be reassured by <iostream>, <vector>, or <string> being present - in the sweep here none of them rescues this name at all - and do not remove <algorithm> because a file compiles without it: in the probed set only <functional> and <chrono> rescue it, and that rescue is not guaranteed.
  • Fifth, if the error says was not declared in this scope instead, fix the name's qualifier to std::equal_range as well - and do not rely on an unqualified call that happens to compile over std iterators, because the same call over raw pointers fails.
  • Sixth, if the failing name is a neighboring one, check its header before fixing: lower_bound, upper_bound, and binary_search take the same added <algorithm>, while swap takes <utility>.

Which fix for which cause

  • #include <algorithm> missing, std::equal_range used in a file whose only include is <limits>, <cstring>, <cstdint>, <cstddef>, <initializer_list>, <version>, <climits>, <cctype>, <new>, <typeinfo>, <type_traits>, <compare>, <concepts>, <ratio>, <bit>, <optional>, <numeric>, <tuple>, <mutex>, <exception>, <utility>, <vector>, <string>, <iostream>, <memory>, <array>, <map>, <set>, <thread>, <stdexcept>, <iterator>, or <system_error>, or that includes nothing: the message is 'equal_range' is not a member of 'std', with no suggestion, no header note, and no help - add #include <algorithm>.
  • std::equal_range used in a textbook file including <iostream> and <vector>: the message is the same plain error, with no suggestion - add #include <algorithm>.
  • std::equal_range used with only <algorithm>, <functional>, or <chrono> included: no error on this library version - add #include <algorithm> anyway when it is not the include already present, because the rescue is not guaranteed.
  • std::lower_bound, std::upper_bound, or std::binary_search used without <algorithm> in the lean context: the message names that name, with no header note - add #include <algorithm>.
  • std::ranges::equal_range used without <algorithm> in the lean context: the message is 'std::ranges' has not been declared - add #include <algorithm>.
  • equal_range used without the std:: qualifier, <algorithm> included, over raw pointers: the message is 'equal_range' was not declared in this scope - qualify the name as std::equal_range. Over std::vector iterators the same unqualified call compiles through argument-dependent lookup in the program probed here - qualify it anyway.

Checklist

  • Check the include list of the file that names the search, not just the project. The include must be in that file, or in a header that file includes directly by design.
  • Do not wait for a note or a suggestion naming the header. For this error, in the contexts probed here, GCC prints neither for equal_range - take the fix from the name's home header, <algorithm>, instead.
  • Do not import the std::swap fix into this error, and do not expect the return type's header to declare the function: in the probed set, <utility> fails here the same plain way as <limits> does. Split neighboring names by home header first.
  • Do not assume the textbook includes rescue this name, and do not delete a working <algorithm> line because a file compiles without it. In the sweep here <iostream> and <vector> do not rescue std::equal_range at all, and the two headers that do rescue it do so only transitively.
  • One header per name the file uses: std::vector comes from <vector> and std::string from <string>, even in a program whose subject is the search - and std::equal_range comes from <algorithm> in return, while the std::pair it returns comes from <utility>.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 3 5 for the bounds around 5 in the sorted vector, and 5 2 1 for the dereferenced result, the equal-element count, and the empty-pair check.
  • 'std::lower_bound' Is Not a Member of 'std' Fix - the same missing-include shape for the lower binary-search bound in <algorithm>, the source of this function's first member: its sweep splits two ways like this guide's, but its rescue list is far longer, and its textbook file is rescued where this guide's is not.
  • 'std::upper_bound' Is Not a Member of 'std' Fix - the same missing-include shape for the upper binary-search bound in <algorithm>, the source of this function's second member: its sweep shares this guide's two transitive rescues, but its error picks up a did you mean 'lower_bound'? suggestion in eleven probed contexts where this guide's error stays plain everywhere probed.
  • 'std::sort' Is Not a Member of 'std' Fix - the same missing-include shape for the sorting function template in <algorithm>, an older sibling in this family whose own guide covers its error and its fix.
  • 'std::find' Is Not a Member of 'std' Fix - the same missing-include shape for the linear-search function template in <algorithm>, an older sibling in this family.

Sources

  • cppreference, std::equal_range — for std::equal_range being a function template defined in <algorithm> since C++98 that returns a std::pair of iterators whose first member is the first element not ordered before the value and whose second member is the first element ordered after the value, or last for either member if no such element exists, with one overload ordering by operator< (by std::less{} since C++20) and a second overload ordering by a comparator comp, both overloads constexpr since C++20, at most 2log2(N)+O(1) comparisons, and the range needing only to be partitioned with respect to value, though it is usually sorted.
  • cppreference, Standard library header <algorithm> — for <algorithm> being the header that declares std::equal_range and the neighboring algorithm names, including the std::ranges::equal_range algorithm function object since C++20.
  • cppreference, std::lower_bound — for std::lower_bound being a function template defined in <algorithm> that returns an iterator to the first element not less than the value.
  • cppreference, std::upper_bound — for std::upper_bound being a function template defined in <algorithm> that returns an iterator to the first element greater than the value.
  • cppreference, std::binary_search — for std::binary_search being a function template defined in <algorithm> that reports whether an element equal to the value is present in a sorted range.

Keep Exploring