C++

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

std::adjacent_find lives in one header, <algorithm> - and in the sweep probed here, covering all 106 standard headers in this library's header set, only 4 other headers pull it in on the side: <execution>, <functional>, <regex>, and <valarray>. Its error is one plain line with nothing after it - no suggestion, no note, nothing to follow - and unlike some of its neighbors it has no second cause hiding behind that wording, because this name predates C++11. This guide pins down the failing shapes, the 4 transitive rescues, the iterator the fixed call gives back, and the include that fixes it by rule.

Written December 2, 2026 · Tested with GCC 13.3.0 · 27 min read

By the end of this guide
  • The error: the include is missing
  • The textbook version fails too - and its diagnostic offers nothing at all
  • Neighboring headers: 101 fail in one shape, and 4 rescue it by accident
  • The fix

Written December 2, 2026

Tested with GCC 13.3.0

What this guide is

std::adjacent_find is a function template defined in the header <algorithm>. It searches a range for the first pair of adjacent equal elements and returns an iterator to the first element of that pair: the first iterator where the element equals the element after it, or, in the predicate form, where the predicate returns true for the two neighbors. If no such pair exists, it returns the last iterator. The iterators need only meet the forward-iterator requirements, and the classic form makes exactly min(M+1, N-1) comparisons over a range of N elements, where M is the distance from the start to the result. The classic call predates C++11, has execution-policy overloads 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, and not in <numeric> - 'adjacent_find' 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 rarely saves anyone: in the sweep below, only 4 of the other 105 headers in the library's header set pull the name in on the side, so most files without <algorithm> reach this error.

And for this name the missing include is the only cause. Some names in this family hide a second cause behind the same wording - a standard floor the name starts at - but std::adjacent_find 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 execution-policy overloads need C++17 and constant-expression use needs C++20 - but those floors belong to the added pieces, not to the classic call, and neither produces this error line for the classic call.

A first-adjacent-pair program's file most often already holds <vector> for the container and <iostream> for printing, and in the sweep probed here neither rescues the name - so the file a reader actually has fails, textbook includes and all. 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 one way - the failure, in a single diagnostic shape, or a rescue - and the rescue set has 5 entries: <algorithm> itself and 4 transitive rescues.

The error: the include is missing

This program finds the first adjacent equal pair in a five-element array, but includes only <limits>:

C++
#include <limits>
int main() {
    int a[5] = {3, 1, 4, 4, 5};
    auto it = std::adjacent_find(a, a + 5);
    return it != a + 5 && *it == 4 ? 0 : 1;
}
Output
-std=c++17 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:4:20: error: 'adjacent_find' is not a member of 'std'
    4 |     auto it = std::adjacent_find(a, a + 5);
      |                    ^~~~~~~~~~~~~

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:3:20: error: 'adjacent_find' is not a member of 'std'
    3 |     auto it = std::adjacent_find(a, a + 5);
      |                    ^~~~~~~~~~~~~

The textbook version fails too - and its diagnostic offers nothing at all

The version most often written first - print the first adjacent equal element of a vector and where it sits - produces this error as well, without <algorithm>:

C++
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {3, 1, 4, 4, 5};
    auto it = std::adjacent_find(v.begin(), v.end());
    std::cout << "found " << *it << " at index " << (it - v.begin()) << "\n";
    return 0;
}
Output
-std=c++17 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:20: error: 'adjacent_find' is not a member of 'std'
    5 |     auto it = std::adjacent_find(v.begin(), v.end());
      |                    ^~~~~~~~~~~~~

It fails, and the failure carries no suggestion. That silence is this name's shape in every probed context: not the textbook file, and not any sole header in the sweep, gives adjacent_find a suggestion tail on its missing-include error. There is nothing in the line to follow, wrong or right; the only information it carries is that the name is not there. A sole <vector> file fails with the same plain line:

Output
-std=c++17 v_vector_fail.cpp -o v_vector_fail_prog
v_vector_fail.cpp: In function 'int main()':
v_vector_fail.cpp:4:20: error: 'adjacent_find' is not a member of 'std'
    4 |     auto it = std::adjacent_find(v.begin(), v.end());
      |                    ^~~~~~~~~~~~~

A program that uses std::adjacent_find 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: 101 fail in one shape, and 4 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 finds the first adjacent equal pair of 3, 1, 4, 4, 5 and checks that the result lands on the first 4, the outcome splits by compile result two ways - the failure, or a rescue - and the failure itself comes in exactly one diagnostic shape. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 101 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>
  • <array>
  • <atomic>
  • <barrier>
  • <bit>
  • <bitset>
  • <cassert>
  • <ccomplex>
  • <cctype>
  • <cerrno>
  • <cfenv>
  • <cfloat>
  • <charconv>
  • <chrono>
  • <cinttypes>
  • <ciso646>
  • <climits>
  • <clocale>
  • <cmath>
  • <codecvt>
  • <compare>
  • <complex>
  • <concepts>
  • <condition_variable>
  • <coroutine>
  • <csetjmp>
  • <csignal>
  • <cstdalign>
  • <cstdarg>
  • <cstdbool>
  • <cstddef>
  • <cstdint>
  • <cstdio>
  • <cstdlib>
  • <cstring>
  • <ctgmath>
  • <ctime>
  • <cuchar>
  • <cwchar>
  • <cwctype>
  • <deque>
  • <exception>
  • <expected>
  • <filesystem>
  • <format>
  • <forward_list>
  • <fstream>
  • <future>
  • <initializer_list>
  • <iomanip>
  • <ios>
  • <iosfwd>
  • <iostream>
  • <istream>
  • <iterator>
  • <latch>
  • <limits>
  • <list>
  • <locale>
  • <map>
  • <memory>
  • <memory_resource>
  • <mutex>
  • <new>
  • <numbers>
  • <numeric>
  • <optional>
  • <ostream>
  • <queue>
  • <random>
  • <ranges>
  • <ratio>
  • <scoped_allocator>
  • <semaphore>
  • <set>
  • <shared_mutex>
  • <source_location>
  • <span>
  • <spanstream>
  • <sstream>
  • <stack>
  • <stacktrace>
  • <stdexcept>
  • <stdfloat>
  • <stop_token>
  • <streambuf>
  • <string>
  • <string_view>
  • <syncstream>
  • <system_error>
  • <thread>
  • <tuple>
  • <type_traits>
  • <typeindex>
  • <typeinfo>
  • <unordered_map>
  • <unordered_set>
  • <utility>
  • <variant>
  • <vector>
  • <version>

A file with no include at all fails the same plain way. Three entries in this list deserve a pause. <iterator> fails: the header of the iterator operations does not declare this algorithm, however iterator-shaped its arguments look. <numeric> fails: the header of the accumulating names does not declare this one either. And <ranges> fails for the classic name: the C++20 ranges library has its own adjacent_find name, and it does not bring this one in - that name gets its own section below.

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

  • <algorithm>
  • <execution>
  • <functional>
  • <regex>
  • <valarray>

The shape is the family shape: <algorithm> sits on top of the container and stream headers, almost nothing pulls it in on the side, and the four headers that do are headers few adjacent-pair programs include. That is also why the failing set covers nearly the whole library: with 101 of the other 105 headers failing, the missing include is the normal state of a file that was never given <algorithm>, not an edge case. <algorithm> - the home header - is on the rescue list by definition, not by transitivity, and the other 4 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> v = {3, 1, 4, 4, 5};
    auto it = std::adjacent_find(v.begin(), v.end());
    std::cout << "found " << *it << " at index " << (it - v.begin()) << "\n";
    return 0;
}
Terminal
-std=c++17 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
found 4 at index 2

