C++

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

std::min lives in one header, <algorithm> - but whether a file that never includes it fails depends on what else the file includes, because many common headers pull the name in transitively. A lean file whose only include is <type_traits>, <utility>, <numeric>, or <limits> gets this error, and GCC prints no note naming the header under it. This guide pins down when the error appears, which probed headers do and do not cause it, and the one include that fixes it by specification.

Written November 30, 2026 · Tested with GCC 13.3.0 · 12 min read

By the end of this guide
  • The error: the include is missing
  • Neighboring headers: which ones rescue it, which ones do not
  • The fix
  • The neighboring names: the whole header family fails too

Written November 30, 2026

Tested with GCC 13.3.0

What this guide is

std::min is a function template defined in the header <algorithm>. It returns the smaller of the given values: the two-value overloads return the smaller of a and b, using operator< or a comparison function object the caller supplies, and the initializer-list overloads return the smallest of the values in the list.

Because the template lives in one specific header, 'min' 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 GCC does not name the header - in the lean contexts probed below there is no note saying which header defines std::min, so the fix has to come from knowing the name's home, not from reading a note.

Unlike some neighboring names, this one is rescued by many common headers: a file that includes <iostream>, <vector>, or <string> compiles the same std::min call without ever including <algorithm>. The error therefore shows up in lean files - small utilities, headers, and translation units whose includes are narrow. Each case is separated below.

The error: the include is missing

This program returns the smaller of two integers, but includes only <type_traits>:

C++
#include <type_traits>
int main() {
    return std::min(3, 4);
}
Terminal
$ g++ -std=c++20 a_type_traits.cpp -o a_prog
a_type_traits.cpp: In function 'int main()':
a_type_traits.cpp:3:17: error: 'min' is not a member of 'std'
    3 |     return std::min(3, 4);
      |                 ^~~

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

C++
int main() {
    return std::min(3, 4);
}
Terminal
$ g++ -std=c++20 n_none.cpp -o n_none_prog
n_none.cpp: In function 'int main()':
n_none.cpp:2:17: error: 'min' is not a member of 'std'
    2 |     return std::min(3, 4);
      |                 ^~~

Two other lean contexts change the wording slightly, without naming <algorithm> either. With only <numeric>, GCC suggests a different name from that header, minus:

C++
#include <numeric>
int main() {
    return std::min(3, 4);
}
Terminal
$ g++ -std=c++20 a_numeric.cpp -o a_numeric_prog
a_numeric.cpp: In function 'int main()':
a_numeric.cpp:3:17: error: 'min' is not a member of 'std'; did you mean 'minus'?
    3 |     return std::min(3, 4);
      |                 ^~~
      |                 minus

And with only <mutex>, GCC suggests the ranges version, std::ranges::min, which that header's own includes do declare:

C++
#include <mutex>
int main() {
    return std::min(3, 4);
}
Terminal
$ g++ -std=c++20 s2_mutex.cpp -o s2_mutex_prog
s2_mutex.cpp: In function 'int main()':
s2_mutex.cpp:3:17: error: 'min' is not a member of 'std'; did you mean 'std::ranges::min'?
    3 |     return std::min(3, 4);
      |                 ^~~
In file included from /usr/include/c++/13/tuple:44,
                 from /usr/include/c++/13/mutex:40,
                 from s2_mutex.cpp:1:
/usr/include/c++/13/bits/ranges_util.h:738:29: note: 'std::ranges::min' declared here
  738 |   inline constexpr __min_fn min{};
      |                             ^~~

Neither suggestion is the fix for a call written as std::min: std::minus is a different function object, and std::ranges::min is a different name in a nested namespace. The fix for the call as written is the missing include, below.

Neighboring headers: which ones rescue it, which ones do not

In a sweep where each header below was compiled as the only header in a program that returns std::min(3, 4), the outcome splits. These headers fail with the same first error, 'min' is not a member of 'std':

  • <type_traits>
  • <utility>
  • <numeric>
  • <limits>

