### Example Fastchess Tournament Setup Source: https://github.com/disservin/fastchess/blob/master/README.md This command demonstrates how to set up a Fastchess tournament with two engines, specific time controls, multiple rounds, repetition, and concurrency. An opening book is highly recommended. ```bash fastchess.exe -engine cmd=Engine1.exe name=Engine1 -engine cmd=Engine2.exe \ name=Engine2 -each tc=10+0.1 -rounds 200 -repeat -concurrency 4 ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/test/add-subdirectory-test/CMakeLists.txt Sets the minimum required CMake version and defines the project name. This is a standard starting point for most CMake projects. ```cmake cmake_minimum_required(VERSION 3.8...3.25) project(fmt-test CXX) ``` -------------------------------- ### Install {fmt} with vcpkg Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Download, bootstrap, and install {fmt} using the vcpkg package manager. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install fmt ``` -------------------------------- ### Install Fastchess with Custom Prefix Source: https://github.com/disservin/fastchess/blob/master/README.md Use 'make install PREFIX=/custom/path' to install the Fastchess binary and man page to a custom location. If PREFIX is not specified, it defaults to /usr/local. ```bash make install PREFIX=/custom/path ``` -------------------------------- ### Install {fmt} on Debian/Ubuntu Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Install the {fmt} development package on Debian-based Linux systems using apt. ```bash apt install libfmt-dev ``` -------------------------------- ### Format String Examples Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/syntax.md Illustrates basic format string usage with explicit and implicit argument referencing. ```c++ "First, thou shalt count to {0}" // References the first argument ``` ```c++ "Bring me a {}" // Implicitly references the first argument ``` ```c++ "From {} to {}" // Same as "From {0} to {1}" ``` -------------------------------- ### Install fmt Subproject with Meson Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Install the fmt subproject from WrapDB. This command should be run from the root of your project. ```bash meson wrap install fmt ``` -------------------------------- ### Install {fmt} on macOS with Homebrew Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Install the {fmt} library on macOS using the Homebrew package manager. ```bash brew install fmt ``` -------------------------------- ### Install Targets Configuration Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/CMakeLists.txt Configures installation directories and generates package configuration files for the fmt library. This snippet sets up paths for CMake modules, libraries, and pkgconfig files, and writes version and configuration files. ```cmake if (FMT_INSTALL) include(CMakePackageConfigHelpers) set_verbose(FMT_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/fmt CACHE STRING "Installation directory for cmake files, a relative path that " "will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute " "path.") set(version_config ${PROJECT_BINARY_DIR}/fmt-config-version.cmake) set(project_config ${PROJECT_BINARY_DIR}/fmt-config.cmake) set(pkgconfig ${PROJECT_BINARY_DIR}/fmt.pc) set(targets_export_name fmt-targets) set_verbose(FMT_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE STRING "Installation directory for libraries, a relative path that " "will be joined to ${CMAKE_INSTALL_PREFIX} or an absolute path.") set_verbose(FMT_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE STRING "Installation directory for pkgconfig (.pc) files, a relative " "path that will be joined with ${CMAKE_INSTALL_PREFIX} or an " "absolute path.") # Generate the version, config and target files into the build directory. write_basic_package_version_file( ${version_config} VERSION ${FMT_VERSION} COMPATIBILITY AnyNewerVersion) join_paths(libdir_for_pc_file "\${exec_prefix}" "${FMT_LIB_DIR}") join_paths(includedir_for_pc_file "\${prefix}" "${FMT_INC_DIR}") configure_file( "${PROJECT_SOURCE_DIR}/support/cmake/fmt.pc.in" "${pkgconfig}" @ONLY) configure_package_config_file( ${PROJECT_SOURCE_DIR}/support/cmake/fmt-config.cmake.in ${project_config} INSTALL_DESTINATION ${FMT_CMAKE_DIR}) set(INSTALL_TARGETS fmt fmt-header-only) set(INSTALL_FILE_SET) if (FMT_USE_CMAKE_MODULES) set(INSTALL_FILE_SET FILE_SET fmt DESTINATION "${FMT_INC_DIR}/fmt") endif () # Install the library and headers. install(TARGETS ${INSTALL_TARGETS} COMPONENT fmt-core EXPORT ${targets_export_name} LIBRARY DESTINATION ${FMT_LIB_DIR} ARCHIVE DESTINATION ${FMT_LIB_DIR} PUBLIC_HEADER DESTINATION "${FMT_INC_DIR}/fmt" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ${INSTALL_FILE_SET}) # Use a namespace because CMake provides better diagnostics for namespaced # imported targets. export(TARGETS ${INSTALL_TARGETS} NAMESPACE fmt:: FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake) # Install version, config and target files. install(FILES ${project_config} ${version_config} DESTINATION ${FMT_CMAKE_DIR} COMPONENT fmt-core) install(EXPORT ${targets_export_name} DESTINATION ${FMT_CMAKE_DIR} NAMESPACE fmt:: COMPONENT fmt-core) install(FILES "${pkgconfig}" DESTINATION "${FMT_PKGCONFIG_DIR}" COMPONENT fmt-core) endif () ``` -------------------------------- ### Install {fmt} with Conda Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Install {fmt} on Linux, macOS, and Windows using Conda from the conda-forge channel. ```bash conda install -c conda-forge fmt ``` -------------------------------- ### Printf Formatting Example Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Shows the conciseness of printf for formatting floating-point numbers with precision. ```c printf("%.2f\n", 1.23456); ``` -------------------------------- ### Project and Include Directories Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/CMakeLists.txt Initializes the CMake project for C++ and includes standard installation directories. It also sets the installation directory for include files. ```cmake project(FMT CXX) include(GNUInstallDirs) set_verbose(FMT_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING "Installation directory for include files, a relative path that " "will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute path.") ``` -------------------------------- ### Visual Studio Build Environment Setup Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/CMakeLists.txt Generates a run-msbuild.bat script for Visual Studio builds, incorporating SDK environment setup and MSBuild path overrides to avoid specific warnings. ```cmake if (FMT_MASTER_PROJECT AND CMAKE_GENERATOR MATCHES "Visual Studio") # If Microsoft SDK is installed create script run-msbuild.bat that # calls SetEnv.cmd to set up build environment and runs msbuild. # It is useful when building Visual Studio projects with the SDK # toolchain rather than Visual Studio. include(FindSetEnv) if (WINSDK_SETENV) set(MSBUILD_SETUP "call \"${WINSDK_SETENV}\"") endif () # Set FrameworkPathOverride to get rid of MSB3644 warnings. join(netfxpath "C:\\Program Files\\Reference Assemblies\\Microsoft\\Framework سيد" ".NETFramework\\v4.0") file(WRITE run-msbuild.bat " ${MSBUILD_SETUP} ${CMAKE_MAKE_PROGRAM} -p:FrameworkPathOverride=\"${netfxpath}\" %*") endif () ``` -------------------------------- ### Core API: fmt::format_to_n Example Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates the usage of fmt::format_to_n to format data into a buffer. Ensure the buffer is large enough to hold the formatted output. ```cpp #include int main() { char buffer[10]; auto result = fmt::format_to_n(buffer, sizeof(buffer), "{}", 42); } ``` -------------------------------- ### Iostreams Formatting Example Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Illustrates the verbosity of iostreams for formatting floating-point numbers with precision. ```c++ std::cout << std::setprecision(2) << std::fixed << 1.23456 << "\n"; ``` -------------------------------- ### Install cppformat on Debian/Ubuntu Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Installs the cppformat development package on Debian or Ubuntu systems. ```bash $ sudo apt-get install libcppformat1-dev ``` -------------------------------- ### Print to stdout using fmt::print Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Basic example of printing a simple string to the standard output using the fmt::print function. Requires including the header. ```c++ #include int main() { fmt::print("Hello, world!\n"); } ``` -------------------------------- ### Install cppformat on macOS with Homebrew Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Installs the cppformat library on macOS using the Homebrew package manager. ```bash $ brew install cppformat ``` -------------------------------- ### Print dates and times using fmt::chrono Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Example of formatting and printing current date and time using fmt::chrono. Requires including and . ```c++ #include int main() { auto now = std::chrono::system_clock::now(); fmt::print("Date and time: {} ", now); fmt::print("Time: {:%H:%M} ", now); } ``` -------------------------------- ### Assembly Output for Named Arguments Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Shows the generated assembly code for the named arguments example, illustrating the efficiency and compactness of the compiled output. ```asm .LC0: .string "answer" .LC1: .string "The answer is {answer}\n" main: sub rsp, 56 mov edi, OFFSET FLAT:.LC1 mov esi, 23 movabs rdx, 4611686018427387905 lea rax, [rsp+32] lea rcx, [rsp+16] mov QWORD PTR [rsp+8], 1 mov QWORD PTR [rsp], rax mov DWORD PTR [rsp+16], 42 mov QWORD PTR [rsp+32], OFFSET FLAT:.LC0 mov DWORD PTR [rsp+40], 0 call fmt::v6::vprint(fmt::v6::basic_string_view, fmt::v6::format_args) xor eax, eax add rsp, 56 ret .L.str.1: .asciz "answer" ``` -------------------------------- ### Experimental fmt::writer API Example Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Demonstrates the usage of the experimental `fmt::writer` API for writing to different destinations like files, `fmt::ostream`, and `std::string`. ```c++ #include void write_text(fmt::writer w) { w.print("The answer is {}.", 42); } int main() { // Write to FILE. write_text(stdout); // Write to fmt::ostream. auto f = fmt::output_file("myfile"); write_text(f); // Write to std::string. auto sb = fmt::string_buffer(); write_text(sb); std::string s = sb.str(); } ``` -------------------------------- ### Configure fmt Include Directories Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/CMakeLists.txt Sets the include directories for the fmt library, specifying build and install interfaces. The system headers attribute ensures proper precedence. ```cmake target_include_directories(fmt ${FMT_SYSTEM_HEADERS_ATTRIBUTE} BEFORE PUBLIC $ $) ``` -------------------------------- ### Example of Compile Time Improvement with Extern Templates Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Illustrates the command-line compilation process before and after applying extern templates to demonstrate reduced compile times. ```shell % time c++ -c test.cc -I include -std=c++17 -O2 c++ -c test.cc -I include -std=c++17 -O2 2.22s user 0.08s system 99% cpu 2.311 total ``` ```shell % time c++ -c test.cc -I include -std=c++17 -O2 c++ -c test.cc -I include -std=c++17 -O2 0.26s user 0.04s system 98% cpu 0.303 total ``` ```shell % time c++ -c test.cc -I include -std=c++17 c++ -c test.cc -I include -std=c++17 0.53s user 0.06s system 98% cpu 0.601 total ``` ```shell % time c++ -c test.cc -I include -std=c++17 c++ -c test.cc -I include -std=c++17 0.24s user 0.06s system 98% cpu 0.301 total ``` -------------------------------- ### Format Subseconds with Chrono Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Illustrates formatting of subseconds for chrono durations. This example uses microseconds and prints the fractional seconds. Requires ``. ```cpp #include int main() { // prints 01.234567 fmt::print("{:%S} ", std::chrono::microseconds(1234567)); } ``` -------------------------------- ### Write to a file using fmt::output_file Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Example of writing to a file efficiently using fmt::output_file. This method is optimized for single-threaded file writes and can be faster than fprintf. ```c++ #include int main() { auto out = fmt::output_file("guide.txt"); out.print("Don't {}", "Panic"); } ``` -------------------------------- ### Named Arguments with fmt::print Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Example demonstrating the use of named arguments with fmt::print for clearer and more maintainable output formatting. This version avoids dynamic memory allocations. ```c++ #include int main() { fmt::print("The answer is {answer}\n", fmt::arg("answer", 42)); } ``` -------------------------------- ### Improved Width Computation Example Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Demonstrates improved width computation for strings, including non-ASCII characters, using left alignment. ```c++ #include int main() { fmt::print("{:-<10}{}\n", "你好", "世界"); fmt::print("{:-<10}{}\n", "hello", "world"); } ``` -------------------------------- ### Compile-Time Floating Point Formatting Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Demonstrates compile-time floating-point formatting using fmt::format_to with FMT_COMPILE. This example works with default settings and does not require header-only mode. ```c++ #include #include consteval auto compile_time_dtoa(double value) -> std::array { auto result = std::array(); fmt::format_to(result.data(), FMT_COMPILE("{}"), value); return result; } constexpr auto answer = compile_time_dtoa(0.42); ``` -------------------------------- ### Wide String Support for Colored Output Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates using wide strings with colored output functions from fmt/color. This example prints a wide string with red foreground color. ```c++ #include int main() { print(fg(fmt::color::red), L"{} ", 42); } ``` -------------------------------- ### Formatting an Enum with format_as Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/api.md This example shows how to make an enum class formattable by defining a `format_as` function that returns the underlying integer value. This function should be in the same namespace as the enum. ```cpp #include namespace kevin_namespacy { enum class film { house_of_cards, american_beauty, se7en = 7 }; auto format_as(film f) { return fmt::underlying(f); } } // namespace kevin_namespacy int main() { fmt::print("{} ", kevin_namespacy::film::se7en); // Output: 7 } ``` -------------------------------- ### Compile-Time Checks for Dynamic Width and Precision Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Example demonstrating compile-time error checking for missing arguments in format strings. This helps catch errors early in the development cycle. ```c++ #include int main() { fmt::print(FMT_STRING("{0:{1}}"), 42); } ``` -------------------------------- ### Compile-Time Checks and Type Erasure Example Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/api.md Demonstrates how to create a custom logging function with compile-time checks and a small binary footprint using fmt::string_view and fmt::format_string. ```APIDOC ## Compile-Time Checks and Type Erasure ### Description This example shows how to implement a custom logging function (`log`) that leverages compile-time format string checks and type erasure to minimize binary code size and improve compile times. It uses `fmt::string_view` for the format string and `fmt::format_string` to enable compile-time validation. ### Method `log(const char* file, int line, fmt::format_string fmt, T&&... args)` ### Endpoint N/A (This is an SDK example, not an HTTP endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c++ #include void vlog(const char* file, int line, fmt::string_view fmt, fmt::format_args args) { fmt::print("{}: {}: {}", file, line, fmt::vformat(fmt, args)); } template void log(const char* file, int line, fmt::format_string fmt, T&&... args) { vlog(file, line, fmt, fmt::make_format_args(args...)); } #define MY_LOG(fmt, ...) log(__FILE__, __LINE__, fmt, __VA_ARGS__) MY_LOG("invalid squishiness: {}", 42); ``` ### Response #### Success Response Prints formatted log messages to standard output. #### Response Example ``` : : invalid squishiness: 42 ``` ``` -------------------------------- ### Start Engine Match with Random Openings Source: https://github.com/disservin/fastchess/blob/master/man.md Initiate a match between two engines using random openings from a specified EPD file. Configures time controls, rounds, and concurrency. ```sh $ fastchess -engine cmd=Engine1.exe name=Engine1 -engine cmd=Engine2.exe \ name=Engine2 -openings file=book.epd format=epd order=random \ -each tc=60+0.6 option.Hash=64 -rounds 200 -repeat -concurrency 4 ``` -------------------------------- ### Find Installed {fmt} with CMake Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Link against an installed version of the {fmt} library in your CMake project. ```cmake find_package(fmt) target_link_libraries( fmt::fmt) ``` -------------------------------- ### Basic Formatting with fmt::format Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/api.md Demonstrates the basic usage of fmt::format to create formatted strings. This function takes a format string and arguments to produce the output. ```cpp #include std::string s = fmt::format("The answer is {} {}", 42, "foo"); // s == "The answer is 42 foo" ``` -------------------------------- ### Configure Quick Match Source: https://github.com/disservin/fastchess/blob/master/README.md Initiate a quick match between two engines with a specified book using this command format. Replace ENGINE1, ENGINE2, and BOOK with your respective engine and book paths. ```bash -quick cmd=ENGINE1 cmd=ENGINE2 book=BOOK ``` -------------------------------- ### Format Code with clang-format Source: https://github.com/disservin/fastchess/blob/master/README.md Run 'make format' to format the codebase according to Google style using clang-format. ```bash make format ``` -------------------------------- ### Base Conversion Formatting Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/syntax.md Demonstrates converting integers to different bases (decimal, hexadecimal, octal, binary) and how to include base prefixes. ```c++ fmt::format("int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); // Result: "int: 42; hex: 2a; oct: 52; bin: 101010" ``` ```c++ fmt::format("int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}", 42); // Result: "int: 42; hex: 0x2a; oct: 052; bin: 0b101010" ``` -------------------------------- ### Build Documentation with CMake Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Compile the documentation for {fmt} after generating build scripts with CMake. ```bash make doc ``` -------------------------------- ### Clone and Build Benchmark Repository Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Clone the format-benchmark repository and generate Makefiles using CMake to prepare for running benchmarks. ```bash git clone --recursive https://github.com/fmtlib/format-benchmark.git cd format-benchmark cmake . ``` -------------------------------- ### Enable Fuzzing Subdirectory Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/CMakeLists.txt Conditionally adds the fuzzing subdirectory when FMT_FUZZ is enabled. This setup is for fuzzing the FMT library itself. ```cmake if (FMT_FUZZ) add_subdirectory(test/fuzzing) # The FMT_FUZZ macro is used to prevent resource exhaustion in fuzzing # mode and make fuzzing practically possible. It is similar to # FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION but uses a different name to # avoid interfering with fuzzing of projects that use {fmt}. # See also https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode. target_compile_definitions(fmt PUBLIC FMT_FUZZ) endif () ``` -------------------------------- ### Build Fuzzers with CMake Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/test/fuzzing/README.md Builds the fuzzers using CMake. Ensure you have clang++ installed and set the necessary environment variables. ```shell mkdir build cd build export CXX=clang++ export CXXFLAGS="-fsanitize=fuzzer-no-link -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION= -g" cmake .. -DFMT_SAFE_DURATION_CAST=On -DFMT_FUZZ=On -DFMT_FUZZ_LINKMAIN=Off -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer" cmake --build . ``` -------------------------------- ### Run Benchmark Tests Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Execute the speed or bloat tests after setting up the benchmark repository. ```bash make speed-test ``` ```bash make bloat-test ``` -------------------------------- ### Build Fastchess with GCC Source: https://github.com/disservin/fastchess/blob/master/README.md Clone the repository, navigate to the directory, and use 'make -j' to build the executable. This command is for GCC compilers. ```bash git clone https://github.com/Disservin/fastchess.git cd fastchess make -j ``` -------------------------------- ### Improved Error Reporting for Unformattable Types Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Shows an example of an unformattable type and the resulting error message which now includes the type name directly. ```c++ #include struct how_about_no {}; int main() { fmt::print("{}", how_about_no()); } ``` -------------------------------- ### Locale-Specific Formatting with Custom Stream Operator Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Example of locale-specific number formatting using a custom ostream operator and fmt::format with a specified locale. ```c++ #include #include struct S { double value; }; std::ostream& operator<<(std::ostream& os, S s) { return os << s.value; } int main() { auto s = fmt::format(std::locale("fr_FR.UTF-8"), "{}", S{0.42}); // s == "0,42" } ``` -------------------------------- ### Date and Time Formatting with fmt/time.h Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates strftime-like date and time formatting using the fmt/time.h header. Requires including the time header and using std::localtime for current time. ```c++ #include "fmt/time.h" std::time_t t = std::time(nullptr); // Prints "The date is 2016-04-29." (with the current date) fmt::print("The date is {:%Y-%m-%d}.", *std::localtime(&t)); ``` -------------------------------- ### Experimental Unicode Support Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Introduces experimental Unicode support in fmt, using the `_u` literal for Unicode strings and formatting. The example formats a clown emoji. ```c++ using namespace fmt::literals; auto s = fmt::format("{:*^5}_u", "🤡_u"); // s == "**🤡**_u" ``` -------------------------------- ### Benchmark Comparison: printf vs. fmt Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Compares the compile times of different formatting methods, showing significant improvement with fmt 11.0.0. ```text Method | Compile Time (s) --------------|------------------ printf | 1.6 IOStreams | 25.9 fmt 10.x | 19.0 fmt 11.0 | 4.8 tinyformat | 29.1 Boost Format | 55.0 ``` -------------------------------- ### Locale-Aware Formatting Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/api.md Use the 'L' format specifier for locale-aware number formatting. This example shows how to set the global locale and format a number with appropriate separators. ```c++ #include #include std::locale::global(std::locale("en_US.UTF-8")); auto s = fmt::format("{:L}", 1000000); // s == "1,000,000" ``` -------------------------------- ### Get CUDA Standard Properties Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/test/cuda-test/CMakeLists.txt Retrieves and prints the CUDA standard and CUDA standard required properties for a target. This is useful for debugging or verifying CMake settings. ```cmake get_target_property(IN_USE_CUDA_STANDARD fmt-in-cuda-test CUDA_STANDARD) message(STATUS "cuda_standard: ${IN_USE_CUDA_STANDARD}") get_target_property(IN_USE_CUDA_STANDARD_REQUIRED fmt-in-cuda-test CUDA_STANDARD_REQUIRED) message(STATUS "cuda_standard_required: ${IN_USE_CUDA_STANDARD_REQUIRED}") ``` -------------------------------- ### Optimized Small Format String Handling Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates an optimized scenario for formatting strings with multiple arguments, showing a significant performance improvement. ```c++ fmt::format("Result: {}: ({},{},{},{})", str1, str2, str3, str4, str5) ``` -------------------------------- ### Formatting to a File Stream Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/api.md Shows how to use fmt::print to write formatted output directly to a FILE* stream. Ensure the stream is valid and accessible. ```cpp #include fmt::print(stdout, "Hello, {}!\n", "world"); ``` -------------------------------- ### Find fmt Library in CMake Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/test/find-package-test/CMakeLists.txt This snippet shows the basic CMake configuration to find the fmt library and link it to an executable. It assumes fmt is installed and discoverable by CMake. ```cmake cmake_minimum_required(VERSION 3.8...3.25) project(fmt-test) find_package(FMT REQUIRED) add_executable(library-test main.cc) target_link_libraries(library-test fmt::fmt) target_compile_options(library-test PRIVATE ${PEDANTIC_COMPILE_FLAGS}) target_include_directories(library-test PUBLIC SYSTEM .) ``` -------------------------------- ### Print with colors and text styles Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Shows how to print text with foreground/background colors and emphasis (bold, underline, italic) using fmt::color. Requires including . ```c++ #include int main() { fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold, "Hello, {}!\n", "world"); fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) | fmt::emphasis::underline, "Olá, {}!\n", "Mundo"); fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic, "你好{}!\n", "世界"); } ``` -------------------------------- ### Format Elements in a Range with fmt::join Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Use `fmt::join()` from `fmt/format.h` to format elements of a range, separated by a specified string. This example prints a vector of doubles. ```c++ #include "fmt/format.h" std::vector v = {1.2, 3.4, 5.6}; // Prints "(+01.20, +03.40, +05.60)". fmt::print("({:+06.2f})", fmt::join(v.begin(), v.end(), ", ")); ``` -------------------------------- ### Using fmt::string_view for Pre-C++17 Systems Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Shows how to use fmt::string_view, a subset of std::string_view, for pre-C++17 compatibility. Requires including and . ```c++ #include #include fmt::print("{}", std::experimental::string_view("foo")); ``` -------------------------------- ### Locale-Aware Number Formatting Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Shows how to use locale for number formatting with fmt, including custom thousands separators. The example formats a number using a custom locale. ```c++ #include struct numpunct : std::numpunct { protected: char do_thousands_sep() const override { return '~'; } }; std::locale loc; auto s = fmt::format(std::locale(loc, new numpunct()), "{:n}", 1234567); // s == "1~234~567" ``` -------------------------------- ### Chrono Formatting with fmt Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates how to format time durations and points using the fmt/chrono header. Supports default and strftime-like formatting. ```c++ #include int main() { using namespace std::literals::chrono_literals; fmt::print("Default format: {} {} ", 42s, 100ms); fmt::print("strftime-like format: {:%H:%M:%S} ", 3h + 15min + 30s); } ``` -------------------------------- ### Colored and Emphasized Output with fmt Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Shows how to apply foreground and background colors, as well as text emphasis (bold, italic, underline) to output using fmt/color. Supports RGB colors on compatible terminals. ```c++ #include int main() { fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold, "Hello, {}!\n", "world"); fmt::print(fg(fmt::color::floral_white) | bg(fmt::color::slate_gray) | fmt::emphasis::underline, "Olá, {}!\n", "Mundo"); fmt::print(fg(fmt::color::steel_blue) | fmt::emphasis::italic, "你好{}!\n", "世界"); } ``` -------------------------------- ### Compile-time Format String Check Example Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Demonstrates how compile-time format string checks catch invalid specifiers for string types. This requires C++20 consteval support. ```c++ #include int main() { fmt::print("{:d}", "I am not a number"); } ``` ```c++ fmt::print(fmt::runtime("{:d}"), "I am not a number"); ``` -------------------------------- ### Formatted String Output with Text Style and Color in C++ Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates how to format strings with text styles, including bold and color, using fmtlib's text_style and color API. This enhances output readability. ```C++ #include std::string message = fmt::format(fmt::emphasis::bold | fg(fmt::color::red), "The answer is {}.", 42); ``` -------------------------------- ### Format Tuple Elements Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates the usage of fmt::join with tuples to format their elements. ```c++ #include #include int main() { std::tuple t{'a', 1, 2.0f}; fmt::print("{}", t); } ``` -------------------------------- ### Run Fastchess Tests Source: https://github.com/disservin/fastchess/blob/master/README.md Execute 'make -j tests' to compile the test suite, then run './fastchess-tests' to verify your changes pass all tests. ```bash make -j tests ./fastchess-tests ``` -------------------------------- ### Applying Text Styles with fmt::styled Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Illustrates how to apply text styles, such as bold emphasis and foreground color, to individual arguments using fmt::styled. This requires including fmt/color.h and fmt/chrono.h for time formatting. ```c++ #include #include int main() { auto now = std::chrono::system_clock::now(); fmt::print( "[{}] {}: {}\n", fmt::styled(now, fmt::emphasis::bold), fmt::styled("error", fg(fmt::color::red)), "something went wrong"); } ``` -------------------------------- ### Format with UTF-8 digit separators using locale Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Demonstrates using a custom locale with a fmt::format_facet to apply UTF-8 digit separators. The example uses U+2019 as a separator. ```c++ auto loc = std::locale( std::locale(), new fmt::format_facet("’")); auto s = fmt::format(loc, "{:L}", 1000); ``` -------------------------------- ### Custom formatter for struct point with nested_formatter Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Example of creating a custom formatter for a struct using fmt::nested_formatter to handle subobjects. Demonstrates automatic width, fill, and alignment. ```c++ #include struct point { double x, y; }; template <> struct fmt::formatter : nested_formatter { auto format(point p, format_context& ctx) const { return write_padded(ctx, [=](auto out) { return format_to(out, "({}, {})", nested(p.x), nested(p.y)); }); } }; int main() { fmt::print("[{:>20.2f}]", point{1, 2}); } ``` -------------------------------- ### Configure Meson for Static Build of fmt Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Use this subproject definition in meson.build to build fmt as a static library. ```meson fmt = subproject('fmt', default_options: 'default_library=static') fmt_dep = fmt.get_variable('fmt_dep') ``` -------------------------------- ### Build Static PIC Library with CMake Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Configure CMake to build {fmt} as a static library with position-independent code (PIC) for use in shared libraries. ```bash cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE .. ``` -------------------------------- ### Generate Build Scripts with CMake Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Create build scripts for the {fmt} library by running CMake in a build directory. ```bash mkdir build cd build cmake .. ``` -------------------------------- ### Build Fastchess with Clang Source: https://github.com/disservin/fastchess/blob/master/README.md Clone the repository, navigate to the directory, and use 'make -j CXX=clang++' to build the executable. This command is for Clang compilers and requires GCC >= 7.3.0 or Clang >= 8.0.0. ```bash git clone https://github.com/Disservin/fastchess.git cd fastchess make -j CXX=clang++ ``` -------------------------------- ### Enabling Header-Only Configuration Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Shows how to configure the fmt library for header-only usage by defining FMT_HEADER_ONLY before including the format.h header. This is useful for simplifying build configurations. ```c++ #define FMT_HEADER_ONLY #include "format.h" ``` -------------------------------- ### Wide String Support for Compile-Time Checks Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Illustrates the use of wide strings with compile-time format string checks in fmt. This example shows a compile-time error for an invalid type specifier. ```c++ print(fmt(L"{:.f}"), 42); // compile-time error: invalid type specifier ``` -------------------------------- ### Enable GZIP Log Compression Source: https://github.com/disservin/fastchess/blob/master/README.md To enable GZIP compression for logs, first compile Fastchess with ZLIB=true. Then, use the compress=true option for the log. ```bash make ZLIB=true ``` ```bash compress=true ``` -------------------------------- ### Custom Logging Function with Compile-Time Checks Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/api.md Create a custom formatting function with compile-time checks and a small binary footprint. This example demonstrates a type-erased logging function that avoids template bloat. ```c++ #include void vlog(const char* file, int line, fmt::string_view fmt, fmt::format_args args) { fmt::print("{}: {}: {}", file, line, fmt::vformat(fmt, args)); } template void log(const char* file, int line, fmt::format_string fmt, T&&... args) { vlog(file, line, fmt, fmt::make_format_args(args...)); } #define MY_LOG(fmt, ...) log(__FILE__, __LINE__, fmt, __VA_ARGS__) MY_LOG("invalid squishiness: {}", 42); ``` -------------------------------- ### Dynamic Width Formatting Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/syntax.md Demonstrates using a placeholder for the width specification, allowing the width to be determined at runtime. ```c++ fmt::format("{:<{}}", "left aligned", 30); // Result: "left aligned " ``` -------------------------------- ### Custom Formatter with Compile-time Error Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Illustrates defining a custom formatter for a type 'Answer' with compile-time error checking for invalid format specifiers. The example shows how an invalid specifier ('x') triggers a compile-time exception. ```cpp struct Answer {}; namespace fmt { template <> struct formatter { constexpr auto parse(parse_context& ctx) { auto it = ctx.begin(); spec = *it; if (spec != 'd' && spec != 's') throw format_error("invalid specifier"); return ++it; } template auto format(Answer, FormatContext& ctx) { return spec == 's' ? format_to(ctx.begin(), "{}", "fourty-two") : format_to(ctx.begin(), "{}", 42); } char spec = 0; }; } std::string s = format(fmt("{:x}"), Answer()); ``` -------------------------------- ### Start SPRT Test with Specific Engine Configurations Source: https://github.com/disservin/fastchess/blob/master/man.md Conduct a Statistical Package for the Renaissance Tournament (SPRT) test with detailed engine configurations, including threads and nodes per move. Sets up time controls, draw/resign rules, and game output format. ```sh $ fastchess \ -engine cmd=Engine1.exe name=Engine1 option.Threads=1 nodes=2000000 \ -engine cmd=Engine2.exe name=Engine2 option.Threads=2 nodes=1000000 \ -openings file=UHO_Lichess_4852_v1.epd format=epd order=random \ -each tc=300+5 -resign movecount=3 score=600 -draw movenumber=34 movecount=8 score=20 \ -sprt elo0=0 elo1=2 alpha=0.05 beta=0.05 \ -rounds 100000 -concurrency 3 -pgnout notation=san nodes=true file=./games/sprt.pgn ``` -------------------------------- ### Formatting Ranges with fmt/ranges.h Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates the experimental support for formatting ranges, containers, and tuple-like types using the fmt/ranges.h header. This allows for convenient printing of collections. ```cpp #include std::vector v = {1, 2, 3}; fmt::print("{}", v); // prints {1, 2, 3} ``` -------------------------------- ### FetchContent for CMake Integration Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Use FetchContent to automatically download and integrate {fmt} as a dependency in CMake projects (requires CMake 3.11+). ```cmake include(FetchContent) FetchContent_Declare( fmt GIT_REPOSITORY https://github.com/fmtlib/fmt GIT_TAG e69e5f977d458f2650bb346dadf2ad30c5320281) # 10.2.1 FetchContent_MakeAvailable(fmt) target_link_libraries( fmt::fmt) ``` -------------------------------- ### Override {fmt} Path with Live-at-Head Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/support/bazel/README.md This snippet is used in `MODULE.bazel` for a live-at-head approach, pointing to a local copy of {fmt}. ```bazel local_path_override( module_name = "fmt", path = "../third_party/fmt", ) ``` -------------------------------- ### Format std::bitset Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Illustrates formatting of std::bitset using the fmt library. Requires including . ```c++ #include #include int main() { fmt::print("{} ", std::bitset<6>(42)); // prints "101010" } ``` -------------------------------- ### Enabling Experimental Grisu Floating-Point Formatting in C++ Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Shows how to enable the experimental Grisu floating-point formatting algorithm by defining the FMT_USE_GRISU macro. This can significantly improve formatting speed. ```C++ #define FMT_USE_GRISU 1 #include auto s = fmt::format("{}", 4.2); // formats 4.2 using Grisu ``` -------------------------------- ### Configure Meson for Header-Only Build of fmt Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Use this subproject definition in meson.build to build fmt as a header-only library. ```meson fmt = subproject('fmt', default_options: ['header-only=true']) fmt_dep = fmt.get_variable('fmt_header_only_dep') ``` -------------------------------- ### Format User-Defined Type with format_as Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Demonstrates how to use `format_as` to format user-defined types. Ensure the `format_as` function is defined for the custom type. ```cpp #include struct floaty_mc_floatface { double value; }; auto format_as(floaty_mc_floatface f) { return f.value; } int main() { fmt::print("{:8} ", floaty_mc_floatface{0.42}); // prints " 0.42" } ``` -------------------------------- ### Fixed global initialization issue with constexpr Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Illustrates a fix for global initialization issues on compilers with constexpr support, using fmt::format for static string initialization. ```c++ // This works on compilers with constexpr support. static const std::string answer = fmt::format("{}", 42); ``` -------------------------------- ### Compile-Time Format String Compilation with Named Arguments Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Demonstrates using UDL-based named arguments for compile-time format string compilation, resolving arguments with no runtime overhead. ```c++ #include using namespace fmt::literals; auto s = fmt::format(FMT_COMPILE("{answer}"), "answer"_a = 42); ``` -------------------------------- ### Configure Source Packaging Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/CMakeLists.txt Sets up CPack to generate a source distribution archive, ignoring specified files and setting package details. This is used when FMT_MASTER_PROJECT is true. ```cmake set(gitignore ${PROJECT_SOURCE_DIR}/.gitignore) if (FMT_MASTER_PROJECT AND EXISTS ${gitignore}) # Get the list of ignored files from .gitignore. file (STRINGS ${gitignore} lines) list(REMOVE_ITEM lines /doc/html) foreach (line ${lines}) string(REPLACE ". ``` ```cmake ")"[.]" line "${line}") string(REPLACE "*" ".*" line "${line}") set(ignored_files ${ignored_files} "${line}$") set(ignored_files ${ignored_files} "${line}/") endforeach () set(ignored_files ${ignored_files} /.git /build/doxyxml .vagrant) set(CPACK_SOURCE_GENERATOR ZIP) set(CPACK_SOURCE_IGNORE_FILES ${ignored_files}) set(CPACK_SOURCE_PACKAGE_FILE_NAME fmt-${FMT_VERSION}) set(CPACK_PACKAGE_NAME fmt) set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.md) include(CPack) endif () ``` -------------------------------- ### Chrono Formatting Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/syntax.md Illustrates formatting a time structure using the fmt/chrono library, specifying a custom date and time format. ```c++ #include auto t = tm(); t.tm_year = 2010 - 1900; t.tm_mon = 7; t.tm_mday = 4; t.tm_hour = 12; t.tm_min = 15; t.tm_sec = 58; fmt::print("{:%Y-%m-%d %H:%M:%S}", t); // Prints: 2010-08-04 12:15:58 ``` -------------------------------- ### Format Function Pointers Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Shows how to use fmt::ptr to format function pointers, including the main function pointer. ```c++ #include int main() { fmt::print("My main: {}\n", fmt::ptr(main)); } ``` -------------------------------- ### UTF-8 String Formatting with Alignment Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Illustrates formatting UTF-8 strings with alignment and padding, demonstrating the library's improved handling of Unicode characters for display purposes. ```c++ fmt::print("┌{0:─^{2}}┐\n" "│{1: ^{2}}│\n" "└{0:─^{2}}┘\n", "", "Прывітанне, свет!", 21); ``` -------------------------------- ### Configuring Main Library Test Executable Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/test/add-subdirectory-test/CMakeLists.txt Defines the main test executable, sets its include directories, private compile options, and links it against the fmt library. Use this for testing the standard fmt library build. ```cmake add_executable(library-test main.cc) target_include_directories(library-test PUBLIC SYSTEM .) target_compile_options(library-test PRIVATE ${PEDANTIC_COMPILE_FLAGS}) target_link_libraries(library-test fmt::fmt) ``` -------------------------------- ### Configure fmt Subproject in Meson Build File Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/get-started.md Add the fmt subproject and retrieve its dependency object in your project's meson.build file. ```meson fmt = subproject('fmt') fmt_dep = fmt.get_variable('fmt_dep') ``` ```meson my_build_target = executable( 'name', 'src/main.cc', dependencies: [fmt_dep]) ``` -------------------------------- ### Named Arguments in fmt::print Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Demonstrates the use of named arguments for enhanced readability in format strings. Requires fmtlib/fmt pull requests 169, 173, and 174. ```c++ fmt::print("The answer is {answer}.", fmt::arg("answer", 42)); ``` -------------------------------- ### Formatting Time Points with Arbitrary Durations Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/ChangeLog.md Demonstrates formatting a time point with arbitrary durations, specifically showing seconds. ```c++ #include int main() { using tp = std::chrono::time_point< std::chrono::system_clock, std::chrono::seconds>; fmt::print("{:%S}", tp(std::chrono::seconds(42))); } ``` -------------------------------- ### Format a string with fmt::format Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/README.md Demonstrates formatting a string with an integer argument using fmt::format. The result is stored in a std::string. ```c++ std::string s = fmt::format("The answer is {}.", 42); // s == "The answer is 42." ``` -------------------------------- ### Percentage Formatting for Floating-Point Values in C++ Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/ChangeLog-old.md Shows how to format floating-point values as percentages using the '%' format specifier. This is useful for displaying ratios or probabilities. ```C++ auto s = fmt::format("{:.1%}", 0.42); // s == "42.0%" ``` -------------------------------- ### Runtime Formatting Source: https://github.com/disservin/fastchess/blob/master/app/third_party/fmt/doc/api.md Explains how to use fmt::runtime to format strings that are not known at compile time. This is necessary when the format string is determined at runtime. ```cpp #include std::string fmt_str = "Hello, {}!"; std::string arg = "world"; std::string result = fmt::format(fmt::runtime(fmt_str), arg); // result == "Hello, world!" ```