One include, <algorithm>, declares the function - and the textbook program, which failed outright before, now prints found 4 at index 2: in 3, 1, 4, 4, 5 the first adjacent equal pair is the two 4s, and the call returns the iterator to the first of them, sitting at index 2. What the include changes is the standing of the program as well as its fate: the name is now declared by a header the file names itself, instead of by an internal include of one of the four rescuing headers that a different library version is free to rearrange.

The return value: one iterator, to the first element of the first matching pair

The call returns a single iterator, not a pair and not a value, and where it lands follows the range. Over a vector it lands on the first element of the first adjacent equal pair; over a list it does the same by stepping; when two pairs qualify it takes the first pair; and when no adjacent pair is equal it returns the last iterator:

C++
#include <algorithm>
#include <iostream>
#include <list>
#include <vector>
int main() {
    std::vector<int> v = {3, 1, 4, 4, 5};
    std::vector<int> none = {3, 1, 4, 1, 5};
    std::list<int> l = {3, 1, 4, 4, 5};
    std::vector<int> two = {2, 2, 3, 3};
    auto pv = std::adjacent_find(v.begin(), v.end());
    std::cout << "vector " << *pv << " at index " << (pv - v.begin()) << "\n";
    auto pn = std::adjacent_find(none.begin(), none.end());
    std::cout << "none " << (pn == none.end() ? "end" : "value") << "\n";
    auto pl = std::adjacent_find(l.begin(), l.end());
    std::cout << "list " << *pl << "\n";
    auto pt = std::adjacent_find(two.begin(), two.end());
    std::cout << "two-pairs " << *pt << " at index " << (pt - two.begin()) << "\n";
    return 0;
}
Terminal
-std=c++17 r_semantics.cpp -o r_semantics_prog
$ ./r_semantics_prog
vector 4 at index 2
none end
list 4
two-pairs 2 at index 0

Read in order: the vector line reports 4 at index 2, the first 4 of the pair in 3, 1, 4, 4, 5 - the returned iterator points at the first element of the pair, so the second element of the pair is the one after it. The none line reports end: over 3, 1, 4, 1, 5 no two neighbors are equal, so the call returns the last iterator, and a caller that dereferences the result without comparing it against the end first has a defect the compiler will not catch. The list line reports 4 - the same kind of answer over a range whose iterators can only be stepped one at a time. The two-pairs line reports 2 at index 0 over 2, 2, 3, 3: both pairs qualify, and the call stops at the first one. In every case the call returns one position in the range passed, and dereferencing it - after the end check - gives the first element of the matching pair.

Predicates: the pair is whatever the predicate accepts

The predicate form replaces equality with a test the caller supplies: the call returns the first iterator where the predicate returns true for that element and the one after it:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {3, 4, 1, 5};
    std::vector<int> m = {4, 7, 2};
    auto s = std::adjacent_find(v.begin(), v.end(),
        [](int x, int y) { return y == x + 1; });
    std::cout << "successor " << *s << " at index " << (s - v.begin()) << "\n";
    auto q = std::adjacent_find(m.begin(), m.end(),
        [](int x, int y) { return x % 3 == y % 3; });
    std::cout << "mod3 " << *q << " at index " << (q - m.begin()) << "\n";
    return 0;
}
Terminal
-std=c++17 r_predicate.cpp -o r_predicate_prog
$ ./r_predicate_prog
successor 3 at index 0
mod3 4 at index 0

The successor line reports 3 at index 0: the predicate there accepts a pair when the second element is the first plus one, and over 3, 4, 1, 5 the first such pair is 3 followed by 4, so the iterator lands on the 3. The mod3 line reports 4 at index 0: that predicate accepts a pair when the two neighbors are equal modulo 3, and over 4, 7, 2 the first pair qualifies - 4 and 7 both leave remainder 1 - so the iterator lands on the 4, even though the two elements are not equal. One predicate drives the whole search, and "adjacent" means whatever the predicate says it means.

The edge ranges: empty, one element, and two

