C++

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

std::equal lives in one header, <algorithm> - but in the sweep probed here, covering all 106 standard headers in this library's header set, 40 other headers pull it in on the side: the textbook <vector> program compiles without the include. Of the 65 headers that do fail, 64 fail with one plain line - and the one exception, <numeric>, offers a suggestion that names the wrong name, 'equal_to'. This guide pins down the failing shapes, the 40 transitive rescues, the classic form's blind spot for the second range's length, and the include that fixes it by rule.

Written December 3, 2026 · Tested with GCC 13.3.0 · 24 min read

By the end of this guide
  • The error: the include is missing
  • Neighboring headers: 64 fail plainly, one offers a wrong-name suggestion, and 40 rescue it by accident
  • The fix
  • What the call does: a yes-or-no answer over two ranges

Written December 3, 2026

Tested with GCC 13.3.0

What this guide is

std::equal is a function template defined in the header <algorithm>. It compares two ranges element by element and returns true when they hold the same elements in the same order, false otherwise: elements are compared with operator== unless the caller passes a predicate. The classic form takes the first range's two ends and only the second range's start, and treats the second range as ending exactly as far along as the first - its length is never checked. A bounded form that also takes the second range's end has existed since C++14 and checks the lengths as well. The classic call predates C++11, has an execution-policy overload since C++17, and has been usable in constant expressions since C++20.

Because the function lives in <algorithm> - not in a container's header - 'equal' is not a member of 'std' is the missing include, and naming that cause is the first step:

  • 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, that second clause often saves people by accident: in the sweep below, 40 of the other 105 headers in the library's header set pull the name in on the side, so many files without <algorithm> never reach this error - and a file that reaches it is usually one whose includes are all outside that rescue set, like the <limits> file in the next section.

And for this name the missing include is the only cause of the classic call's error. Some names in this family hide a second cause behind the same wording - a standard floor the name starts at - but std::equal predates C++11, so a file that includes <algorithm> compiles this call at every standard level probed here, C++98 included, as the versions section below shows. The pieces layered on top do have floors - the bounded form needs C++14, the execution-policy overload needs C++17, and constant-expression use needs C++20 - but those floors belong to the added pieces, not to the classic call.

This name's diagnostic is plain in almost every context probed here. In 64 of the 65 failing sole-header contexts probed here, the error is one plain line with no suggestion tail, no note lines, and no help lines. The one exception is <numeric>, and its suggestion names the wrong name: did you mean 'equal_to'? - std::equal_to is a function-object class template, the x == y object other algorithms use as a default predicate, not a function that compares two ranges. The sweep covers every one of the 106 standard headers in this library's header set, compiled as the only header in the program, and the outcome splits three ways - the plain failure, the one wrong-name suggestion, or a rescue - and the rescue set has 41 entries, because in this library the name is declared by a low-level header that much of the library includes.

The error: the include is missing

This program compares two three-element arrays, 1, 2, 3 and 1, 2, 3, but includes only <limits>:

C++
#include <limits>
int main() {
    int a[3] = {1, 2, 3};
    int b[3] = {1, 2, 3};
    std::equal(a, a + 3, b);
    return 0;
}
Output
-std=c++17 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:5:10: error: 'equal' is not a member of 'std'
    5 |     std::equal(a, a + 3, b);
      |          ^~~~~

Read it in full: one plain error line - no suggestion tail rides on it, there are no note lines, and there are no help lines. Nothing in the diagnostic names <algorithm> or points anywhere at all. The same program with no include at all fails the same way:

Output
-std=c++17 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:4:10: error: 'equal' is not a member of 'std'
    4 |     std::equal(a, a + 3, b);
      |          ^~~~~

The textbook version does not fail - and that is the trap

Trap
The version most often written first - compare two vectors and print the verdicts - produces no error at all in this library, without <algorithm>:
C++
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v1 = {1, 2, 3};
    std::vector<int> v2 = {1, 2, 3};
    std::vector<int> v3 = {1, 9, 3};
    std::cout << std::equal(v1.begin(), v1.end(), v2.begin()) << " " << std::equal(v1.begin(), v1.end(), v3.begin()) << "\n";
    return 0;
}
Terminal
-std=c++17 t_textbook.cpp -o t_textbook_prog
$ ./t_textbook_prog
1 0

