C++
'std::rotate' Is Not a Member of 'std' Fix
std::rotate lives in one header, <algorithm> - and on this library version almost no ordinary file rescues it by accident: in the sweep probed here, covering all 106 standard headers in the library's header set, only <functional>, <chrono>, <execution>, <regex>, and <valarray> pull the name in on the side, and the textbook combination of <iostream> and <vector> does not. The error therefore surfaces in textbook files as well as lean ones, and in the sweep probed here it splits by compile result only two ways - the plain error, with no suggestion tail, no note lines, and no help lines in any probed failing context, or one of those five transitive rescues - with no link-failure shape behind any probed header. This guide pins down both outcomes, which probed headers cause each one, and the one include that fixes the error by specification.
Written December 1, 2026 · Tested with GCC 13.3.0 · 22 min read
- The error: the include is missing, in a lean file
- A neighboring header does not rescue it: only <utility>
- The textbook version fails too - plainly, with no suggestion
- Neighboring headers: which ones fail, which ones rescue it
Written December 1, 2026
Tested with GCC 13.3.0
What this guide is
std::rotate is a function template defined in the header <algorithm>. It performs a left rotation on the range [first, last): the elements in [first, middle) are placed after the elements in [middle, last), with the order of the elements inside each part preserved, and it returns an iterator to the element originally pointed to by first - or last if middle equals first. The plain overload is constexpr since C++20; a second overload, since C++17, takes an execution policy as its first argument. The plain overload makes at most std::distance(first, last) swaps, and its iterators must be forward iterators. To rotate into a separate output range instead of in place, std::rotate_copy is the tool.
Because the template lives in one specific header, 'rotate' is not a member of 'std' has one common cause:
- The
#include <algorithm>line is missing, and no other header in the file pulls the name in transitively. For this error, in the contexts probed here, GCC prints no note naming<algorithm>, no suggestion on the error line, no note lines, and no help lines, so the fix has to come from knowing the name's home, not from reading a diagnostic tail. The neighboring names probed here -std::reverse,std::partition, andstd::sort, all in the same header - are silent the same way in the same lean context, as the neighboring-names section shows.
What makes this error worth separating from its relatives is the shape of the sweep behind it. The sweep probed here is the widest in this family: every one of the 106 standard headers in this library's header set was compiled as the only header in the program, and the outcome still splits by compile result only two ways - the plain compile error, or a transitive rescue - and the rescue side is exactly the five-header list its closest sibling produced: std::partition, probed in its own guide, is rescued by <functional>, <chrono>, <execution>, <regex>, and <valarray>, and std::rotate is rescued by the same five, no more, across the full header set. There is also no near-name trap in this sweep: no probed header declares a similarly named std name that GCC could offer as a suggestion - std::rotate_copy, the closest relative, lives in <algorithm> itself, and no probed sole header declares it without also declaring rotate, as its own mini-sweep below shows. The older siblings in this family - std::reverse, std::partition, std::sort, and std::find - have their own guides and are linked at the end, not re-taught here.
The error: the include is missing, in a lean file
This program rotates an array left by two positions with std::rotate and returns success if the returned iterator lands at index 4, but includes only <limits>:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return std::rotate(a, a + 2, a + 6) - a == 4 ? 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: 'rotate' is not a member of 'std'
4 | return std::rotate(a, a + 2, a + 6) - a == 4 ? 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::rotate(a, a + 2, a + 6) - a == 4 ? 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: 'rotate' is not a member of 'std'
3 | return std::rotate(a, a + 2, a + 6) - a == 4 ? 0 : 1;
| ^~~~~~
A neighboring header does not rescue it: only <utility>
A reader coming from the std::swap error might reach for <utility> first. In the program probed here it changes nothing - the same plain error, at the same position:
#include <utility>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return std::rotate(a, a + 2, a + 6) - a == 4 ? 0 : 1;
}
$ g++ -std=c++20 u_utility.cpp -o u_utility_prog
u_utility.cpp: In function 'int main()':
u_utility.cpp:4:17: error: 'rotate' is not a member of 'std'
4 | return std::rotate(a, a + 2, a + 6) - a == 4 ? 0 : 1;
| ^~~~~~
That is expected once the homes are separated: <utility> declares std::swap, and std::rotate is not one of its names. The two errors share a shape and a sentence pattern, but each name takes its own header, and the fix below is <algorithm>, not the swap fix.
The textbook version fails too - plainly, with no suggestion
The version most often written first - rotate a vector left by two positions and print where the returned iterator lands, with std::cout - gets the same error, without <algorithm>:
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::cout << std::rotate(v.begin(), v.begin() + 2, v.end()) - v.begin() << "\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: 'rotate' is not a member of 'std'
5 | std::cout << std::rotate(v.begin(), v.begin() + 2, v.end()) - v.begin() << "\n";
| ^~~~~~
What happened: on this library version, neither <vector> nor <iostream> pulls this name in transitively, so the call fails in a textbook file just as it does in a lean one. The error is also exactly as plain here as in the lean file: there is no did you mean tail on the error line, no note lines, and no help lines. Do not wait for a suggestion to point the way: the fix for the name the program means is the include below. In the sweep probed here, the only headers that rescue std::rotate are <functional>, <chrono>, <execution>, <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::rotate includes <algorithm>, whether or not it happens to compile without it.
Neighboring headers: which ones fail, which ones rescue it
In a sweep where each of the 106 standard headers in this library's header set was compiled as the only header in a program that rotates an array left by two positions and returns whether the returned iterator lands at index 4 and the rotated ends hold 3 and 2, the outcome splits by compile result two ways. Every diagnostic component was classified separately - the error line, any suggestion tail on it, any note lines, and any help lines - and these 100 headers fail with the plain is not a member of 'std' error, with no suggestion, no note, and no help:
<any><array><atomic><barrier><bit><bitset><cassert><ccomplex><cctype><cerrno><cfenv><cfloat><charconv><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 way. And these headers rescue the program - it compiles and runs with no <algorithm> anywhere in the file:
<algorithm><functional><chrono><execution><regex><valarray>
Two contrasts with the neighboring sweeps are worth holding on to. First, the split here is two-way: in the sweep probed here, every failing sole header fails at compile time with the plain error - each one was also compiled to an object file on its own, and that step failed the same way - so the declared-but-not-defined link failure that std::swap produces behind five headers has no counterpart for this name in the probed set. Second, there is no suggestion class in this sweep at all, and no near-name trap either: <semaphore>, which adds a did you mean 'binary_semaphore'? tail to the std::binary_search error, fails plainly here, and <ranges> - the header a reader might expect to carry the ranges form - fails plainly for the plain name too. The closest relative, std::rotate_copy, was swept on its own over eight sole headers: it fails plainly with <limits>, <vector>, <iostream>, and <ranges>, and is rescued by <algorithm>, <functional>, <chrono>, and <execution> - so no probed header in that set makes rotate_copy visible while rotate stays missing, and GCC never gets the chance to offer one as a suggestion for the other. The rescue list, though, matches the short lists in this family: <algorithm> - the home header - is on this list by definition, not by transitivity, and every other rescue on that list is this library version's behavior, not a guarantee.
The fix
Add the header:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
auto point = std::rotate(v.begin(), v.begin() + 2, v.end());
std::cout << (point - v.begin());
for (int x : v) std::cout << " " << x;
std::cout << "\n";
return 0;
}
$ g++ -std=c++20 h_fixed.cpp -o h_fixed_prog
$ ./h_fixed_prog
4 3 4 5 6 1 2
One include, <algorithm>, declares the template. Rotating 1, 2, 3, 4, 5, 6 left by two moves 3, 4, 5, 6 to the front and 1, 2 to the back, and the returned iterator points at the element that was first - 1, now at index 4 - so the program prints 4 followed by the rotated contents.
The fixed programs: the point follows the split
With <algorithm> added, std::rotate answers to whatever split point the program passes. Rotating three copies of the same vector at split points 1, 2, and 5 puts the returned iterator at index 5, 4, and 1 respectively - in each case 6 minus the split, the new home of the element that started first - and the first element after each rotation is the element that sat at the split:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> a = {1, 2, 3, 4, 5, 6};
std::vector<int> b = {1, 2, 3, 4, 5, 6};
std::vector<int> c = {1, 2, 3, 4, 5, 6};
std::cout << std::rotate(a.begin(), a.begin() + 1, a.end()) - a.begin() << " " << std::rotate(b.begin(), b.begin() + 2, b.end()) - b.begin() << " " << std::rotate(c.begin(), c.begin() + 5, c.end()) - c.begin() << "\n";
std::cout << a[0] << " " << b[0] << " " << c[0] << "\n";
return 0;
}
$ g++ -std=c++20 i_cases.cpp -o i_cases_prog
$ ./i_cases_prog
5 4 1
2 3 6
The two edge splits behave as the return rule says. When the middle iterator equals the first, nothing moves and the function returns last - index 6 here; when the middle equals the last, nothing moves either and the function returns first - index 0. Both vectors still start with 1:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> a = {1, 2, 3, 4, 5, 6};
std::vector<int> b = {1, 2, 3, 4, 5, 6};
std::cout << std::rotate(a.begin(), a.begin(), a.end()) - a.begin() << " " << std::rotate(b.begin(), b.end(), b.end()) - b.begin() << "\n";
std::cout << a[0] << " " << b[0] << "\n";
return 0;
}
$ g++ -std=c++20 k_edges.cpp -o k_edges_prog
$ ./k_edges_prog
6 0
1 1
The rotated order is exact, not just a moved first element: after rotating by two, every element matches the expected order 3, 4, 5, 6, 1, 2, which this program checks element by element and reports as 1, alongside the returned point at index 4 and the value it points at, 1 - the element that started the range:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
auto point = std::rotate(v.begin(), v.begin() + 2, v.end());
const int want[] = {3, 4, 5, 6, 1, 2};
bool ok = true;
for (int i = 0; i < 6; ++i) ok = ok && (v[i] == want[i]);
std::cout << ok << " " << (point - v.begin()) << " " << *point << "\n";
return 0;
}
$ g++ -std=c++20 k_values.cpp -o k_values_prog
$ ./k_values_prog
1 4 1
The execution-policy overload - the second overload, since C++17 - takes the policy as its first argument and needs <execution> for the policy itself. With std::execution::par the same rotation puts the returned iterator at the same index, 4, and the same first element, 3:
#include <algorithm>
#include <execution>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::cout << std::rotate(std::execution::par, v.begin(), v.begin() + 2, v.end()) - v.begin() << " " << v[0] << "\n";
return 0;
}
$ g++ -std=c++20 j_policy.cpp -o j_policy_prog
$ ./j_policy_prog
4 3
The neighboring names: same header, same silence
The names that std::rotate is built alongside share its home header and its silence. std::reverse - the function template defined in <algorithm> that reverses the order of the elements in a range - gets its own error, again with no header note:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
std::reverse(a, a + 6);
return a[0] == 6 ? 0 : 1;
}
$ g++ -std=c++20 b_reverse.cpp -o b_reverse_prog
b_reverse.cpp: In function 'int main()':
b_reverse.cpp:4:10: error: 'reverse' is not a member of 'std'
4 | std::reverse(a, a + 6);
| ^~~~~~~
std::partition - the function template defined in <algorithm> that reorders a range so the elements satisfying a predicate come first - fails the same way:
#include <limits>
int main() {
int a[] = {5, 1, 4, 2, 3, 6};
return std::partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
}
$ g++ -std=c++20 c_partition.cpp -o c_partition_prog
c_partition.cpp: In function 'int main()':
c_partition.cpp:4:17: error: 'partition' is not a member of 'std'
4 | return std::partition(a, a + 6, [](int x) { return x % 2 == 0; }) - a == 3 ? 0 : 1;
| ^~~~~~~~~
std::sort - the function template defined in <algorithm> that sorts a range into ascending order - fails the same way:
#include <limits>
int main() {
int a[] = {5, 1, 4, 2, 3, 6};
std::sort(a, a + 6);
return a[0] == 1 ? 0 : 1;
}
$ g++ -std=c++20 d_sort.cpp -o d_sort_prog
d_sort.cpp: In function 'int main()':
d_sort.cpp:4:10: error: 'sort' is not a member of 'std'
4 | std::sort(a, a + 6);
| ^~~~
And the closest relative of all, std::rotate_copy - the function template defined in <algorithm> that copies the rotated order into a separate output range, leaving the source unchanged - fails the same way, again with no header note:
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {0, 0, 0, 0, 0, 0};
return std::rotate_copy(a, a + 2, a + 6, b) - b == 6 ? 0 : 1;
}
$ g++ -std=c++20 p_copy_lean.cpp -o p_copy_lean_prog
p_copy_lean.cpp: In function 'int main()':
p_copy_lean.cpp:5:17: error: 'rotate_copy' is not a member of 'std'
5 | return std::rotate_copy(a, a + 2, a + 6, b) - b == 6 ? 0 : 1;
| ^~~~~~~~~~~
One contrast is worth holding on to: in the lean programs here, rotate, reverse, partition, sort, and rotate_copy all get no note and no suggestion. Do not read the absence of a diagnostic tail as a puzzle to solve - in this probed set the tail is simply absent for this header's names in this context, and the fix comes from the names' home, <algorithm>.
The neighboring names, fixed
And the neighboring names work under the same one added header: sorting 5, 1, 4, 2, 3, 6 and then reversing it puts 6 first and 1 last, and partitioning that descending range by even puts the partition point at index 3:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {5, 1, 4, 2, 3, 6};
std::sort(v.begin(), v.end());
std::reverse(v.begin(), v.end());
std::cout << v[0] << " " << v[5] << " " << (std::partition(v.begin(), v.end(), [](int x) { return x % 2 == 0; }) - v.begin()) << "\n";
return 0;
}
$ g++ -std=c++20 k_neighbors_fixed.cpp -o k_neighbors_fixed_prog
$ ./k_neighbors_fixed_prog
6 1 3
std::rotate_copy writes the rotated order into the output range and leaves the source alone: the output holds 3, 4, 5, 6, 1, 2, the returned iterator sits one past its end at index 6, and the source vector still starts with 1:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> out(6);
auto end = std::rotate_copy(v.begin(), v.begin() + 2, v.end(), out.begin());
std::cout << (end - out.begin());
for (int x : out) std::cout << " " << x;
std::cout << " " << v[0] << "\n";
return 0;
}
$ g++ -std=c++20 k_copy_fixed.cpp -o k_copy_fixed_prog
$ ./k_copy_fixed_prog
6 3 4 5 6 1 2 1
Since C++20 the same <algorithm> header also declares std::ranges::rotate, the ranges form of the same rotation. It comes in two call shapes - an iterator triple, and a range plus the middle iterator - and both return the subrange from the new position of the original first element to the end of the range: here both put that subrange's beginning at index 4 and leave 3 at the front. 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:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::vector<int> w = {1, 2, 3, 4, 5, 6};
auto tail = std::ranges::rotate(v.begin(), v.begin() + 2, v.end());
auto tail2 = std::ranges::rotate(w, w.begin() + 2);
std::cout << (tail.begin() - v.begin()) << " " << v[0] << " " << (tail2.begin() - w.begin()) << " " << w[0] << "\n";
return 0;
}
$ g++ -std=c++20 r_ranges.cpp -o r_ranges_prog
$ ./r_ranges_prog
4 3 4 3
#include <limits>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
auto tail = std::ranges::rotate(a, a + 2, a + 6);
return tail.begin() - a == 4 ? 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:22: error: 'std::ranges' has not been declared
4 | auto tail = std::ranges::rotate(a, a + 2, a + 6);
| ^~~~~~
A different wording - and a case where the qualifier is not needed
Including <algorithm> is not the only half of the name - but for this function the unqualified form behaves two ways, and which one a program gets depends on its arguments. This program includes the header, drops the std:: qualifier, and passes raw pointers into a C array:
#include <algorithm>
int main() {
int a[] = {1, 2, 3, 4, 5, 6};
return rotate(a, a + 2, a + 6) - a == 4 ? 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: 'rotate' was not declared in this scope
4 | return rotate(a, a + 2, a + 6) - a == 4 ? 0 : 1;
| ^~~~~~
g2_unqualified_ptr.cpp:4:12: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:61,
from g2_unqualified_ptr.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:1390:5: note: 'std::_V2::rotate'
1390 | rotate(_ForwardIterator __first, _ForwardIterator __middle,
| ^~~~~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:1473:32: note: 'std::ranges::rotate'
1473 | inline constexpr __rotate_fn rotate{};
| ^~~~~~
That wording - was not declared in this scope - is a different defect with a different fix: the header is present, the qualifier is not, and raw pointers belong to no namespace, so no lookup finds the name. Here the suggestions do name the right names - the first points at std::rotate itself, shown under its internal inline namespace as std::_V2::rotate at the declaration in the internal header the transcript names, and the second at std::ranges::rotate. Qualify the name as std::rotate; adding includes does not bring the name out of namespace std.
The same unqualified call with std::vector iterators as its arguments behaves differently - it compiles and runs, printing 4:
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
std::vector<int> v = {1, 2, 3, 4, 5, 6};
std::cout << rotate(v.begin(), v.begin() + 2, v.end()) - v.begin() << "\n";
return 0;
}
$ g++ -std=c++20 g_unqualified.cpp -o g_unqualified_prog
$ ./g_unqualified_prog
4
What happened: the iterators belong to namespace std, so argument-dependent lookup finds std::rotate from the arguments themselves, even without the qualifier. That is a property of the argument types, not a style to rely on: the same call over raw pointers fails, as the transcript above shows. Write the qualifier either way.
The exact rule
std::rotateis declared by#include <algorithm>, and by no other header by rule. In the sweep probed here,, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , - ,
, 'rotate' is not a member of 'std'means the<algorithm>include is missing and nothing else in the file pulled the name in - and, in the contexts probed here, GCC prints no note naming<algorithm>, no suggestion on the error line, no note lines, and no help lines under it, in the textbook context as well as the lean ones.- In the sweep probed here, the split by compile result is two-way: a sole header either fails with that plain compile error or rescues the program. Each failing sole header also failed when compiled to an object file on its own, so the probed set contains no declared-but-not-defined link-failure shape for this name.
- In the sweep probed here, only five headers besides
<algorithm>rescuestd::rotatetransitively -<functional>,<chrono>,<execution>,<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::rotatein. std::reverse,std::partition,std::sort, andstd::rotate_copyare 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.std::ranges::rotateis declared by the same#include <algorithm>since C++20: with the include it rotates the range and returns the subrange from the new position of the original first element to the end, in both its iterator-triple and its range-plus-middle call shapes, and in the lean context probed here it gets the error'std::ranges' has not been declaredwhen that include is missing.'rotate' was not declared in this scopefor an unqualifiedrotateuse over raw pointers is a different defect: qualify the name asstd::rotate- 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::rotate. If<algorithm>is not there, add it - that is the fix in the common case, and it holds whether the file failed at compile time or happened to compile before through a transitive rescue. - Second, do not wait for a diagnostic tail to name the fix. In the contexts probed here this error carries no suggestion, no note, and no help - take the fix from the name the program means and its home header,
<algorithm>. - Third, do not reach for
<utility>because the error sentence looks like thestd::swaperror. In the program probed here,<utility>as the only include fails with the same plain error - 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<functional>,<chrono>,<execution>,<regex>, and<valarray>rescue it, and that rescue is not guaranteed. - Fifth, if the error says
was not declared in this scopeinstead, fix the name's qualifier tostd::rotateas well - and do not rely on an unqualified call that happens to compile overstditerators, because the same call over raw pointers fails. - Sixth, if the failing name is a neighboring one, check its header before fixing:
reverse,partition,sort, androtate_copytake the same added<algorithm>, whileswaptakes<utility>.
Which fix for which cause
#include <algorithm>missing,std::rotateused in a file whose only include is one of the 100 headers listed in the sweep section above, or that includes nothing: the message is'rotate' is not a member of 'std', with no suggestion, no header note, and no help - add#include <algorithm>.std::rotateused in a textbook file including<iostream>and<vector>: the message is the same plain error, with no suggestion - add#include <algorithm>.std::rotateused with only<algorithm>,<functional>,<chrono>,<execution>,<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::reverse,std::partition,std::sort, orstd::rotate_copyused without<algorithm>in the lean context: the message names that name, with no header note - add#include <algorithm>.std::ranges::rotateused without<algorithm>in the lean context: the message is'std::ranges' has not been declared- add#include <algorithm>.rotateused without thestd::qualifier,<algorithm>included, over raw pointers: the message is'rotate' was not declared in this scope- qualify the name asstd::rotate. 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 rotation, not just the project. The include must be in that file, or in a header that file includes directly by design.
- Do not wait for a note or a suggestion naming the header. For this error, in the contexts probed here, GCC prints neither for
rotate- 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 the same plain way as<limits>does. Split neighboring names by home header first. - Do not assume the textbook includes rescue this name, and do not delete a working
<algorithm>line because a file compiles without it. In the sweep here<iostream>and<vector>do not rescuestd::rotateat 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 rotation - andstd::rotatecomes from<algorithm>in return. The execution-policy overload additionally takes<execution>for the policy object itself. - After the fix, confirm the program runs, not just that it compiles: the fixed programs here print
4 3 4 5 6 1 2for the returned point and the rotated contents, and1 4 1for the order check, the point, and the value it points at.
Related guides
- 'std::reverse' Is Not a Member of 'std' Fix - the same missing-include shape for the order-reversing function template in
<algorithm>, an older sibling in this family whose own guide covers its error and its fix. - 'std::partition' Is Not a Member of 'std' Fix - the same missing-include shape for the predicate reordering in
<algorithm>: its sweep produced exactly the same five transitive rescues as this guide's full header sweep, and its textbook file fails plainly just as this guide's does. - 'std::sort' Is Not a Member of 'std' Fix - the same missing-include shape for the sorting function template in
<algorithm>, an older sibling in this family whose own guide covers its error and its fix. - 'std::find' Is Not a Member of 'std' Fix - the same missing-include shape for the linear-search function template in
<algorithm>, an older sibling in this family.
Sources
- cppreference,
std::rotate— forstd::rotatebeing a function template defined in<algorithm>that performs a left rotation on[first, last), placing the elements in[first, middle)after the elements in[middle, last)with the order inside each part preserved, returning an iterator to the element originally pointed to byfirst(orlastifmiddleequalsfirst), with the plain overloadconstexprsince C++20, an execution-policy overload since C++17, at moststd::distance(first, last)swaps, and the iterators required to be forward iterators. - cppreference, Standard library header
<algorithm>— for<algorithm>being the header that declaresstd::rotateand the neighboring algorithm names, including thestd::ranges::rotatealgorithm function object since C++20. - cppreference,
std::ranges::rotate— forstd::ranges::rotatebeing an algorithm function object defined in<algorithm>since C++20, in an iterator-triple form and a range-plus-middle form, that performs the same left rotation and returns the subrange referring to the part rotated to the right - an empty range ifmiddleequalsfirst, and the entire range ifmiddleequalslast. - cppreference,
std::rotate_copy— forstd::rotate_copybeing a function template defined in<algorithm>that copies the rotated order of[first, last)into a separate output range beginning at the result iterator, leaving the source range unchanged. - cppreference,
std::reverse— forstd::reversebeing a function template defined in<algorithm>that reverses the order of the elements in a range. - cppreference,
std::partition— forstd::partitionbeing a function template defined in<algorithm>that reorders the elements in[first, last)so all elements for which the unary predicate returnstruecome before all elements for which it returnsfalse, returning the iterator to the partition point. - cppreference,
std::sort— forstd::sortbeing a function template defined in<algorithm>that sorts the elements in a range into ascending order.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.