No short range is an error, but the short ranges split by whether a pair can exist at all. An empty range returns the last iterator - there is no pair to find - and a one-element range returns the last iterator too, for the same reason. Two elements are the shortest range that can hold a pair, and two equal elements return the first of them:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> e;
    std::vector<int> one = {8};
    std::vector<int> two = {8, 8};
    auto pe = std::adjacent_find(e.begin(), e.end());
    std::cout << "empty " << (pe == e.end() ? "end" : "value") << "\n";
    auto po = std::adjacent_find(one.begin(), one.end());
    std::cout << "one " << (po == one.end() ? "end" : "value") << "\n";
    auto pt = std::adjacent_find(two.begin(), two.end());
    std::cout << "two " << *pt << " at index " << (pt - two.begin()) << "\n";
    return 0;
}
Terminal
-std=c++17 k_empty.cpp -o k_empty_prog
$ ./k_empty_prog
empty end
one end
two 8 at index 0

The empty and one lines both report end, because in both ranges the documented result when no pair matches is the last iterator - so a caller that dereferences the result without checking has to rule both cases out, not just the empty one. The two line reports 8 at index 0: the single pair in the range matches, and the iterator lands on its first element. Only ranges of two or more elements can return anything else.

Forward iterators: the weakest iterators it accepts

The iterator requirement is the forward-iterator one: the range does not need to be indexable, and it does not need to be walkable backward. This program finds the first adjacent equal pair of a forward list - a container whose iterators step in one direction only:

C++
#include <algorithm>
#include <forward_list>
#include <iostream>
int main() {
    std::forward_list<int> fl = {3, 1, 4, 4, 5};
    auto it = std::adjacent_find(fl.begin(), fl.end());
    std::cout << *it << "\n";
    return 0;
}
Terminal
-std=c++17 f_forward.cpp -o f_forward_prog
$ ./f_forward_prog
4

It reports 4. The scan is a single forward pass - each element is compared with the one after it, in order - and a forward-only range is enough for it, which is the floor the list line in the return-value section also stands on.

Versions: no second cause - this name predates C++11

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

C++
#include <algorithm>
#include <iostream>
int main() {
    int a[5] = {3, 1, 4, 4, 5};
    int* it = std::adjacent_find(a, a + 5);
    std::cout << *it << " " << (it - a) << "\n";
    return 0;
}
Terminal
-std=c++98 c_version98.cpp -o c_version98_prog
$ ./c_version98_prog
4 2
Terminal
-std=c++11 c_version11.cpp -o c_version11_prog
$ ./c_version11_prog
4 2

Both builds print 4 2 - the value 4, at index 2. 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> v = {3, 1, 4, 4, 5};
    auto it = std::adjacent_find(std::execution::seq, v.begin(), v.end());
    return it != v.end() && *it == 4 ? 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:5:39: error: 'std::execution' has not been declared
    5 |     auto it = std::adjacent_find(std::execution::seq, v.begin(), v.end());
      |                                       ^~~~~~~~~

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 overloads of std::adjacent_find exist:

C++
#include <algorithm>
#include <execution>
#include <vector>
int main() {
    std::vector<int> v = {3, 1, 4, 4, 5};
    auto it = std::adjacent_find(std::execution::seq, v.begin(), v.end());
    return it != v.end() && *it == 4 ? 0 : 1;
}
Terminal
-std=c++17 p_policy_both.cpp -o p_policy_both_prog
$ ./p_policy_both_prog

The policy forms belong to the algorithm names, and this is one: the overloads are part of this name since C++17, so they carry that 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:6:39: error: 'std::execution' has not been declared
    6 |     auto it = std::adjacent_find(std::execution::seq, v.begin(), v.end());
      |                                       ^~~~~~~~~

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