These headers rescue the program - it compiles with no <algorithm> anywhere in the file:

  • <vector>
  • <string>
  • <iostream>
  • <functional>
  • <array>
  • <cmath>

Note <iostream> in the rescue list: the textbook version of this program, the one that prints the result with std::cout, does not fail on this library version, because <iostream> pulls std::min in transitively. That rescue is a property of this library version, not a rule of the language - no header except <algorithm> is required to declare std::min, and another library could leave it out. A program that uses std::min includes <algorithm>, whether or not it happens to compile without it.

The same holds for the other failing contexts in the sweep. This program includes only <utility>:

C++
#include <utility>
int main() {
    return std::min(3, 4);
}
Terminal
$ g++ -std=c++20 a_utility.cpp -o a_utility_prog
a_utility.cpp: In function 'int main()':
a_utility.cpp:3:17: error: 'min' is not a member of 'std'
    3 |     return std::min(3, 4);
      |                 ^~~

And this one includes only <limits> - a header that itself declares a min() member function on std::numeric_limits, which is not the free function template std::min:

C++
#include <limits>
int main() {
    return std::min(3, 4);
}
Terminal
$ g++ -std=c++20 a_limits.cpp -o a_limits_prog
a_limits.cpp: In function 'int main()':
a_limits.cpp:3:17: error: 'min' is not a member of 'std'
    3 |     return std::min(3, 4);
      |                 ^~~

The fix

Add the header:

C++
#include <algorithm>
#include <iostream>
int main() {
    std::cout << std::min(3, 4) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 h_fixed.cpp -o h_prog
$ ./h_prog
3

One include, <algorithm>, declares the template. std::min(3, 4) returns the smaller of the two values, so the program prints 3.

The neighboring names: the whole header family fails too

The other names declared by <algorithm> fail with the same shape of error in the same lean context. std::max - the function template that returns the greater of the given values - gets its own error, again with no header note:

C++
#include <type_traits>
int main() {
    return std::max(3, 4);
}
Terminal
$ g++ -std=c++20 b_max.cpp -o b_prog
b_max.cpp: In function 'int main()':
b_max.cpp:3:17: error: 'max' is not a member of 'std'
    3 |     return std::max(3, 4);
      |                 ^~~

std::clamp - the function template, since C++17, that returns a reference to the value in [lo, hi] that is closest to v - fails the same way:

C++
#include <type_traits>
int main() {
    return std::clamp(15, 0, 10);
}
Terminal
$ g++ -std=c++20 c_clamp.cpp -o c_prog
c_clamp.cpp: In function 'int main()':
c_clamp.cpp:3:17: error: 'clamp' is not a member of 'std'
    3 |     return std::clamp(15, 0, 10);
      |                 ^~~~~

std::min_element - the function template that finds the smallest element in a range and returns an iterator to it - fails the same way:

C++
#include <type_traits>
int main() {
    int values[] = {5, 2, 8};
    return *std::min_element(values, values + 3);
}
Terminal
$ g++ -std=c++20 d_min_element.cpp -o d_prog
d_min_element.cpp: In function 'int main()':
d_min_element.cpp:4:18: error: 'min_element' is not a member of 'std'
    4 |     return *std::min_element(values, values + 3);
      |                  ^~~~~~~~~~~

And std::max_element, which returns an iterator to the largest element in a range, fails the same way:

C++
#include <type_traits>
int main() {
    int values[] = {5, 2, 8};
    return *std::max_element(values, values + 3);
}
Terminal
$ g++ -std=c++20 e_max_element.cpp -o e_prog
e_max_element.cpp: In function 'int main()':
e_max_element.cpp:4:18: error: 'max_element' is not a member of 'std'
    4 |     return *std::max_element(values, values + 3);
      |                  ^~~~~~~~~~~

One added include declares every one of these names: the minimum, the maximum, the clamp, and both range searches.

The neighboring names, fixed

With <algorithm> added, the doubles overload, the custom comparator, the initializer list, the clamp, and the range searches all work in short programs. On doubles, std::min returns the smaller value, 1.75:

C++
#include <algorithm>
#include <iostream>
int main() {
    std::cout << std::min(2.5, 1.75) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 i_doubles.cpp -o i_prog
$ ./i_prog
1.75

With a custom comparator that reverses the ordering - it returns true when a is greater than b - the same std::min call returns 4, the value that is smallest under that ordering:

C++
#include <algorithm>
#include <iostream>
int main() {
    auto by_reverse = [](int a, int b) { return a > b; };
    std::cout << std::min(3, 4, by_reverse) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 j_comparator.cpp -o j_prog
$ ./j_prog
4

The initializer-list overload takes the whole list at once and returns its smallest value, 1:

C++
#include <algorithm>
#include <iostream>
int main() {
    std::cout << std::min({5, 2, 8, 1}) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 k_initlist.cpp -o k_prog
$ ./k_prog
1

std::clamp returns the boundary when the value lies outside [lo, hi] and the value itself when it lies inside: 15 clamps to 10, -3 clamps to 0, and 7 stays 7:

C++
#include <algorithm>
#include <iostream>
int main() {
    std::cout << std::clamp(15, 0, 10) << "\n";
    std::cout << std::clamp(-3, 0, 10) << "\n";
    std::cout << std::clamp(7, 0, 10) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 l_clamp_fixed.cpp -o l_prog
$ ./l_prog
10
0
7

And std::max, std::min_element, and std::max_element run in one program: the maximum of 3 and 4 is 4, the smallest element of {5, 2, 8} is 2, and the largest is 8:

C++
#include <algorithm>
#include <iostream>
int main() {
    int values[] = {5, 2, 8};
    std::cout << std::max(3, 4) << "\n";
    std::cout << *std::min_element(values, values + 3) << "\n";
    std::cout << *std::max_element(values, values + 3) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 m_max_minelem_fixed.cpp -o m_prog
$ ./m_prog
4
2
8

A different wording: the name without its qualifier

Including <algorithm> is not the only half of the name. This program includes the header but drops the std:: qualifier:

C++
#include <algorithm>
#include <iostream>
int main() {
    std::cout << min(3, 4) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++20 g_unqualified.cpp -o g_prog
g_unqualified.cpp: In function 'int main()':
g_unqualified.cpp:4:18: error: 'min' was not declared in this scope
    4 |     std::cout << min(3, 4) << "\n";
      |                  ^~~
g_unqualified.cpp:4:18: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:61,
                 from g_unqualified.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:5785:5: note:   'std::min'
 5785 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
In file included from /usr/include/c++/13/bits/ranges_algo.h:39,
                 from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_util.h:738:29: note:   'std::ranges::min'
  738 |   inline constexpr __min_fn min{};
      |                             ^~~

That wording - was not declared in this scope - is a different defect with a different fix: the header is present, the qualifier is not. Qualify the name as std::min; adding includes does not bring the name out of namespace std.

The exact rule

  • std::min is declared by #include <algorithm>, and nowhere else by rule. In the sweep probed here, <type_traits>, <utility>, <numeric>, and <limits> do not declare it, and neither does a file with no include at all.
  • 'min' is not a member of 'std' in a lean file means the <algorithm> include is missing - and, unlike some neighboring errors, GCC prints no note naming <algorithm> under it in the contexts probed here. The suggestions it does print in two contexts, minus under <numeric> and std::ranges::min under <mutex>, name other entities, not the header.
  • In the sweep probed here, <vector>, <string>, <iostream>, <functional>, <array>, and <cmath> each rescue std::min transitively: a file whose only include is one of those compiles the call without <algorithm>. That is this library version's behavior, not a guarantee - no header is required to pull std::min in.
  • std::max, std::clamp, std::min_element, and std::max_element are declared by the same #include <algorithm>: in the programs shown here, which include only <type_traits> beside the use, each gets its own is not a member of 'std' error when that include is missing, with no header note.
  • 'min' was not declared in this scope for an unqualified min use is a different defect: qualify the name as std::min - the include alone does not bring the name out of namespace std.

The fixes, ranked

  • First, check the include list of the file that names std::min. If <algorithm> is not there, add it - that is the fix in the common case, whether or not another header happens to rescue the file today.
  • Second, do not follow the suggestions GCC prints in the lean contexts as if they were the fix: std::minus and std::ranges::min are different names for different things. They appear because those names are visible in the file, not because they replace std::min.
  • Third, do not rely on <iostream>, <vector>, or any other neighboring header pulling the name in. In the sweep here those headers do rescue it - and no header is required to, so a file that uses std::min includes <algorithm> itself.
  • Fourth, if the error says was not declared in this scope instead, fix the name's qualifier to std::min as well.
  • Fifth, if the failing name is a neighboring one - max, clamp, min_element, or max_element - the same added include fixes it: every one of those names shares the header, and none of them gets a header note in the programs here either.

Which fix for which cause

  • #include <algorithm> missing, std::min used in a file whose only include is <type_traits>, <utility>, <numeric>, or <limits>, or that includes nothing: the message is 'min' is not a member of 'std', with no header note - add #include <algorithm>.
  • Only a rescuing header included - <vector>, <string>, <iostream>, <functional>, <array>, or <cmath>: no error on this library version - add #include <algorithm> anyway, because the rescue is not guaranteed.
  • std::min used with only <numeric> included: the message adds did you mean 'minus'? - ignore the suggestion and add #include <algorithm>.
  • std::min used with only <mutex> included: the message adds did you mean 'std::ranges::min'? - that is a different name; add #include <algorithm> for the call as written.
  • std::max, std::clamp, std::min_element, or std::max_element used without <algorithm> in the lean context: the message names that name, with no header note - add #include <algorithm>.
  • min used without the std:: qualifier, <algorithm> included: the message is 'min' was not declared in this scope - qualify the name as std::min.

Checklist

  • Check the include list of the file that names the minimum, 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 naming the header. For this error, in the contexts probed here, GCC prints none - take the fix from the name's home header, <algorithm>, instead of guessing from the suggestions it does print.
  • Do not rely on a neighboring header pulling std::min in. In the sweep here, six common headers do - and none of them is required to.
  • One header per name the file uses: std::pair comes from <utility> and std::accumulate from <numeric>, even in a program whose subject is the minimum - and neither of those headers declares std::min in return.
  • After the fix, confirm the program runs, not just that it compiles: the fixed programs here print 3 for the integer minimum, 1.75 for the doubles, 4 for the reversed-comparator minimum, 1 for the initializer list, 10, 0, and 7 for the three clamps, and 4, 2, and 8 for the maximum and the two range searches.

Sources

  • cppreference, std::min - for std::min being a function template defined in <algorithm> that returns the smaller of the given values, with overloads taking two values, two values and a comparison function, an initializer list, or an initializer list and a comparison function, returning the first value when the two are equivalent.
  • cppreference, Standard library header <algorithm> - for <algorithm> being the header that declares the std::min, std::max, std::clamp, std::min_element, and std::max_element function templates.
  • cppreference, std::max - for std::max being a function template defined in <algorithm> that returns the greater of the given values, with the same two-value, comparator, and initializer-list overload shapes as std::min.
  • cppreference, std::clamp - for std::clamp being a function template defined in <algorithm> (since C++17) that returns a reference to the value in [lo, hi] that is closest to v - lo if v is less than lo, hi if hi is less than v, otherwise v.
  • cppreference, std::min_element - for std::min_element being a function template defined in <algorithm> that finds the smallest element in the range [first, last) and returns an iterator to it, or last if the range is empty.

Keep Exploring