GCC 16.2: std::print, ranges::to, and from_range — What Actually Compiles, and the Macro That Does Not Exist
On GCC 16.2.0, std::print, ranges::to, and the from_range constructor all compile and run, and std::hazard_pointer fails at the include because the header is not shipped. The macro that tests from_range is __cpp_lib_containers_ranges, not __cpp_lib_ranges_from_range, which is not a standard macro name at all.
Written November 9, 2026 · Tested with GCC 16.2.0 · 5 min read
- The compile matrix
- std::print works
- ranges::to works, and this guide does not re-teach it
- fromrange works, and the macro test was wrong
What this guide is
Four library features, one compiler, one question each: does it compile, and does it run? The compiler is GCC 16.2.0, run in the gcc:16 container image with the flag -std=c++2c. Three of the four compile and run: std::print, std::ranges::to, and the from_range constructor. The fourth, std::hazard_pointer, fails at the include line, because the header does not exist in this libstdc++.
The sharpest finding is not in the four rows. It is in the test itself. The probe first tested a macro named __cpp_lib_ranges_from_range, and the result read UNDEFINED while the from_range constructor compiled and ran. The first reading of that result was that the library had forgotten the macro. That reading was wrong. The name __cpp_lib_ranges_from_range appears nowhere in the standard feature-test macro table, so it is undefined on every compiler, and testing it proves nothing about any library. The macro that covers from_range constructors is __cpp_lib_containers_ranges, and GCC 16.2 defines it as 202202. This guide gives the corrected test, with the wrong name called out so nobody else burns an afternoon on it.
The setup
The compiler is g++ 16.2.0 inside the Docker image gcc:16, run under WSL2. Every probe is a small program compiled with -Wall -Wextra and the flag -std=c++2c, in a container started with --rm, so nothing lingers after the run.
The compile matrix
The macro value is what the program printed after including the header <version>.
- std::ranges::to — macro __cpp_lib_ranges_to_container = 202202; compile rc=0; run rc=0, output
ranges::to size=3 v[2]=6. - std::print — macro __cpp_lib_print = 202406; compile rc=0; run rc=0, output
hi 42. - from_range constructor — macro __cpp_lib_containers_ranges = 202202; compile rc=0; run rc=0, output
from_range size=3 v[2]=3. - std::hazard_pointer — macro __cpp_lib_hazard_pointer undefined; compile rc=1; no binary, no run.
GCC 16.2 reports exactly the standard value for the three features it ships: 202202 for ranges_to_container and containers_ranges, 202406 for print. For hazard_pointer it defines nothing, which matches the missing header: the feature-test macro for a C++26 feature is 202606L in the standard table, and this libstdc++ does not ship the feature yet.
std::print works
The probe includes <print>, prints the macro, and calls std::print:
#include <print>
#include <iostream>
int main() {
#ifdef __cpp_lib_print
std::cout << "__cpp_lib_print=" << __cpp_lib_print << "\n";
#else
std::cout << "__cpp_lib_print=UNDEFINED\n";
#endif
std::print("hi {}\n", 42);
return 0;
}
It compiles with zero warnings and runs with exit code 0, printing __cpp_lib_print=202406 and then hi 42. No extra link flag is needed: <print> links with the standard library alone. Per cppreference, <print> is a C++23 header, and std::print writes formatted output to stdout.
The same program fails on the box's older compilers at the include line. On GCC 13.3.0 the error is fatal error: print: No such file or directory, and on Clang 18.1.3 it is fatal error: 'print' file not found. So <print> is absent on GCC 13.3.0 and Clang 18.1.3 and present on GCC 16.2.0. GCC 14 and GCC 15 were not tested here, so this guide claims no floor for std::print below GCC 16.
ranges::to works, and this guide does not re-teach it
The probe pipes a transformed view into ranges::to:
#include <ranges>
#include <vector>
#include <iostream>
int main() {
#ifdef __cpp_lib_ranges_to_container
std::cout << "__cpp_lib_ranges_to_container=" << __cpp_lib_ranges_to_container << "\n";
#else
std::cout << "__cpp_lib_ranges_to_container=UNDEFINED\n";
#endif
auto v = std::vector<int>{1,2,3} | std::views::transform([](int x){ return x*2; })
| std::ranges::to<std::vector<int>>();
std::cout << "ranges::to size=" << v.size() << " v[2]=" << v[2] << "\n";
return 0;
}
It compiles with zero warnings and runs with exit code 0, printing __cpp_lib_ranges_to_container=202202 and ranges::to size=3 v[2]=6. That row is the whole of this guide's ranges::to coverage, on purpose: the four-compiler matrix already lives in the sibling guide Build a C++ Ranges Pipeline: C++20 Views, Then C++23, With the Compiler Matrix, which shows ranges::to needs GCC 14 or newer of the compilers tested and the from_range constructor needs GCC 16. Repeating that matrix here would teach the same lesson twice. This guide adds the GCC 16.2 row with the exact macro values, and the next section adds the correction the sibling guide does not carry.
from_range works, and the macro test was wrong
The from_range probe builds a vector from an iota view with the tagged constructor:
#include <ranges>
#include <vector>
#include <iostream>
int main() {
#ifdef __cpp_lib_ranges_from_range
std::cout << "__cpp_lib_ranges_from_range=" << __cpp_lib_ranges_from_range << "\n";
#else
std::cout << "__cpp_lib_ranges_from_range=UNDEFINED\n";
#endif
auto v = std::vector<int>(std::from_range, std::views::iota(1, 4));
std::cout << "from_range size=" << v.size() << " v[2]=" << v[2] << "\n";
return 0;
}
It compiles with zero warnings and runs with exit code 0, printing __cpp_lib_ranges_from_range=UNDEFINED and from_range size=3 v[2]=3. The constructor works and the macro reads undefined, in the same program. The first reading was that the library ships the feature but forgot its macro. That reading was wrong, and the error was in the probe, not the library: __cpp_lib_ranges_from_range is not a standard macro name. It appears nowhere in the cppreference feature-test macro table, which lists __cpp_lib_containers_ranges at 202202L as the macro for the range constructors, and lists no macro with from_range in its name at all. An undefined result for a name the standard never defined proves nothing about the compiler.
The corrected probe tests the real names, and GCC 16.2 answers every one of them as the standard table says it should:
#include <version>
#include <iostream>
int main() {
#ifdef __cpp_lib_containers_ranges
std::cout << "__cpp_lib_containers_ranges=" << __cpp_lib_containers_ranges << "\n";
#else
std::cout << "__cpp_lib_containers_ranges=UNDEFINED\n";
#endif
#ifdef __cpp_lib_ranges_to_container
std::cout << "__cpp_lib_ranges_to_container=" << __cpp_lib_ranges_to_container << "\n";
#else
std::cout << "__cpp_lib_ranges_to_container=UNDEFINED\n";
#endif
#ifdef __cpp_lib_print
std::cout << "__cpp_lib_print=" << __cpp_lib_print << "\n";
#else
std::cout << "__cpp_lib_print=UNDEFINED\n";
#endif
#ifdef __cpp_lib_hazard_pointer
std::cout << "__cpp_lib_hazard_pointer=" << __cpp_lib_hazard_pointer << "\n";
#else
std::cout << "__cpp_lib_hazard_pointer=UNDEFINED\n";
#endif
#ifdef __cpp_lib_ranges_from_range
std::cout << "__cpp_lib_ranges_from_range=" << __cpp_lib_ranges_from_range << "\n";
#else
std::cout << "__cpp_lib_ranges_from_range=UNDEFINED (not a standard macro)\n";
#endif
return 0;
}
The output on GCC 16.2.0 is __cpp_lib_containers_ranges=202202, __cpp_lib_ranges_to_container=202202, __cpp_lib_print=202406, __cpp_lib_hazard_pointer=UNDEFINED, and __cpp_lib_ranges_from_range=UNDEFINED (not a standard macro). The from_range constructor is covered by the first line, not the last: gate from_range code on __cpp_lib_containers_ranges. Two traps sit next to each other here, and the sibling ranges guide documents the other one: include <version> before testing any macro, because without it a macro can read absent while the feature is present. A macro can read undefined because the header was not included, or because the name was never real. Check the name against the standard table first, then the header, then the compiler.
hazard_pointer: the header is not there
The probe is a minimal C++26 use of the feature:
#include <hazard_pointer>
#include <atomic>
#include <iostream>
int main() {
#ifdef __cpp_lib_hazard_pointer
std::cout << "__cpp_lib_hazard_pointer=" << __cpp_lib_hazard_pointer << "\n";
#else
std::cout << "__cpp_lib_hazard_pointer=UNDEFINED\n";
#endif
int x = 42;
std::atomic<int*> ap{&x};
std::hazard_pointer hp = std::make_hazard_pointer();
int* p = hp.protect(ap);
std::cout << "protected value=" << *p << "\n";
hp.reset();
return 0;
}
It fails to compile with exit code 1, and no binary is produced, so there is no run at all. The error is the whole result:
/probe/hazard_pointer_probe.cpp:3:10: fatal error: hazard_pointer: No such file or directory
Per the cppreference table, __cpp_lib_hazard_pointer is 202606L, a C++26 feature, and libstdc++ in GCC 16.2.0 does not ship the header. That is a statement about this library version, not about the feature: the header and the macro may both appear in a later GCC, and this guide claims nothing about any other compiler. No lock-free-stack probe could run, because there is nothing to link against. This guide reports the absence only. Whether the hazard-pointer territory is dead is a question this guide does not take up.
What this guide does not claim
The scope is one compiler version: GCC 16.2.0 in the gcc:16 image, with the flag -std=c++2c. No MSVC result, no libc++ result, and no GCC 14 or GCC 15 result for std::print is claimed here. The std::print test uses one format string and one argument; formatting edge cases such as width, precision, and chrono types are untested. The from_range test is one constructor form, a vector built from an iota view; other containers and other range types are untested. The hazard_pointer absence is about libstdc++ 16.2.0; a newer GCC may ship it. The ranges::to and from_range cross-compiler ladder lives in the sibling ranges guide, and this guide does not repeat its numbers.
Checklist
- Before gating from_range code on a macro, test __cpp_lib_containers_ranges, not __cpp_lib_ranges_from_range: the second name is not a standard macro and reads undefined on every compiler.
- Before reading any feature-test macro as absent, include
<version>: without it the macro may be invisible while the feature is present. - Before assuming std::print is portable, check the compiler:
<print>is absent on GCC 13.3.0 and Clang 18.1.3 and present on GCC 16.2.0. - Before writing a lock-free stack on std::hazard_pointer with GCC 16.2, check for the header: it is not there, and the compile fails at the include line.
- Before quoting a macro value, print it from the compiler: GCC 16.2 reports 202202 for ranges_to_container and containers_ranges, 202406 for print, and nothing for hazard_pointer.
Related guides on this site
- How Fast Does std::jthread Actually Stop? Measured Shutdown Latency
- What Does std::generator Cost, Measured?
- C++20 Coroutines + io_uring: A co_await File Read That Actually Runs
- std::formatter That Compiles: A Clang-Only Specialization Project
Sources
- cppreference.com, Library feature-test macros (since C++20) — read 2026-11-09: __cpp_lib_containers_ranges 202202L; __cpp_lib_ranges_to_container 202202L; __cpp_lib_print 202406L; __cpp_lib_hazard_pointer 202606L; no __cpp_lib_ranges_from_range anywhere in the table.
- cppreference.com, Standard library header
<print>(C++23) — read 2026-11-09:<print>is a C++23 header; std::print writes formatted output to stdout. - cppreference.com, std::ranges::to — construction order: range constructor, from_range-tagged constructor, iterator-pair constructor, back-insertion element by element; reserve behavior when the source is a sized range; mandatory parentheses in pipe form; __cpp_lib_ranges_to_container 202202L.
- Veldica, Build a C++ Ranges Pipeline: C++20 Views, Then C++23, With the Compiler Matrix — the sibling guide: the four-compiler macro matrix for ranges::to and from_range, and the warning to include
<version>before testing any macro. - Veldica, GCC 16 Defaults to C++20: What Breaks in Your Old Code — the sibling guide: GCC 16.2.0 on the box, default standard C++20, and the compiler versions used for the cross-checks in this guide.
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.