C++
#include <algorithm>
#include <array>
constexpr bool check() {
    std::array<int, 5> a = {3, 1, 4, 4, 5};
    auto it = std::adjacent_find(a.begin(), a.end());
    return it != a.end() && *it == 4;
}
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:5:33: warning: call to non-'constexpr' function '_FIter std::adjacent_find(_FIter, _FIter) [with _FIter = int*]' [-Winvalid-constexpr]
    5 |     auto it = std::adjacent_find(a.begin(), a.end());
      |               ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
                 from c_constexpr17.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:4020:5: note: '_FIter std::adjacent_find(_FIter, _FIter) [with _FIter = int*]' declared here
 4020 |     adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
      |     ^~~~~~~~~~~~~
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 forms - 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: find and search live in the same header

The two names a reader most often reaches for alongside this one do not live in a container's header either. std::find returns an iterator to the first element equal to a given value, and std::search returns an iterator to the first occurrence of one range inside another - and both are declared by <algorithm>, alongside std::adjacent_find. They share this name's failure, and this name's silence: in a file whose only include is <vector>, a std::find call fails with the plain error:

Output
-std=c++17 b_find_vector.cpp -o b_find_vector_prog
b_find_vector.cpp: In function 'int main()':
b_find_vector.cpp:4:20: error: 'find' is not a member of 'std'
    4 |     auto it = std::find(v.begin(), v.end(), 4);
      |                    ^~~~
  • and a std::search call in the same file fails the same plain way:
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(v.begin(), v.end(), pat.begin(), pat.end());
      |                    ^~~~~~

Neither neighbor's diagnostic offers a suggestion either, in this file: all three names fail with the one bare line, and there is nothing in any of the three lines to follow, wrong or right. They are shown here only as neighbors, not re-taught.

The neighboring names, fixed

The three names together take the same one added header - <algorithm> covers all of them, and <vector> covers only the container they walk. The fixed neighbor program reports find 4, search 4, and adjacent 4 over 3, 1, 4, 4, 5:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {3, 1, 4, 4, 5};
    std::vector<int> pat = {4, 4};
    std::cout << "find " << *std::find(v.begin(), v.end(), 4) << "\n";
    std::cout << "search " << *std::search(v.begin(), v.end(), pat.begin(), pat.end()) << "\n";
    std::cout << "adjacent " << *std::adjacent_find(v.begin(), v.end()) << "\n";
    return 0;
}
Terminal
-std=c++17 b_neighbors_fixed.cpp -o b_neighbors_fixed_prog
$ ./b_neighbors_fixed_prog
find 4
search 4
adjacent 4

Read in order: the first element equal to 4 is a 4, the first occurrence of the pattern 4, 4 starts at a 4, and the first adjacent equal pair starts at a 4 - three different questions over the same range, all answered from the same header. One header declares all three operations, and a complete search program needs it alongside the container's own header.

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::adjacent_find is a function object in the ranges namespace, declared in <algorithm>, that also accepts a whole range - and it returns an iterator, the same shape as the classic call's result, not a pair and not a subrange. Compiled as C++20 it reports 4 at index 2 for the same five-element vector the return-value program scans:

C++
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
    std::vector<int> v = {3, 1, 4, 4, 5};
    auto r = std::ranges::adjacent_find(v);
    std::cout << *r << " at index " << (r - v.begin()) << "\n";
    return 0;
}
Terminal
-std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
4 at index 2

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. The classic header is not interchangeable with the container headers for this form either: a file that includes <array> alone fails for it, with an error that names the namespace the reader used:

Output
-std=c++20 r_ranges_arrayonly.cpp -o r_ranges_arrayonly_prog
r_ranges_arrayonly.cpp: In function 'int main()':
r_ranges_arrayonly.cpp:4:27: error: 'adjacent_find' is not a member of 'std::ranges'
    4 |     auto r = std::ranges::adjacent_find(a);
      |                           ^~~~~~~~~~~~~

And in this library, a file whose only include is <ranges> compiles the ranges form over a plain array - the ranges header carries the name on the side here, whatever the standard's synopsis says about its home:

Terminal
-std=c++20 r_ranges_rangesheader.cpp -o r_ranges_rangesheader_prog
$ ./r_ranges_rangesheader_prog

That is this library version's behavior, not a rule to build on: the header the standard names for both forms is <algorithm>, and a complete program names it. The classic name, meanwhile, is not pulled in by the ranges header at all: in the sweep probed here, a file whose only include is <ranges> fails for std::adjacent_find 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[5] = {3, 1, 4, 4, 5};
    auto it = adjacent_find(a, a + 5);
    return it != a + 5 && *it == 4 ? 0 : 1;
}
Output
-std=c++17 g_unqualified.cpp -o g_unqualified_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:4:15: error: 'adjacent_find' was not declared in this scope; did you mean 'std::adjacent_find'?
    4 |     auto it = adjacent_find(a, a + 5);
      |               ^~~~~~~~~~~~~
      |               std::adjacent_find
In file included from /usr/include/c++/13/algorithm:73,
                 from g_unqualified.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:94:1: note: 'std::adjacent_find' declared here
   94 | adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred);
      | ^~~~~~~~~~~~~

That wording - was not declared in this scope, with did you mean 'std::adjacent_find'? 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::adjacent_find; 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> v = {3, 1, 4, 4, 5};
    auto it = adjacent_find(v.begin(), v.end());
    return it != v.end() && *it == 4 ? 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::adjacent_find through them. A list's iterators rescue it the same way - the same unqualified call over a list compiles and runs:

C++
#include <algorithm>
#include <list>
int main() {
    std::list<int> v = {3, 1, 4, 4, 5};
    auto it = adjacent_find(v.begin(), v.end());
    return it != v.end() && *it == 4 ? 0 : 1;
}
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, 5> v = {3, 1, 4, 4, 5};
    auto it = adjacent_find(v.begin(), v.end());
    return it != v.end() && *it == 4 ? 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:5:15: error: 'adjacent_find' was not declared in this scope; did you mean 'std::adjacent_find'?
    5 |     auto it = adjacent_find(v.begin(), v.end());
      |               ^~~~~~~~~~~~~
      |               std::adjacent_find
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:94:1: note: 'std::adjacent_find' declared here
   94 | adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred);
      | ^~~~~~~~~~~~~

An initializer list's iterators fail the same way, for the same reason - in this library they are plain pointers too:

C++
#include <algorithm>
#include <initializer_list>
int main() {
    std::initializer_list<int> v = {3, 1, 4, 4, 5};
    auto it = adjacent_find(v.begin(), v.end());
    return it != v.end() && *it == 4 ? 0 : 1;
}
Output
-std=c++17 g_unqualified_il.cpp -o g_unqualified_il_prog
g_unqualified_il.cpp: In function 'int main()':
g_unqualified_il.cpp:5:15: error: 'adjacent_find' was not declared in this scope; did you mean 'std::adjacent_find'?
    5 |     auto it = adjacent_find(v.begin(), v.end());
      |               ^~~~~~~~~~~~~
      |               std::adjacent_find
