Cpp Std Is Sorted Not Member Fix | Veldica
layout: landing
explore_theme: programming
analytics_page: cpp_std_is_sorted_not_member_fix
analytics_page_view_event: page_view_cpp_std_is_sorted_not_member_fix
page_title: "'is_sorted' Is Not a Member of 'std' Fix"
page_description: "A program that uses std::is_sorted fails with ''is_sorted' is not a member of 'std'' when the #include
Written December 1, 2026
Tested with GCC 13.3.0
What this guide is
std::is_sorted is a function template defined in the header <algorithm>, since C++11. It reports whether every element of the range [first, last) is sorted: with the plain overload the order is operator< (since C++20, std::less{}), and the comparator overload tests the order with respect to the comparison the program passes instead. It returns true when the range is sorted and false otherwise - and an empty range or a range of one element counts as sorted, so both return true. It makes at most N-1 comparisons, where N is the distance from first to last - a linear pass, with no element ever compared twice against the same neighbor. Both plain overloads are constexpr since C++20. Unlike the heap algorithms in this family, std::is_sorted does have execution-policy overloads, since C++17 - the fixed-programs section below runs one. Actually sorting a range is a separate step: std::sort has its own guide and is not re-taught here, and sorting a heap with std::sort_heap has its own guide too.
Because the template lives in one specific header, 'is_sorted' 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 never prints a note naming<algorithm>, and it never prints note lines or help lines under the error - behind every failing sole header in the sweep the diagnostic is the plain error line and its caret block, or that same line carrying one suggestion tail,; did you mean 'is_signed'?. That suggestion is a trap:std::is_signedis a type trait from<type_traits>, not a sorting test, and following it does not fix the call. The neighboring names probed here -std::sort,std::is_heap,std::is_heap_until, andstd::is_sorted_until, all in the same header - get no suggestion at all 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. The sweep probed here 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 compile error, the same error with the is_signed suggestion tail, or a transitive rescue. The older siblings in this family - std::sort, std::sort_heap, std::make_heap, std::partial_sort, std::nth_element, std::rotate, and std::partition - 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 asks whether an array is sorted with std::is_sorted and returns success if it is, but includes only <limits>:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return std::is_sorted(a, a + 6) ? 0 : 1;
}
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:4:17: error: 'is_sorted' is not a member of 'std'
4 | return std::is_sorted(a, a + 6) ? 0 : 1;
| ^~~~~~~~~
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:
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return std::is_sorted(a, a + 6) ? 0 : 1;
}
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:3:17: error: 'is_sorted' is not a member of 'std'
3 | return std::is_sorted(a, a + 6) ? 0 : 1;
| ^~~~~~~~~
The textbook version fails too - with a suggestion for the wrong name
The version most often written first - ask whether a vector is sorted and print the answer, with std::cout - gets the same error, without <algorithm>, but here the error line carries a tail:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::cout << std::is_sorted(v.begin(), v.end()) << "\n";
return 0;
}
$ g++ -std=c++20 t_textbook.cpp -o t_textbook_prog
t_textbook.cpp: In function 'int main()':
t_textbook.cpp:5:23: error: 'is_sorted' is not a member of 'std'; did you mean 'is_signed'?
5 | std::cout << std::is_sorted(v.begin(), v.end()) << "\n";
| ^~~~~~~~~
| is_signed
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 - but something those headers do pull in declares std::is_signed, and GCC offers that name as the nearest match. It is the wrong name for the job: is_signed answers whether a type is a signed arithmetic type, not whether a range is in order. In the sweep probed here, the only headers that rescue std::is_sorted are <chrono>, <execution>, <functional>, <regex>, and <valarray>, besides <algorithm> itself, and that rescue is a property of this library version, not a rule of the language. A program that uses std::is_sorted includes <algorithm>, whether or not it happens to compile without it.
Neighboring headers: which ones fail plainly, which ones add the suggestion, which ones rescue it
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 asks whether an array is sorted and returns success if it is, the outcome splits by compile result and diagnostic shape three ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines. These 34 headers fail with the plain is not a member of 'std' error, with no suggestion, no note, and no help:
<cassert><cctype><cerrno><cfenv><cfloat><cinttypes><ciso646><climits><clocale><csetjmp><csignal><cstdalign><cstdarg><cstdbool><cstddef><cstdint><cstdio><cstdlib><cstring><ctime><cuchar><cwchar><cwctype><expected><initializer_list><iosfwd><limits><new><source_location><spanstream><stacktrace><stdfloat><typeinfo><version>
These 66 headers fail with the same error carrying the suggestion tail ; did you mean 'is_signed'?, again with no note lines and no help lines:
<any><array><atomic><barrier><bit><bitset><ccomplex><charconv><cmath><codecvt><compare><complex><concepts><condition_variable><coroutine><ctgmath><deque><exception><filesystem><format><forward_list><fstream><future><iomanip><ios><iostream><istream><iterator><latch><list><locale><map><memory><memory_resource><mutex><numbers><numeric><optional><ostream><queue><random><ranges><ratio><scoped_allocator><semaphore><set><shared_mutex><span><sstream><stack><stdexcept><stop_token><streambuf><string><string_view><syncstream><system_error><thread><tuple><type_traits><typeindex><unordered_map><unordered_set><utility><variant><vector>
A file with no include at all fails the plain way. No failing sole header prints note lines or help lines - the only variation in the whole failing set is that one suggestion tail.
A sole <vector> file shows the suggestion shape in full:
#include <vector>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return std::is_sorted(a, a + 6) ? 0 : 1;
}
$ g++ -std=c++20 v_vector.cpp -o v_vector_prog
v_vector.cpp: In function 'int main()':
v_vector.cpp:4:17: error: 'is_sorted' is not a member of 'std'; did you mean 'is_signed'?
4 | return std::is_sorted(a, a + 6) ? 0 : 1;
| ^~~~~~~~~
| is_signed
And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:
<algorithm><chrono><execution><functional><regex><valarray>
Two contrasts with the neighboring sweeps are worth holding on to. First, there is no link-failure shape in this sweep: every failing sole header fails at compile time with the error above, 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, the suggestion class here is large but uniform: all 66 suggestion headers offer the same wrong name, is_signed, because the trait header rides along transitively behind most of the library, while the 34 plain headers are the ones that pull in almost nothing - mostly the C-compatibility headers and a few near-empty ones. <algorithm> - the home header - is on the rescue 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:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> sorted = {1, 2, 3, 4, 5, 6};
std::vector<int> unsorted = {1, 3, 2, 4, 5, 6};
std::cout << std::is_sorted(sorted.begin(), sorted.end()) << " " << std::is_sorted(unsorted.begin(), unsorted.end()) << "\n";
return 0;
}
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
1 0
One include, <algorithm>, declares the template: the sorted vector reports 1, and the vector with 3 and 2 swapped reports 0 - the test distinguishes the two ranges instead of answering 1 for everything.
The fixed programs: empty and single-element ranges, checked element by element
The answer leaves one thing to check independently: every element is at most the one after it, across the whole range. This program runs that element-by-element pass alongside std::is_sorted over the range, and reports the empty and single-element answers beside it:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> e;
std::vector<int> one = {7};
std::vector<int> v = {1, 2, 3, 4, 5, 6};
bool ok = std::is_sorted(v.begin(), v.end());
for (std::size_t i = 1; i < v.size(); ++i) ok = ok && (v[i - 1] <= v[i]);
std::cout << ok << " " << std::is_sorted(e.begin(), e.end()) << " " << std::is_sorted(one.begin(), one.end()) << "\n";
return 0;
}
$ g++ -std=c++20 k_values.cpp -o k_values_prog
$ ./k_values_prog
1 1 1
The comparator overload tests the order the program passes instead: with std::greater<int>() from <functional>, a descending range counts as sorted and the same range under the plain order does not - the program prints 1 0:
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {6, 5, 4, 3, 2, 1};
std::cout << std::is_sorted(v.begin(), v.end(), std::greater<int>()) << " " << std::is_sorted(v.begin(), v.end()) << "\n";
return 0;
}
$ g++ -std=c++20 j_comp.cpp -o j_comp_prog
$ ./j_comp_prog
1 0
There is also an execution-policy version to run - the contrast with the heap algorithms in this family, which have none. Passing std::execution::par as a first argument selects the policy overload that has existed since C++17, and the call compiles and runs, printing 1 for the sorted vector:
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::cout << std::is_sorted(std::execution::par, v.begin(), v.end()) << "\n";
return 0;
}
$ g++ -std=c++20 j_policy.cpp -o j_policy_prog
$ ./j_policy_prog
1
So a sortedness test can take a policy where a heap sort cannot; the policy overloads are part of this name's own overload set, and <execution> is the header the policy argument itself comes from.
The neighboring names: same header, plain in the lean context
The names that std::is_sorted is built alongside share its home header. In the lean context here - only <limits> included - they get no suggestion at all. std::sort - the function template defined in <algorithm> that sorts a range - gets its own error, again with no header note. Its own guide covers its error and its fix in full; it is shown here only as a neighbor:
#include <limits>
int main() {
int a[] = {3, 1, 2};
std::sort(a, a + 3);
return a[0] == 1 ? 0 : 1;
}
$ g++ -std=c++20 b_sort.cpp -o b_sort_prog
b_sort.cpp: In function 'int main()':
b_sort.cpp:4:10: error: 'sort' is not a member of 'std'
4 | std::sort(a, a + 3);
| ^~~~
std::is_heap - the function template defined in <algorithm> that reports whether a range is a heap - fails the same way:
#include <limits>
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
return std::is_heap(a, a + 6) ? 0 : 1;
}
$ g++ -std=c++20 b_is_heap.cpp -o b_is_heap_prog
b_is_heap.cpp: In function 'int main()':
b_is_heap.cpp:4:17: error: 'is_heap' is not a member of 'std'
4 | return std::is_heap(a, a + 6) ? 0 : 1;
| ^~~~~~~
std::is_heap_until - the function template defined in <algorithm> that finds the largest subrange that is a heap - fails the same way:
#include <limits>
int main() {
int a[] = {6, 5, 4, 2, 3, 1};
return std::is_heap_until(a, a + 6) == a + 6 ? 0 : 1;
}
$ g++ -std=c++20 b_is_heap_until.cpp -o b_is_heap_until_prog
b_is_heap_until.cpp: In function 'int main()':
b_is_heap_until.cpp:4:17: error: 'is_heap_until' is not a member of 'std'
4 | return std::is_heap_until(a, a + 6) == a + 6 ? 0 : 1;
| ^~~~~~~~~~~~~
And std::is_sorted_until - the function template defined in <algorithm> that finds the largest subrange that is sorted - fails the same way, again with no header note:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return std::is_sorted_until(a, a + 6) == a + 6 ? 0 : 1;
}
$ g++ -std=c++20 b_is_sorted_until.cpp -o b_is_sorted_until_prog
b_is_sorted_until.cpp: In function 'int main()':
b_is_sorted_until.cpp:4:17: error: 'is_sorted_until' is not a member of 'std'
4 | return std::is_sorted_until(a, a + 6) == a + 6 ? 0 : 1;
| ^~~~~~~~~~~~~~~
One contrast is worth holding on to: in the lean programs here, is_sorted, sort, is_heap, is_heap_until, and is_sorted_until all get no note, and only is_sorted behind the wider headers gets a suggestion - and that suggestion names the wrong name anyway. Do not read either shape as a puzzle - in this probed set the fix comes from the names' home, <algorithm>, either way.
The neighboring names, fixed
And the neighboring names work under the same one added header: sorting a vector and confirming it gives 1, a heap confirms as a heap with 1, its heap prefix runs to the end with 1, and the sorted vector's sorted prefix runs to the end with 1:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {5, 1, 4, 2, 3, 6};
std::sort(v.begin(), v.end());
bool s = std::is_sorted(v.begin(), v.end());
std::vector<int> h = {6, 5, 4, 2, 3, 1};
bool hh = std::is_heap(h.begin(), h.end());
bool hu = std::is_heap_until(h.begin(), h.end()) == h.end();
bool su = std::is_sorted_until(v.begin(), v.end()) == v.end();
std::cout << s << " " << hh << " " << hu << " " << su << "\n";
return 0;
}
$ g++ -std=c++20 k_neighbors_fixed.cpp -o k_neighbors_fixed_prog
$ ./k_neighbors_fixed_prog
1 1 1 1
Since C++20 the same <algorithm> header also declares std::ranges::is_sorted, the ranges form of the same test. It comes in two call shapes - an iterator pair, and a single range - and returns the answer directly: here both shapes report 1 for the sorted vector and the single-range shape reports 0 for the unsorted one, printing 1 1 0. 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. Behind a sole <vector> the wording changes: the namespace exists there, but the name is missing from it, so the error is 'is_sorted' is not a member of 'std::ranges':
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> w = {1, 3, 2, 4, 5, 6};
std::cout << std::ranges::is_sorted(v.begin(), v.end()) << " " << std::ranges::is_sorted(v) << " " << std::ranges::is_sorted(w) << "\n";
return 0;
}
$ g++ -std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
1 1 0
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return std::ranges::is_sorted(a, a + 6) ? 0 : 1;
}
$ 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:17: error: 'std::ranges' has not been declared
4 | return std::ranges::is_sorted(a, a + 6) ? 0 : 1;
| ^~~~~~
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
return std::ranges::is_sorted(v.begin(), v.end()) ? 0 : 1;
}
$ g++ -std=c++20 r3_ranges_vector.cpp -o r3_ranges_vector_prog
r3_ranges_vector.cpp: In function 'int main()':
r3_ranges_vector.cpp:4:25: error: 'is_sorted' is not a member of 'std::ranges'
4 | return std::ranges::is_sorted(v.begin(), v.end()) ? 0 : 1;
| ^~~~~~~~~
A different wording - and cases where the qualifier is not needed, and where it is
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:
#include <algorithm>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return is_sorted(a, a + 6) ? 0 : 1;
}
$ 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:12: error: 'is_sorted' was not declared in this scope
4 | return is_sorted(a, a + 6) ? 0 : 1;
| ^~~~~~~~~
g2_unqualified_ptr.cpp:4:12: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
from g2_unqualified_ptr.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:394:1: note: 'std::is_sorted'
394 | is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
| ^~~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:2017:35: note: 'std::ranges::is_sorted'
2017 | inline constexpr __is_sorted_fn is_sorted{};
| ^~~~~~~~~
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 notes do name the right names - the first points at std::is_sorted itself, shown at its execution-policy declaration in the internal header the transcript names, and the second at std::ranges::is_sorted. Qualify the name as std::is_sorted; adding includes does not bring the name out of namespace std.
The same unqualified call with std::array iterators as its arguments fails the same way, for the same underlying reason on this library version - a std::array iterator is a raw pointer here, so it belongs to no namespace either:
#include <algorithm>
#include <array>
#include <iostream>
int main() {
std::array<int, 6> a = {1, 2, 3, 4, 5, 6};
std::cout << is_sorted(a.begin(), a.end()) << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified_array.cpp -o g_unqualified_array_prog
g_unqualified_array.cpp: In function 'int main()':
g_unqualified_array.cpp:6:18: error: 'is_sorted' was not declared in this scope
6 | std::cout << is_sorted(a.begin(), a.end()) << "\n";
| ^~~~~~~~~
g_unqualified_array.cpp:6:18: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:73,
from g_unqualified_array.cpp:1:
/usr/include/c++/13/pstl/glue_algorithm_defs.h:394:1: note: 'std::is_sorted'
394 | is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
| ^~~~~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:2017:35: note: 'std::ranges::is_sorted'
2017 | inline constexpr __is_sorted_fn is_sorted{};
| ^~~~~~~~~
The same unqualified call with std::vector iterators as its arguments behaves differently - it compiles and runs, printing 1, the answer for the sorted vector:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::cout << is_sorted(v.begin(), v.end()) << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified.cpp -o g_unqualified_prog
$ ./g_unqualified_prog
1
What happened: the vector iterators belong to namespace std, so argument-dependent lookup finds std::is_sorted 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, and over this library version's std::array iterators, fails, as the transcripts above show. Write the qualifier either way.
The exact rule
std::is_sortedis declared by#include <algorithm>, and by no other header by rule. In the sweep probed here,, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , - ,
, 'is_sorted' is not a member of 'std'means the<algorithm>include is missing and nothing else in the file pulled the name in. In the contexts probed here, GCC prints no note naming<algorithm>, no note lines, and no help lines under it - behind 34 failing sole headers the error line is plain, and behind 66 it carries the one suggestion tail; did you mean 'is_signed'?, which names a type trait, not this algorithm.- In the sweep probed here, the split is three-way: a sole header either fails plainly, fails with the
is_signedsuggestion tail, or rescues the program. No probed sole header produces a declared-but-not-defined link-failure shape for this name. - In the sweep probed here, only five headers besides
<algorithm>rescuestd::is_sortedtransitively -<chrono>,<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, those headers are not required to pullstd::is_sortedin. std::is_sortedhas the plain and comparator overloads, bothconstexprsince C++20, and execution-policy overloads since C++17: passingstd::execution::parwith<algorithm>and<execution>included compiles and runs, unlike the heap algorithms in this family, which have no policy overload.std::sort,std::is_heap,std::is_heap_until, andstd::is_sorted_untilare declared by the same#include <algorithm>: in the programs shown here, which include only<limits>beside the use, each gets its ownis not a member of 'std'error when that include is missing, with no header note and no suggestion.std::ranges::is_sortedis declared by the same#include <algorithm>since C++20: with the include it reports the answer in both its iterator-pair and its single-range call shapes; in the lean context probed here it gets the error'std::ranges' has not been declaredwhen that include is missing, and behind a sole<vector>it gets'is_sorted' is not a member of 'std::ranges'.'is_sorted' was not declared in this scopefor an unqualifiedis_sorteduse over raw pointers - and overstd::arrayiterators on this library version - is a different defect: qualify the name asstd::is_sorted- the include alone does not bring the name out of namespacestd. The same unqualified use overstd::vectoriterators 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::is_sorted. If<algorithm>is not there, add it - that is the fix in the common case, and it holds whether the file failed plainly, failed with the suggestion tail, or happened to compile before through a transitive rescue. - Second, do not follow the suggestion when one appears. For this error, in the contexts probed here, the only suggestion GCC prints is
is_signed- a type trait from<type_traits>that tests a type, not a range - and no note ever names the header. Take the fix from the name's home header,<algorithm>, instead. - Third, do not reach for
<utility>because the error sentence looks like thestd::swaperror. In the sweep probed here,<utility>as the only include fails with the same error, suggestion tail and all - the two names live in different headers, and each takes its own. - 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<chrono>,<execution>,<functional>,<regex>, and<valarray>rescue it, and that rescue is not guaranteed. - Fifth, an execution policy is allowed here, unlike the heap algorithms: the policy overloads have existed since C++17, so a policy call that fails is failing for another reason - check that
<algorithm>and<execution>are both included before changing the call. - Sixth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::is_sortedas well - and do not rely on an unqualified call that happens to compile overstdvector iterators, because the same call over raw pointers and overstd::arrayiterators fails. - Seventh, if the failing name is a neighboring one, check its header before fixing:
sort,is_heap,is_heap_until, andis_sorted_untiltake the same added<algorithm>, whileswaptakes<utility>.
Which fix for which cause
#include <algorithm>missing,std::is_sortedused in a file whose only include is one of the 34 headers listed as plain in the sweep section above, or that includes nothing: the message is'is_sorted' is not a member of 'std', with no suggestion, no header note, and no help - add#include <algorithm>.#include <algorithm>missing,std::is_sortedused in a file whose only include is one of the 66 headers listed as suggestion in the sweep section above: the message is the same error ending; did you mean 'is_signed'?- add#include <algorithm>, and do not substitutestd::is_signed.std::is_sortedused in a textbook file including<iostream>and<vector>: the message is the same error, with theis_signedsuggestion tail - add#include <algorithm>.std::is_sortedused with only<algorithm>,<chrono>,<execution>,<functional>,<regex>, or<valarray>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::is_sortedcalled with an execution policy as its first argument,<algorithm>and<execution>included: no error - the policy overloads exist since C++17 and the call runs.std::sort,std::is_heap,std::is_heap_until, orstd::is_sorted_untilused without<algorithm>in the lean context: the message names that name, plainly, with no header note - add#include <algorithm>.std::ranges::is_sortedused without<algorithm>in the lean context: the message is'std::ranges' has not been declared- add#include <algorithm>. Behind a sole<vector>the message is'is_sorted' is not a member of 'std::ranges'- the same fix.is_sortedused without thestd::qualifier,<algorithm>included, over raw pointers orstd::arrayiterators: the message is'is_sorted' was not declared in this scope- qualify the name asstd::is_sorted. Overstd::vectoriterators 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 test, not just the project. The include must be in that file, or in a header that file includes directly by design.
- Do not follow the
is_signedsuggestion, and do not wait for a note naming the header. For this error, in the contexts probed here, GCC prints that one wrong suggestion behind 66 headers and no note naming<algorithm>behind any of them - take the fix from the name's home header,<algorithm>, instead. - Do not import the
std::swapfix into this error: in the probed set,<utility>fails here too, with the suggestion tail. 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 rescuestd::is_sortedat all, and the five headers that do rescue it do so only transitively. - One header per name the file uses:
std::vectorcomes from<vector>andstd::stringcomes from<string>, even in a program whose subject is the test - andstd::is_sortedcomes from<algorithm>in return. The comparator overload'sstd::greatercomes from<functional>, and the execution-policy overloads' policy comes from<execution>. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
1 0for the sorted and unsorted vectors, and1 1 1for the sorted-order check over the range and the empty and single-element answers.
Related guides
- 'std::sort' Is Not a Member of 'std' Fix - the same missing-include shape for the full sorting function template in
<algorithm>, the operation this guide's test checks the result of: its own full header sweep, its error, and its fix are covered there. - 'std::sort_heap' Is Not a Member of 'std' Fix - the same missing-include shape for the heap-sorting function template in
<algorithm>: its own full header sweep, its error, and its fix are covered there, and its sweep has no suggestion class at all, where this guide's suggestion class is the larger half of its failing set. - 'std::make_heap' Is Not a Member of 'std' Fix - the same missing-include shape for the heap-construction function template in
<algorithm>: its own full header sweep, its error, and its fix are covered there.
Sources
- cppreference,
std::is_sorted— forstd::is_sortedbeing a function template defined in<algorithm>since C++11 that checks whether all elements of[first, last)are sorted, with respect tooperator<(until C++20) /std::less{}(since C++20) for the plain overload and a comparator overload, bothconstexprsince C++20, execution-policy overloads since C++17, a linear number of comparisons - at most N-1 for a range of length N - returnstrueif all elements are sorted andfalseotherwise, andtruefor empty ranges and ranges of length one. - cppreference, Standard library header
<algorithm>— for<algorithm>being the header that declaresstd::is_sortedand the neighboring algorithm names, including thestd::ranges::is_sortedalgorithm function object since C++20. - cppreference,
std::ranges::is_sorted— forstd::ranges::is_sortedbeing an algorithm function object defined in<algorithm>since C++20,constexpr, constrained to forward iterators and ranges, in an iterator-sentinel form and a range form, that checks whether a range is sorted and returns that answer, at a linear number of applications of the comparison and twice as many applications of the projection. - cppreference,
std::is_sorted_until— forstd::is_sorted_untilbeing a function template defined in<algorithm>that finds the largest subrange that is sorted. - cppreference,
std::sort— forstd::sortbeing a function template defined in<algorithm>that sorts a range. - cppreference,
std::is_heap— forstd::is_heapbeing a function template defined in<algorithm>that checks whether a range is a heap. - cppreference,
std::is_heap_until— forstd::is_heap_untilbeing a function template defined in<algorithm>that finds the largest subrange that is a heap.