Ship the C++20 feature and its fallback in one file
The code review that started this series ended with a portability question. std::osyncstream is C++20, but not every compiler in a shipping codebase has it yet. The reviewer’s answer was to detect the feature and fall back:
#include <version>
#if defined(__cpp_lib_syncbuf)
#include <syncstream>
#else
#include <mutex>
#endif
That is the feature-test-macro system, and it is the right tool for exactly this.
On GCC 16.1 the demo prints __cpp_lib_syncbuf = 201803 and takes the syncstream path. On a compiler without <syncstream> the same source compiles the mutex branch instead. One file, the best available tool on each.
Why not just check the language version
You could gate on __cplusplus >= 202002L, but that asks the wrong question. A compiler can be in C++20 mode and still lack a particular library feature, because language and library support land at different times and in different releases. __cpp_lib_syncbuf answers the precise question: is this library facility present? Each standard library feature has its own macro, defined to a date-stamped value (201803L here, the month the paper was adopted), so you can compare against that value when you need a specific revision.
<version> is the header that makes this ergonomic. Included on its own it defines every library feature-test macro without dragging in the features themselves, so you can ask “do I have <syncstream>?” before you decide to include it. The whole system is standardized in SD-6, the committee’s feature-test-macro document.
The pattern generalizes
The same shape covers the rest of this series. Gate std::print on __cpp_lib_print, gate a coroutine path on __cpp_impl_coroutine, and so on. Write the modern path and the fallback, and let the macro choose. The result compiles everywhere and uses the good tool wherever the good tool exists.
Sources: SD-6: SG10 feature-test recommendations · cppreference: feature test macros.