It prints 1 0 - true for the identical pair, false for the pair that differs. Neither <iostream> nor <vector> is this name's home; the program compiles because <vector> pulls the declaring header in transitively in this library version. That rescue is exactly why this error surprises people when it finally appears: the same call, moved into a file whose includes are <limits>, <chrono>, or <numeric>, fails outright, and nothing about the call changed. A program that uses std::equal includes <algorithm>, whether or not it happens to compile without it. A sole <algorithm> file makes the point in miniature - the call compiles and runs with nothing else in sight:

Terminal
-std=c++17 i_algorithm.cpp -o i_algorithm_prog
$ ./i_algorithm_prog

Neighboring headers: 64 fail plainly, one offers a wrong-name suggestion, and 40 rescue it by accident

In a sweep where each of the 106 standard headers in this library's header set was compiled as the only header in a program that compares 1, 2, 3 with 1, 2, 3 and with 1, 9, 3 and checks that the answers are true and false, the outcome splits by compile result three ways - the failure in two diagnostic shapes, or a rescue. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 64 headers all fail with the plain is not a member of 'std' error line - no suggestion tail on that line, no note lines, and no help lines:

  • <any>
  • <atomic>
  • <barrier>
  • <bit>
  • <cassert>
  • <cctype>
  • <cerrno>
  • <cfenv>
  • <cfloat>
  • <charconv>
  • <chrono>
  • <cinttypes>
  • <ciso646>
  • <climits>
  • <clocale>
  • <compare>
  • <concepts>
  • <condition_variable>
  • <coroutine>
  • <csetjmp>
  • <csignal>
  • <cstdalign>
  • <cstdarg>
  • <cstdbool>
  • <cstddef>
  • <cstdint>
  • <cstdio>
  • <cstdlib>
  • <cstring>
  • <ctime>
  • <cuchar>
  • <cwchar>
  • <cwctype>
  • <exception>
  • <expected>
  • <format>
  • <initializer_list>
  • <iosfwd>
  • <latch>
  • <limits>
  • <mutex>
  • <new>
  • <numbers>
  • <optional>
  • <ranges>
  • <ratio>
  • <scoped_allocator>
  • <semaphore>
  • <shared_mutex>
  • <source_location>
  • <span>
  • <spanstream>
  • <stacktrace>
  • <stdfloat>
  • <stop_token>
  • <syncstream>
  • <thread>
  • <tuple>
  • <type_traits>
  • <typeindex>
  • <typeinfo>
  • <utility>
  • <variant>
  • <version>

A file with no include at all fails the plain way. Three entries deserve a pause. <limits> fails plainly: the header of the numeric limits declares nothing close enough to this name to trigger a guess. <ranges> fails plainly for the classic name too: the C++20 ranges library has its own equal name, and it does not bring this one in - that name gets its own section below. And one failing header is not on this list at all, because its failure is the sweep's only decorated shape. A file whose only include is <numeric> fails with a suggestion - and the suggestion is a trap of its own, because it names std::equal_to, a function object that compares two single values, not the range algorithm:

C++
#include <numeric>
int main() {
    int a[3] = {1, 2, 3};
    int b[3] = {1, 2, 3};
    std::equal(a, a + 3, b);
    return 0;
}
Output
-std=c++17 a_numeric.cpp -o a_numeric_prog
a_numeric.cpp: In function 'int main()':
a_numeric.cpp:5:10: error: 'equal' is not a member of 'std'; did you mean 'equal_to'?
    5 |     std::equal(a, a + 3, b);
      |          ^~~~~
      |          equal_to

Following that suggestion does not fix the program: std::equal_to is a class template whose instances answer x == y for one pair of values, and no call to it compares two ranges. It is offered in this one file because that name is visible there; in the other 64 failing files nothing close enough is declared, so no guess is offered at all - and no shape names <algorithm>.