In file included from /usr/include/c++/13/algorithm:73,
                 from g_unqualified_il.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:94:1: note: 'std::adjacent_find' declared here
   94 | adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred);
      | ^~~~~~~~~~~~~

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::adjacent_find is declared by #include <algorithm>, and by no other header by rule. In the sweep probed here, 101 of the other 105 headers in the library's header set - among them <vector>, <iostream>, <iterator>, <numeric>, <ranges>, and <limits> - do not declare it, and neither does a file with no include at all; the remaining 4 pull it in transitively, as this library version's behavior, not as a guarantee.
  • 'adjacent_find' 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 - in the sweep probed here, every failing sole header fails with one error line and no suggestion tail, no note lines, and no help lines, all 101 in the one plain shape. There is no version cause for the classic call: it predates C++11, and with <algorithm> included it compiles and runs as C++98.
  • In the sweep probed here, 4 headers besides <algorithm> rescue std::adjacent_find transitively - <execution>, <functional>, <regex>, and <valarray> - 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::adjacent_find in.
  • The result rules are the documented ones, as the fixed programs here show: the fixed program prints found 4 at index 2 for the five-element vector; the return-value program prints vector 4 at index 2, none end, list 4, and two-pairs 2 at index 0 - the iterator lands on the first element of the first matching pair, and on the last iterator when no pair matches. The call returns one position in the range passed, not the elements themselves and not a pair of positions.
  • The edge ranges follow from the pair requirement: an empty range and a one-element range both return the last iterator - the edge program here prints empty end and one end - and the shortest range that can match, two equal elements, returns its first element - the edge program prints two 8 at index 0. A result equal to the last iterator must not be dereferenced.
  • The classic std::adjacent_find predates C++11: with <algorithm> included it compiles and runs as C++98 and as C++11, reporting 4 2 in both builds here. The layered pieces have floors: the execution-policy overloads start 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 iterators must meet the forward-iterator requirements. The forward-list program here shows the floor in action: over a forward list, whose iterators step in one direction only, the call prints 4.
  • std::find and std::search are declared by #include <algorithm> as well: in the programs here, a find call and a search call in a file whose only include is <vector> each fail with the same plain error this guide's name gets, and the fixed neighbor program, which includes both <algorithm> and <vector>, prints find 4, search 4, and adjacent 4. For none of the three names is the container's header the declaring header.
  • std::ranges::adjacent_find 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 an iterator - compiled as C++17 the ranges program here fails with 'std::ranges' has not been declared, and compiled as C++20 it prints 4 at index 2 for the five-element vector. In the probes here <ranges> alone compiles the ranges form in this library - behavior, not a guarantee - while <array> alone fails for it with 'adjacent_find' is not a member of 'std::ranges', and <ranges> fails plainly for the classic name in the sweep.
  • 'adjacent_find' was not declared in this scope for an unqualified adjacent_find use is a different defect: qualify the name as std::adjacent_find - 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 and over an initializer list'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::adjacent_find. If <algorithm> is not there, add it - that is the fix for the only cause of this error. It holds whether the file failed in a lean context or happened to compile before through one of the 4 transitive rescues and stopped compiling when its other includes changed.
  • Second, 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.
  • Third, do not reach for a container's header because the call walks a container, for <iterator> because the call takes iterators, or for <numeric> because the call reduces a range to one answer. In the sweep probed here all three fail for this name - the declaring header is <algorithm>, and a complete program names it alongside the container's own header.
  • Fourth, do not remove <algorithm> because a file compiles without it: in the probed set only 4 headers rescue it, 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.
  • Fifth, 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 policy overloads, and that pair of changes is the whole fix for the policy form.
  • Sixth, 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::adjacent_find needs C++20 - with its header still <algorithm> by the standard, not <ranges>.
  • Seventh, if the error says was not declared in this scope instead, fix the name's qualifier to std::adjacent_find as well - and do not rely on argument-dependent lookup to rescue the unqualified call, because a plain array, a std::array, and an initializer list each remove that rescue in the probed set.
  • Eighth, if the failing name is a neighboring one, the fix is the same header: find and search take an added <algorithm> too - one header for all three search operations, and the container's header for the container alone.

