While poking around the code snippets I noticed there are workaround custom written header for the <fmt> and <ranges> standard libraries, for compilers not yet fully implementing C++20 at the time the book and source were written. Examining either of the headers shows the authors DO add to the std namespace.
// Compatibility include for compilers that do not support the <ranges> module yet
// (falls back to the reference implementation from https://github.com/ericniebler/range-v3)
// See Appendix A for the preprocessing directives and macros we use here.
#ifdef __cpp_lib_ranges
#error Remove/rename this compatibility header (use Standard Library header instead)
#else
#include "range-v3/include/range/v3/all.hpp"
// Technically you are not allowed to add to the std namespace,
// but necessity knows no law...namespace std::ranges
{
usingnamespace ::ranges::cpp20;
using ::ranges::empty;
using ::ranges::begin;
using ::ranges::end;
using ::ranges::size;
template <class Val, class CharT, class Traits>
auto istream_view(basic_istream<CharT, Traits>& s) { return basic_istream_view<Val>(s); }
}
namespace std::views
{
usingnamespace ::ranges::cpp20::views;
}
#endif
M'ok.
"Luckily" Visual Studio 2019/2022 do both appear to implement all of the C++20 standard (https://en.cppreference.com/w/cpp/compiler_support/20), though for at least a few of the features the language standard needed is -std:c++latest instead of -std:c++20. <ranges> (<concepts> actually) and module use are two C++20 features I know of requiring setting to latest.
// Compatibility include for compilers that do not support the <format> module yet
// (falls back to the reference implementation from https://fmt.dev)
// See Appendix A for the preprocessing directives and macros we use here.
#ifdef __cpp_lib_format
#error Remove Workarounds/format from your include directories (use Standard Library header instead)
#else
#define FMT_HEADER_ONLY
#include "fmt/include/fmt/format.h"
// Technically you are not allowed to add to the std namespace,
// but necessity knows no law...
namespace std
{
usingnamespace fmt;
}
#endif