And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:

  • <algorithm>
  • <array>
  • <bitset>
  • <ccomplex>
  • <cmath>
  • <codecvt>
  • <complex>
  • <ctgmath>
  • <deque>
  • <execution>
  • <filesystem>
  • <forward_list>
  • <fstream>
  • <functional>
  • <future>
  • <iomanip>
  • <ios>
  • <iostream>
  • <istream>
  • <iterator>
  • <list>
  • <locale>
  • <map>
  • <memory>
  • <memory_resource>
  • <ostream>
  • <queue>
  • <random>
  • <regex>
  • <set>
  • <sstream>
  • <stack>
  • <stdexcept>
  • <streambuf>
  • <string>
  • <string_view>
  • <system_error>
  • <unordered_map>
  • <unordered_set>
  • <valarray>
  • <vector>

The declaring header in this library sits underneath the container, stream, and iterator headers, so a large part of the library pulls it in on the side, and the rescue set runs to 40 transitive entries. That is also why the failing set is the smaller side here: with 65 of the other 105 headers failing, the missing include shows itself only in files whose includes avoid the whole container and stream family. <algorithm> - the home header - is on the rescue list by definition, not by transitivity, and the other 40 rescues are 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> v1 = {1, 2, 3};
    std::vector<int> v2 = {1, 2, 3};
    std::vector<int> v3 = {1, 9, 3};
    std::cout << std::equal(v1.begin(), v1.end(), v2.begin()) << " " << std::equal(v1.begin(), v1.end(), v3.begin()) << "\n";
    return 0;
}
Terminal
-std=c++17 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
1 0

One include, <algorithm>, declares the function - and the textbook program prints 1 0 again, this time by rule: the name is now declared by a header the file names itself, instead of by an internal include of one of the 40 rescuing headers that a different library version is free to rearrange. For a file that does fail - the <limits> shape above - the same one include is the whole fix.

What the call does: a yes-or-no answer over two ranges

The call returns one bool, and which inputs produce it is where this name's one real subtlety lives. Identical ranges report true; a single differing element reports false; a predicate decides what counts as matching; an empty first range matches anything; and - the subtlety - the classic form compares exactly as many elements as the first range has, so a first range that is a prefix of the second still reports true:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> a = {1, 2, 3};
    std::vector<int> b = {1, 2, 3};
    std::cout << "same " << std::equal(a.begin(), a.end(), b.begin()) << "\n";
    std::vector<int> c = {1, 9, 3};
    std::cout << "differ " << std::equal(a.begin(), a.end(), c.begin()) << "\n";
    std::vector<int> f = {1, 2};
    std::vector<int> g = {1, 2, 3, 4};
    std::cout << "prefix-classic " << std::equal(f.begin(), f.end(), g.begin()) << "\n";
    std::vector<int> h = {2, 4, 6};
    std::vector<int> i = {1, 2, 3};
    std::cout << "predicate " << std::equal(h.begin(), h.end(), i.begin(), [](int x, int y) { return x == 2 * y; }) << "\n";
    std::vector<int> mt;
    std::cout << "empty " << std::equal(mt.begin(), mt.end(), g.begin()) << "\n";
    return 0;
}
Terminal
-std=c++17 r_semantics.cpp -o r_semantics_prog
$ ./r_semantics_prog
same 1
differ 0
prefix-classic 1
predicate 1
empty 1

Read in order: the same line reports 1 - every element matches. The differ line reports 0: one position, the 2 against the 9, is enough. The prefix-classic line reports 1, and it is the line to remember: the classic form was never told where the second range ends, so it compares the first range's two elements, finds both matching, and stops - the extra 3, 4 in the second range are never looked at, and the ranges are reported equal even though their lengths differ. The predicate line reports 1: under a predicate that treats each first-range value as matching twice the second-range value, every position matches. The empty line reports 1: an empty first range has no position that could differ, so it matches any second range.

The bounded form: the second range gets an end too

The classic form trusts that the second range is at least as long as the first, and it cannot see a length difference at all. Since C++14 a bounded form takes the second range's end as well, and then the lengths are part of the answer:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> a = {1, 2, 3};
    std::vector<int> b = {1, 2};
    std::cout << "longer-first " << std::equal(a.begin(), a.end(), b.begin(), b.end()) << "\n";
    std::vector<int> c = {1, 2};
    std::vector<int> d = {1, 2, 9};
    std::cout << "longer-second " << std::equal(c.begin(), c.end(), d.begin(), d.end()) << "\n";
    std::vector<int> e = {1, 2};
    std::vector<int> f = {1, 2};
    std::cout << "same-length " << std::equal(e.begin(), e.end(), f.begin(), f.end()) << "\n";
    return 0;
}
Terminal
-std=c++17 r_bounded.cpp -o r_bounded_prog
$ ./r_bounded_prog
longer-first 0
longer-second 0
same-length 1