Which fix for which cause

  • #include <algorithm> missing, std::adjacent_find used in a file whose only include is one of the 101 headers listed as plain-failing in the sweep section above, or that includes nothing: the message is 'adjacent_find' is not a member of 'std', with no suggestion tail, no note lines, and no help lines - add #include <algorithm>.
  • std::adjacent_find used in a file whose only include is one of the 4 transitive-rescue headers listed in the sweep section above - <execution>, <functional>, <regex>, <valarray>: no error on this library version - add #include <algorithm> anyway, because those rescues are not guaranteed.
  • std::adjacent_find used in a textbook file including <iostream> and <vector>: the error above, plain, with no suggestion - add #include <algorithm>; the textbook includes do not rescue this name.
  • std::adjacent_find used with <algorithm> included, at any standard level from C++98 up: no version error - the classic call predates C++11, and the same file reports 4 2 compiled as C++98 and as C++11.
  • std::adjacent_find called with an execution policy, with <algorithm> included but <execution> not: the message is 'std::execution' has not been declared - add <execution>; the policy overloads exist for this name since C++17, and compiled as C++14 the same program fails on the policy's name for the standard's reason.
  • adjacent_find used without the std:: qualifier, <algorithm> included, over plain-array arguments, a std::array's iterators, or an initializer list's iterators: the message is 'adjacent_find' was not declared in this scope; did you mean 'std::adjacent_find'? - qualify the name as std::adjacent_find. Over a vector's iterators or a list's iterators, the same unqualified call compiles through argument-dependent lookup - qualify it anyway, so the call does not depend on the iterators' types.

Checklist

  • Check the include list of the file that names the call, not just the project. The include must be in that file, or in a header that file includes directly by design.
  • Do not import the container's header, the iterator header, or the numeric header into this error as the fix: std::adjacent_find and its two neighbors take <algorithm> and std::vector takes <vector>, so there are two headers in a complete search program, one for the search operations and one for the container.
  • Do not assume the textbook includes rescue this name by rule, and do not delete a working <algorithm> line because a file compiles without it. In the sweep here <iostream> and <vector> fail for std::adjacent_find - plainly, with no suggestion attached - and the 4 headers that rescue it do so only as this library version's behavior.
  • Read the return value as one position, not two and not a value: it is the iterator to the first element of the first adjacent pair the test accepts; when no pair is accepted it is the last iterator, which must not be dereferenced - and that end result is also what an empty range and a one-element range return, because neither holds a pair. The fixed programs here print found 4 at index 2 for the textbook case, and vector 4 at index 2, none end, list 4, and two-pairs 2 at index 0 for the return-value cases.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 4 2 under C++98 and C++11, 4 for the forward list, 4 at index 2 for the ranges form at C++20, and find 4, search 4, and adjacent 4 for the neighbor calls.
  • 'std::find' Is Not a Member of 'std' Fix - the single-value member of this guide's family: std::find returns an iterator to the first element equal to a value, from <algorithm> like this guide's name, where std::adjacent_find returns an iterator to the first element whose neighbor matches it - and both fail with the same plain line when the header is missing.
  • 'std::search' Is Not a Member of 'std' Fix - the pattern member of the family: std::search returns an iterator to the first occurrence of a whole pattern range, from <algorithm> like this guide's name, where std::adjacent_find needs no pattern at all - the pair it looks for is defined by the two neighboring elements themselves.

Sources

  • cppreference, std::adjacent_find — for std::adjacent_find being a function template defined in <algorithm>; for the return being an iterator to the first element of the first adjacent pair satisfying the condition, with the last iterator returned when no such pair exists; for the iterators needing to meet the forward-iterator requirements; for the classic form making exactly min(M+1, N-1) comparisons, where M is the distance to the result and N the length of the range; for the classic overloads carrying no "since" marker - the name predates C++11, with a defect report applied to C++98 - and for the execution-policy overloads existing since C++17 and constant-expression use since C++20.
  • cppreference, std::ranges::adjacent_find — for the ranges form existing since C++20 and returning an iterator to the first of the first matching pair, or an iterator equal to last when no pair matches - an iterator result, not a subrange.
  • cppreference, Standard library header <algorithm> — for <algorithm> being the header whose synopsis declares std::adjacent_find, std::find, std::search, and the C++20 std::ranges::adjacent_find, the home-header fact the fix, the neighbor, and the ranges sections of this guide rest on.

Keep Exploring