The longer-first line reports 0: the ranges agree for as far as the second range goes, but the lengths differ, and the bounded form counts that as inequality - the case the classic form above reported as 1. The longer-second line reports 0 the other way around. The same-length line reports 1: same length, same elements. The bounded form carries a real floor, and it shows in this library: compiled as C++11, the same four-iterator call fails, because at that standard the only four-argument form is the predicate form, and the second range's end is taken for a predicate and rejected inside it:

Output
-std=c++11 c_bounded_cpp11.cpp -o c_bounded_cpp11_prog
/usr/include/c++/13/bits/stl_algobase.h:1587:32: error: no match for call to '(__gnu_cxx::__normal_iterator<int*, std::vector<int> >) (int&, int&)'

So the bounded form is the one piece of this name with a floor below the policy overload: C++14, not C++17.

Input iterators: the weakest iterators it accepts

The reading side needs only input iterators - the weakest iterator category there is, the kind that reads each element once, in one pass. This program compares two text streams directly, through stream iterators that cannot be rewound or re-read:

C++
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
int main() {
    std::istringstream s1("1 2 3");
    std::istringstream s2("1 2 3");
    std::istringstream t1("1 2 3");
    std::istringstream s3("1 9 3");
    bool same = std::equal(std::istream_iterator<int>(s1), std::istream_iterator<int>(), std::istream_iterator<int>(s2));
    bool diff = std::equal(std::istream_iterator<int>(t1), std::istream_iterator<int>(), std::istream_iterator<int>(s3));
    std::cout << same << " " << diff << "\n";
    return 0;
}
Terminal
-std=c++17 r_input.cpp -o r_input_prog
$ ./r_input_prog
1 0

It reports 1 0 - the identical streams compare equal, the differing streams do not, read straight out of the streams. The policy overloads are the exception in the family: they ask for forward iterators, because a parallel execution may need to revisit the ranges.

Versions: no second cause for the classic call - it predates C++11

This call needs no modern-enough standard, and that is what separates it from some of its neighbors. std::equal predates C++11 - the cppreference page carries no "since" marker on the classic overloads. The fixed programs in this guide are compiled as C++17, but there is no floor below that to hit for the classic call: with <algorithm> included, the same comparison compiled as C++98 compiles and runs:

C++
#include <algorithm>
#include <iostream>
int main() {
    int a[3] = {1, 2, 3};
    int b[3] = {1, 2, 3};
    int c[3] = {1, 9, 3};
    std::cout << std::equal(a, a + 3, b) << " " << std::equal(a, a + 3, c) << "\n";
    return 0;
}
Terminal
-std=c++98 c_version98.cpp -o c_version98_prog
$ ./c_version98_prog
1 0

So this name's error has one cause, not two: add <algorithm>, and no standard flag needs to change with it. A file that includes <algorithm> and still sees this error does not have a version problem with the classic call; the include is not reaching the file that names the call, or the name in the file is not this name.

The pieces layered on top of the classic call do carry floors, and naming one splits in two when a reader tries it. This name does have an execution-policy overload, since C++17 - and naming the policy with only <algorithm> included fails on the policy's name, not the algorithm's:

C++
#include <algorithm>
#include <vector>
int main() {
    std::vector<int> v1 = {1, 2, 3};
    std::vector<int> v2 = {1, 2, 3};
    return std::equal(std::execution::seq, v1.begin(), v1.end(), v2.begin()) ? 0 : 1;
}
Output
-std=c++17 p_policy_algonly.cpp -o p_policy_algonly_prog
p_policy_algonly.cpp: In function 'int main()':
p_policy_algonly.cpp:6:28: error: 'std::execution' has not been declared
    6 |     return std::equal(std::execution::seq, v1.begin(), v1.end(), v2.begin()) ? 0 : 1;
      |                            ^~~~~~~~~

That wording - has not been declared, naming std::execution - is the missing-header shape, and here adding the header is the whole fix: add <execution> alongside <algorithm>, and the same call compiles and runs, because the policy overload of std::equal exists:

Terminal
-std=c++17 p_policy_both.cpp -o p_policy_both_prog
$ ./p_policy_both_prog

The policy form belongs to this name, and it carries the C++17 floor. Compiled as C++14, the same two-header program fails on the policy's name again - at that standard the policy names are not there to be declared:

Output
-std=c++14 p_policy_cpp14.cpp -o p_policy_cpp14_prog
p_policy_cpp14.cpp: In function 'int main()':
p_policy_cpp14.cpp:7:28: error: 'std::execution' has not been declared
    7 |     return std::equal(std::execution::seq, v1.begin(), v1.end(), v2.begin()) ? 0 : 1;
      |                            ^~~~~~~~~

And since C++20 the classic call is also usable in constant expressions - this program's comparison happens at compile time, and the assertion on the result is part of the build:

C++
#include <algorithm>
#include <array>
constexpr bool check() {
    std::array<int, 3> a{1, 2, 3};
    std::array<int, 3> b{1, 2, 3};
    return std::equal(a.begin(), a.end(), b.begin());
}
static_assert(check());
int main() { return 0; }
Terminal
-std=c++20 c_constexpr20.cpp -o c_constexpr20_prog
$ ./c_constexpr20_prog

Compiled as C++17, the same program fails - the call is not a constant expression there, and the static assertion cannot hold:

Output
-std=c++17 c_constexpr17.cpp -o c_constexpr17_prog
c_constexpr17.cpp: In function 'constexpr bool check()':
c_constexpr17.cpp:6:22: warning: call to non-'constexpr' function 'bool std::equal(_II1, _II1, _II2) [with _II1 = int*; _II2 = int*]' [-Winvalid-constexpr]
    6 |     return std::equal(a.begin(), a.end(), b.begin());
      |            ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from c_constexpr17.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:1547:5: note: 'bool std::equal(_II1, _II1, _II2) [with _II1 = int*; _II2 = int*]' declared here
 1547 |     equal(_II1 __first1, _II1 __last1, _II2 __first2)
      |     ^~~~~
c_constexpr17.cpp: At global scope:
c_constexpr17.cpp:8:20: error: non-constant condition for static assertion
    8 | static_assert(check());
      |               ~~~~~^~
c_constexpr17.cpp:8:20: error: 'constexpr bool check()' called in a constant expression
c_constexpr17.cpp:3:16: note: 'constexpr bool check()' declared here
    3 | constexpr bool check() {
      |                ^~~~~

So C++20 is the floor for that layered piece and C++17 is the floor for the policy form - and no standard at any level rescues a missing include, while no include is needed beyond <algorithm> for the classic call at any standard level.

The neighboring names: two share the side door, one does not

The three names a reader most often reaches for alongside this one all live in <algorithm> too, but in a file whose only include is <vector> they split. std::mismatch - which finds the first position where two ranges differ - compiles in that file, and so does std::lexicographical_compare - which reports whether one range sorts before another: in this library both are declared by the same low-level header <vector> pulls in. std::search - which finds a sub-range inside a range - fails with the plain error in the same file:

Output
-std=c++17 b_search_vector.cpp -o b_search_vector_prog
b_search_vector.cpp: In function 'int main()':
b_search_vector.cpp:5:20: error: 'search' is not a member of 'std'
    5 |     auto it = std::search(v1.begin(), v1.end(), v2.begin(), v2.end());
      |                    ^~~~~~

Three neighbors, one home by the standard, and two fates in this library: two ride the same transitive rescue as this guide's name, and one is left outside it. They are shown here only as neighbors, not re-taught.

The neighboring names, fixed

Together the four names take one header between them - <algorithm> for all of them, with <vector> covering only the containers they work on. The fixed neighbor program reports all four operations:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> a = {1, 2, 3};
    std::vector<int> b = {1, 2, 3};
    std::cout << "equal " << std::equal(a.begin(), a.end(), b.begin()) << "\n";
    std::vector<int> c = {1, 2, 3};
    std::vector<int> d = {1, 9, 3};
    auto r = std::mismatch(c.begin(), c.end(), d.begin());
    std::cout << "mismatch " << (r.first - c.begin()) << " " << *(r.first) << " " << *(r.second) << "\n";
    std::cout << "lexicographical_compare " << std::lexicographical_compare(c.begin(), c.end(), d.begin(), d.end()) << "\n";
    std::vector<int> hay = {1, 2, 3, 4};
    std::vector<int> needle = {2, 3};
    auto it = std::search(hay.begin(), hay.end(), needle.begin(), needle.end());
    std::cout << "search " << (it - hay.begin()) << "\n";
    return 0;
}
Terminal
-std=c++17 b_neighbors_fixed.cpp -o b_neighbors_fixed_prog
$ ./b_neighbors_fixed_prog
equal 1
mismatch 1 2 9
lexicographical_compare 1
search 1

Read in order: equal reports 1, true, because the two ranges hold the same elements; mismatch reports the first difference at index 1 with both values; lexicographical_compare reports 1, true, because at the first difference the first range's 2 sorts before the second range's 9; and search reports 1, the index where the needle 2, 3 starts inside the haystack.

A ranges form since C++20, in the same header

C++20 added a ranges form of this name, and the standard declares it in the same header as the classic name. std::ranges::equal is a function object in the ranges namespace, declared in <algorithm>, that accepts whole ranges - and unlike the classic form it always takes both ranges' ends, so the lengths are always part of its answer. It returns a plain bool. Compiled as C++20 it compares the same vectors and reports both verdicts:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v1 = {1, 2, 3};
    std::vector<int> v2 = {1, 2, 3};
    std::vector<int> v3 = {1, 9, 3};
    std::cout << "ranges " << std::ranges::equal(v1, v2) << " " << std::ranges::equal(v1, v3) << "\n";
    return 0;
}
Terminal
-std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
ranges 1 0

Two boundaries and one library behavior keep the forms straight. The ranges form needs C++20: compiled as C++17, that same program fails on the namespace itself, with 'std::ranges' has not been declared:

Output
-std=c++17 r_ranges_cpp17.cpp -o r_ranges_cpp17_prog
r_ranges_cpp17.cpp: In function 'int main()':
r_ranges_cpp17.cpp:7:23: error: 'std::ranges' has not been declared
    7 |     std::cout << std::ranges::equal(v1, v2) << "\n";
      |                       ^~~~~~

And in this library the ranges header does not rescue the ranges form - a file whose only include is <ranges> fails for it, with the same wrong-name suggestion the classic name earned in the <numeric> file, this time inside the ranges namespace:

Output
-std=c++20 r_ranges_rangesheader.cpp -o r_ranges_rangesheader_prog
r_ranges_rangesheader.cpp: In function 'int main()':
r_ranges_rangesheader.cpp:5:25: error: 'equal' is not a member of 'std::ranges'; did you mean 'equal_to'?
    5 |     return std::ranges::equal(a, b) ? 0 : 1;
      |                         ^~~~~
      |                         equal_to

A file that includes <array> alone fails for the ranges form with the identical diagnostic - same suggestion, same wrong name. That is this library version's behavior, not the rule: the header the standard names for both forms is <algorithm>, so a complete program names it. The classic name, meanwhile, is not pulled in by the ranges header either: in the sweep probed here, a file whose only include is <ranges> fails for std::equal with the plain error, as the sweep section above lists.

A different wording - and an argument-dependent rescue that depends on the iterators' types

Including <algorithm> is not the only half of the name. Over plain arrays, the unqualified call fails:

C++
#include <algorithm>
int main() {
    int a[3] = {1, 2, 3};
    int b[3] = {1, 2, 3};
    equal(a, a + 3, b);
    return 0;
}
Output
-std=c++17 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:5:5: error: 'equal' was not declared in this scope; did you mean 'std::equal'?
    5 |     equal(a, a + 3, b);
      |     ^~~~~
      |     std::equal
In file included from /usr/include/c++/13/algorithm:73,
                 from g_unqualified.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:347:1: note: 'std::equal' declared here
  347 | equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~

That wording - was not declared in this scope, with did you mean 'std::equal'? on the error line and a note pointing at a declaration - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::equal; adding includes does not bring the name out of namespace std. Swap the arrays for a vector, and the same unqualified call compiles and runs:

C++
#include <algorithm>
#include <vector>
int main() {
    std::vector<int> v1 = {1, 2, 3};
    std::vector<int> v2 = {1, 2, 3};
    return equal(v1.begin(), v1.end(), v2.begin()) ? 0 : 1;
}
Terminal
-std=c++17 g_unqualified_vec.cpp -o g_unqualified_vec_prog
$ ./g_unqualified_vec_prog

That compile is argument-dependent lookup at work, not a rule to rely on: the vector's iterators are std types, so their associated namespace is std, and lookup finds std::equal through them. A list's iterators rescue it the same way - the same unqualified call over a list compiles and runs:

Terminal
-std=c++17 g_unqualified_list.cpp -o g_unqualified_list_prog
$ ./g_unqualified_list_prog

But the container being a std type is not enough by itself - over a std::array, the same unqualified call fails with the same wording, because in this library a std::array's iterators are plain pointers, and a pointer has no associated namespace:

C++
#include <algorithm>
#include <array>
int main() {
    std::array<int, 3> a{1, 2, 3};
    std::array<int, 3> b{1, 2, 3};
    return equal(a.begin(), a.end(), b.begin()) ? 0 : 1;
}
Output
-std=c++17 g_unqualified_stdarray.cpp -o g_unqualified_stdarray_prog
g_unqualified_stdarray.cpp: In function 'int main()':
g_unqualified_stdarray.cpp:6:12: error: 'equal' was not declared in this scope; did you mean 'std::equal'?
    6 |     return equal(a.begin(), a.end(), b.begin()) ? 0 : 1;
      |            ^~~~~
      |            std::equal
In file included from /usr/include/c++/13/algorithm:73,
                 from g_unqualified_stdarray.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:347:1: note: 'std::equal' declared here
  347 | equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~

The pattern across the probed set is exact: the rescue follows the iterator type, not the container's name - class iterators of std containers carry the name in, pointer iterators do not, whatever container stands behind them. Write the qualifier either way.

The exact rule

  • std::equal is declared by #include <algorithm>, and by no other header by rule. In the sweep probed here, 65 of the other 105 headers in the library's header set - among them <limits>, <ranges>, <chrono>, and <utility> - do not declare it, and neither does a file with no include at all; the remaining 40 pull it in transitively, as this library version's behavior, not as a guarantee.
  • 'equal' is not a member of 'std' has one cause in the contexts probed here: the <algorithm> include is missing and nothing else in the file pulled the name in - and it comes in two shapes in the sweep probed here: 64 failing sole headers fail with one error line and no suggestion tail, no note lines, and no help lines, and one, <numeric>, fails with the suggestion did you mean 'equal_to'?, which names a function object, not this algorithm.
  • In the sweep probed here, 40 headers besides <algorithm> rescue std::equal transitively - among them <vector>, <iostream>, <iterator>, <string>, and <map> - 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, no header besides <algorithm> is required to pull std::equal in.
  • The result rules are the documented ones, as the fixed programs here show: the fixed program prints 1 0 for the textbook case; the semantics program prints same 1, differ 0, prefix-classic 1, predicate 1, and empty 1 - the call returns true when every compared position matches, and the classic form compares exactly the first range's length in positions, so a second range that merely starts the same way still reports true.
  • The bounded form follows from the same rule: it checks the lengths too - the bounded program here prints longer-first 0, longer-second 0, and same-length 1 - and it starts at C++14: compiled as C++11 the same call fails, because the second range's end is taken for a predicate.
  • The classic call's reading side needs only input iterators: the stream program here compares two pairs of stream iterators and prints 1 0.
  • The classic std::equal predates C++11: with <algorithm> included it compiles and runs as C++98, reporting 1 0. The layered pieces have floors: the bounded form starts at C++14; the execution-policy overload starts at C++17 - with only <algorithm> included, naming std::execution::seq fails with 'std::execution' has not been declared; with <execution> included alongside it, the policy call compiles and runs; and compiled as C++14, the same program fails on the policy's name. Constant-expression use starts at C++20: the static-assert program here compiles as C++20 and fails as C++17.
  • The neighbors split in this library: std::mismatch and std::lexicographical_compare are declared by #include <algorithm> as well and compile in a sole <vector> file through the same transitive rescue as this name, and std::search is declared by it too but fails in that file with the plain error. The fixed neighbor program prints equal 1, mismatch 1 2 9, lexicographical_compare 1, and search 1.
  • std::ranges::equal is a ranges form of this same name: a function object in namespace std::ranges, declared in <algorithm> by the standard, needing C++20, returning a plain bool and always taking both ranges' ends - compiled as C++17 the ranges program here fails with 'std::ranges' has not been declared, and compiled as C++20 it prints ranges 1 0 for the two three-element vectors. In the probes here <ranges> alone does not rescue it in this library - it fails with the suggestion did you mean 'equal_to'?, <array> alone fails for it the same way, and <ranges> fails plainly for the classic name in the sweep.
  • 'equal' was not declared in this scope for an unqualified equal use is a different defect: qualify the name as std::equal - the include alone does not bring the name out of namespace std. For this name the unqualified call's fate depends on the iterators' types: over plain arrays it fails, as the first unqualified program above shows; over a vector's iterators and over a list's iterators it is rescued through argument-dependent lookup, as the second and third show, because those iterators are std class types; over a std::array's iterators it fails again, because in this library those iterators are plain pointers. Qualify the name either way.

The fixes, ranked

  • First, check the include list of the file that names std::equal. If <algorithm> is not there, add it - that is the fix for the only cause of this error. It holds whether the file failed plainly - 64 of the 65 probed failures did - or happened to compile before through one of the 40 transitive rescues and stopped compiling when its other includes changed.
  • Second, do not follow the one suggestion this error ever offers here: in a <numeric> file the compiler proposes equal_to, but std::equal_to is a function object that compares two single values - renaming the call to it does not compare any ranges. The fix for the <numeric> file is the same include as everywhere else.
  • Third, do not chase a standard flag for the classic call: this name predates C++11, so no flag change fixes this error, and a file with <algorithm> included that still fails has an include that is not reaching the translation unit, not a version problem.
  • Fourth, do not reach for a container's header because the call reads containers, or for <iterator> because the call takes iterators. In the sweep probed here both happen to rescue this name in this library - and neither is the declaring header by rule. The declaring header is <algorithm>, and a complete program names it alongside the container's own header.
  • Fifth, do not remove <algorithm> because a file compiles without it: in the probed set 40 headers rescue the classic name, and those rescues are not guaranteed - a file that drops the include is one internal-include change away from the error in the first section.
  • Sixth, when the two ranges may differ in length, use the bounded form and keep the standard at C++14 or later: the classic form compares only the first range's length in elements and reports a prefix as equal, and the bounded form is the one that counts a length difference as inequality.
  • Seventh, if the error names std::execution instead - 'std::execution' has not been declared - add <execution> alongside <algorithm> and keep the standard at C++17 or later: this name does have a policy overload, and that pair of changes is the whole fix for the policy form.
  • Eighth, match the standard to the one piece beyond the classic call that has a floor: constant-expression use needs C++20, and the ranges form std::ranges::equal needs C++20 - with its header still <algorithm> by the standard, not <ranges>.
  • Ninth, if the error says was not declared in this scope instead, fix the name's qualifier to std::equal as well - and do not rely on argument-dependent lookup to rescue the unqualified call, because a plain array and a std::array each remove that rescue in the probed set.

Sources

  • cppreference, std::equal - the function template is defined in <algorithm>; it returns true when the two ranges have the same size and each corresponding elements are equal, comparing with operator== or a given predicate; the bounded overloads that also take the second range's end are marked since C++14, the execution-policy overloads since C++17, and the classic overloads constexpr since C++20, with no since marker on the classic call itself.
  • cppreference, <algorithm> header - the header that declares this name and the other algorithm names used as neighbors here.
  • cppreference, std::ranges::equal - the C++20 ranges form of this name, a function object in namespace std::ranges declared in <algorithm>, returning true when the two ranges have the same size and equal elements.
  • cppreference, std::mismatch - the neighboring name that finds the first position where two ranges differ, declared in <algorithm>.
  • cppreference, std::lexicographical_compare - the neighboring name that reports whether one range sorts before another, declared in <algorithm>.
  • cppreference, std::search - the neighboring name that finds a sub-range inside a range, declared in <algorithm>.

Keep Exploring