ronantakizawa/codereview-bench huggingface dataset:
Repository: fmtlib/fmt
File: src/os.cc (C++)

Code before:
  // are closed.
  read_end = file(fds[0]);
  write_end = file(fds[1]);
}

buffered_file file::fdopen(const char* mode) {
// Don't retry as fdopen doesn't return EINTR.
#  if defined(__MINGW32__) && defined(_POSIX_)
  FILE* f = ::fdopen(fd_, mode);
#  else
  FILE* f = FMT_POSIX_CALL(fdopen(fd_, mode));
#  endif
  if (!f)
    FMT_THROW(system_error(
        errno, FMT_STRING("cannot associate stream with file descriptor")));
  buffered_file bf(f);
  fd_ = -1;
  return bf;
}

#  if defined(_WIN32) && !defined(__MINGW32__)
file file::open_windows_file(wcstring_view path, int oflag) {
  int fd_ = -1;
  using mode_t = int;
  constexpr mode_t mode =
      S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
  FMT_POSIX_CALL(wsopen_s(&fd_, path.c_str(), oflag, _SH_DENYNO, mode));
  if (fd_ == -1)
    FMT_THROW(system_error(errno, FMT_STRING("cannot open file {}"),
                           detail::utf16_to_utf8(path.c_str()).c_str()));
  return file(fd_);
}
#  endif

long getpagesize() {
#  ifdef _WIN32
  SYSTEM_INFO si;
  GetSystemInfo(&si);
  return si.dwPageSize;
#  else
  long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE));
  if (size < 0)
    FMT_THROW(system_error(errno, FMT_STRING("cannot get memory page size")));
  return size;
#  endif
}

FMT_BEGIN_DETAIL_NAMESPACE

void file_buffer::grow(size_t) {
  if (this->size() == this->capacity()) flush();

Review comment (suggestion):
Let's move to a constant, e.g. `default_open_mode` and reuse here and above to make sure modes are consistent.

Code after:
  // The following assignments don't throw because read_fd and write_fd
  // are closed.
  read_end = file(fds[0]);
  write_end = file(fds[1]);
}

buffered_file file::fdopen(const char* mode) {
// Don't retry as fdopen doesn't return EINTR.
#  if defined(__MINGW32__) && defined(_POSIX_)
  FILE* f = ::fdopen(fd_, mode);
#  else
  FILE* f = FMT_POSIX_CALL(fdopen(fd_, mode));
#  endif
  if (!f)
    FMT_THROW(system_error(
        errno, FMT_STRING("cannot associate stream with file descriptor")));
  buffered_file bf(f);
  fd_ = -1;
  return bf;
}

#  if defined(_WIN32) && !defined(__MINGW32__)
file file::open_windows_file(wcstring_view path, int oflag) {
  int fd_ = -1;
  auto err =
      _wsopen_s(&fd_, path.c_str(), oflag, _SH_DENYNO, default_open_mode);
  if (fd_ == -1)
    FMT_THROW(system_error(err, FMT_STRING("cannot open file {}"),
                           detail::utf16_to_utf8(path.c_str()).c_str()));
  return file(fd_);
}
#  endif

long getpagesize() {
#  ifdef _WIN32
  SYSTEM_INFO si;
  GetSystemInfo(&si);
  return si.dwPageSize;
#  else
  long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE));
  if (size < 0)
    FMT_THROW(system_error(errno, FMT_STRING("cannot get memory page size")));
  return size;
#  endif
}

FMT_BEGIN_DETAIL_NAMESPACE

void file_buffer::grow(size_t) {
  if (this->size() == this->capacity()) flush();
}
Repository: fmtlib/fmt
File: include/fmt/std.h (C/C++)

Code before:
template <typename BitRef, typename Char>
struct formatter<BitRef, Char,
                 enable_if_t<detail::is_bit_reference_like<BitRef>::value>>
    : formatter<bool, Char> {
  template <typename FormatContext>
  FMT_CONSTEXPR auto format(const BitRef& v, FormatContext& ctx) const
      -> decltype(ctx.out()) {
    return formatter<bool, Char>::format(v, ctx);
  }
};

#ifdef _LIBCPP_VERSION

// Workaround for libc++ incompatibility with C++ standard.
// According to the Standard, `bitset::operator[] const` returns bool.
FMT_EXPORT
template <typename C, typename Char>
struct formatter<std::__bit_const_reference<C>, Char> : formatter<bool, Char> {
  template <typename FormatContext>
  FMT_CONSTEXPR20 auto format(const std::__bit_const_reference<C>& v,
                              FormatContext& ctx) const -> decltype(ctx.out()) {
    return formatter<bool, Char>::format(v, ctx);
  }
};

#endif

FMT_END_NAMESPACE

#endif  // FMT_STD_H_


Review comment (refactor):
I think this can be replaced by a specialization of `is_bit_reference_like` for `__bit_const_reference` which seems a bit cleaner (no duplicate formatter).

Code after:
// According to the Standard, `bitset::operator[] const` returns bool.
template <typename C>
struct is_bit_reference_like<std::__bit_const_reference<C>> {
  static constexpr const bool value = true;
};

#endif

}  // namespace detail

// We can't use std::vector<bool, Allocator>::reference and
// std::bitset<N>::reference because the compiler can't deduce Allocator and N
// in partial specialization.
FMT_EXPORT
template <typename BitRef, typename Char>
struct formatter<BitRef, Char,
                 enable_if_t<detail::is_bit_reference_like<BitRef>::value>>
    : formatter<bool, Char> {
  template <typename FormatContext>
  FMT_CONSTEXPR auto format(const BitRef& v, FormatContext& ctx) const
      -> decltype(ctx.out()) {
    return formatter<bool, Char>::format(v, ctx);
  }
};

FMT_END_NAMESPACE

#endif  // FMT_STD_H_
Repository: fmtlib/fmt
File: include/fmt/format.h (C/C++)

Code before:
#ifndef FMT_NO_UNIQUE_ADDRESS
#  if FMT_CPLUSPLUS >= 202002L
#    if FMT_HAS_CPP_ATTRIBUTE(no_unique_address)
#      define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]]
// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485)
#    elif (FMT_MSC_VERSION >= 1929) && !FMT_CLANG_VERSION
#      define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#    endif
#  endif
#endif
#ifndef FMT_NO_UNIQUE_ADDRESS
#  define FMT_NO_UNIQUE_ADDRESS
#endif

#if FMT_GCC_VERSION || defined(__clang__)
#  define FMT_VISIBILITY(value) __attribute__((visibility(value)))
#else
#  define FMT_VISIBILITY(value)
#endif

#ifdef __has_builtin
#  define FMT_HAS_BUILTIN(x) __has_builtin(x)
#else
#  define FMT_HAS_BUILTIN(x) 0
#endif

#if FMT_GCC_VERSION || FMT_CLANG_VERSION
#  define FMT_NOINLINE __attribute__((noinline))
#else
#  define FMT_NOINLINE
#endif

#ifndef FMT_THROW
#  if FMT_EXCEPTIONS
#    if FMT_MSC_VERSION || defined(__NVCC__)
FMT_BEGIN_NAMESPACE
namespace detail {
template <typename Exception> inline void do_throw(const Exception& x) {
  // Silence unreachable code warnings in MSVC and NVCC because these
  // are nearly impossible to fix in a generic code.
  volatile bool b = true;
  if (b) throw x;
}
}  // namespace detail
FMT_END_NAMESPACE
#      define FMT_THROW(x) detail::do_throw(x)
#    else
#      define FMT_THROW(x) throw x
#    endif
#  else
#    define FMT_THROW(x) \

Review comment (suggestion):
I don't think we should introduce a new macro. Let's update `FMT_VISIBILITY` instead since we shouldn't be changing visibility in general when not compiling a shared library.

Code after:
#ifndef FMT_NO_UNIQUE_ADDRESS
#  if FMT_CPLUSPLUS >= 202002L
#    if FMT_HAS_CPP_ATTRIBUTE(no_unique_address)
#      define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]]
// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485)
#    elif (FMT_MSC_VERSION >= 1929) && !FMT_CLANG_VERSION
#      define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#    endif
#  endif
#endif
#ifndef FMT_NO_UNIQUE_ADDRESS
#  define FMT_NO_UNIQUE_ADDRESS
#endif

#if FMT_GCC_VERSION || defined(__clang__)
#  define FMT_VISIBILITY(value) __attribute__((visibility(value)))
#else
#  define FMT_VISIBILITY(value)
#endif

#if !defined(FMT_HEADER_ONLY) && !defined(_WIN32) && \
    (defined(FMT_LIB_EXPORT) || defined(FMT_SHARED))
#  define FMT_INLINE_API FMT_VISIBILITY("default")
#else
#  define FMT_INLINE_API
#endif

#ifdef __has_builtin
#  define FMT_HAS_BUILTIN(x) __has_builtin(x)
#else
#  define FMT_HAS_BUILTIN(x) 0
#endif

#if FMT_GCC_VERSION || FMT_CLANG_VERSION
#  define FMT_NOINLINE __attribute__((noinline))
#else
#  define FMT_NOINLINE
#endif

#ifndef FMT_THROW
#  if FMT_EXCEPTIONS
#    if FMT_MSC_VERSION || defined(__NVCC__)
FMT_BEGIN_NAMESPACE
namespace detail {
template <typename Exception> inline void do_throw(const Exception& x) {
  // Silence unreachable code warnings in MSVC and NVCC because these
  // are nearly impossible to fix in a generic code.
  volatile bool b = true;
  if (b) throw x;
}
}  // namespace detail
Repository: fmtlib/fmt
File: include/fmt/std.h (C/C++)

Code before:
#include <typeinfo>
#include <utility>
#include <vector>

#include "format.h"
#include "ostream.h"

#if FMT_HAS_INCLUDE(<version>)
#  include <version>
#endif
// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
#if FMT_CPLUSPLUS >= 201703L
#  if FMT_HAS_INCLUDE(<filesystem>)
#    include <filesystem>
#  endif
#  if FMT_HAS_INCLUDE(<variant>)
#    include <variant>
#  endif
#  if FMT_HAS_INCLUDE(<optional>)
#    include <optional>
#  endif
#  if FMT_HAS_INCLUDE(<expected>)
#    include <expected>
#  endif
#endif

#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>)
#  include <source_location>
#endif

// GCC 4 does not support FMT_HAS_INCLUDE.
#if FMT_HAS_INCLUDE(<cxxabi.h>) || defined(__GLIBCXX__)
#  include <cxxabi.h>
// Android NDK with gabi++ library on some architectures does not implement
// abi::__cxa_demangle().
#  ifndef __GABIXX_CXXABI_H__
#    define FMT_HAS_ABI_CXA_DEMANGLE
#  endif
#endif

// Check if typeid is available.
#ifndef FMT_USE_TYPEID
// __RTTI is for EDG compilers. _CPPRTTI is for MSVC.
#  if defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
      defined(__INTEL_RTTI__) || defined(__RTTI)
#    define FMT_USE_TYPEID 1
#  else
#    define FMT_USE_TYPEID 0
#  endif
#endif


Review comment (suggestion):
Move it outside ``#if FMT_CPLUSPLUS >= 201703L``.

And use C++23 condition to avoid msvc warning:
```c++
#if FMT_HAS_INCLUDE(<expected>) && FMT_CPLUSPLUS > 202002L
#  include <expected>
#endif
``` 

Code after:
#include <typeinfo>
#include <utility>
#include <vector>

#include "format.h"
#include "ostream.h"

#if FMT_HAS_INCLUDE(<version>)
#  include <version>
#endif
// Checking FMT_CPLUSPLUS for warning suppression in MSVC.
#if FMT_CPLUSPLUS >= 201703L
#  if FMT_HAS_INCLUDE(<filesystem>)
#    include <filesystem>
#  endif
#  if FMT_HAS_INCLUDE(<variant>)
#    include <variant>
#  endif
#  if FMT_HAS_INCLUDE(<optional>)
#    include <optional>
#  endif
#endif

#if FMT_HAS_INCLUDE(<expected>) && FMT_CPLUSPLUS > 202002L
#  include <expected>
#endif

#if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE(<source_location>)
#  include <source_location>
#endif

// GCC 4 does not support FMT_HAS_INCLUDE.
#if FMT_HAS_INCLUDE(<cxxabi.h>) || defined(__GLIBCXX__)
#  include <cxxabi.h>
// Android NDK with gabi++ library on some architectures does not implement
// abi::__cxa_demangle().
#  ifndef __GABIXX_CXXABI_H__
#    define FMT_HAS_ABI_CXA_DEMANGLE
#  endif
#endif

// Check if typeid is available.
#ifndef FMT_USE_TYPEID
// __RTTI is for EDG compilers. _CPPRTTI is for MSVC.
#  if defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \
      defined(__INTEL_RTTI__) || defined(__RTTI)
#    define FMT_USE_TYPEID 1
#  else
#    define FMT_USE_TYPEID 0
#  endif
#endif
Repository: fmtlib/fmt
File: include/fmt/ranges.h (C/C++)

Code before:
      set_brackets({}, {});
      ++it;
    } else {
      bool check_for_s = false;
      if (it != end && *it == '?') {
        ++it;
        detail::maybe_set_debug_format(underlying_, true);
        set_brackets({}, {});
        check_for_s = true;
        is_debug = true;
      }
      if (it != end && *it == 's') {
        if (!std::is_same<T, Char>::value) {
          report_error("invalid format specifier");
        }
        if (!is_debug) {
          set_brackets(detail::string_literal<Char, '"'>{},
                       detail::string_literal<Char, '"'>{});
        }
        check_for_s = false;
        is_string_format = true;
        ++it;
      }
      if (check_for_s) {
        report_error("invalid format specifier");
      }
    }

    if (it != end && *it != '}') {
      if (is_string_format || *it != ':')
        report_error("invalid format specifier");
      ++it;
    } else {
      if (!is_string_format) detail::maybe_set_debug_format(underlying_, true);
    }

    ctx.advance_to(it);
    return underlying_.parse(ctx);
  }

  template <typename R, typename FormatContext, typename U = T,
            enable_if_t<std::is_same<U, Char>::value, bool> = true>
  auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) {
    detail::range_mapper<buffered_context<Char>> mapper;
    auto out = ctx.out();
    out = detail::copy<Char>(opening_bracket_, out);
    int i = 0;
    auto it = detail::range_begin(range);
    auto end = detail::range_end(range);
    if (is_string_format) {
      if (is_debug) {

Review comment (suggestion):
There should be a check that the element is of `Char` type.

Code after:
    }

    switch (detail::to_ascii(*it)) {
    case 'n':
      set_brackets({}, {});
      ++it;
      break;
    case '?':
      is_debug = true;
      set_brackets({}, {});
      ++it;
      if (it == end || *it != 's') {
        report_error("invalid format specifier");
      }
      FMT_FALLTHROUGH;
    case 's':
      if (!std::is_same<T, Char>::value) {
        report_error("invalid format specifier");
      }
      if (!is_debug) {
        set_brackets(detail::string_literal<Char, '"'>{},
                     detail::string_literal<Char, '"'>{});
        set_separator({});
        detail::maybe_set_debug_format(underlying_, false);
      }
      is_string_format = true;
      ++it;
      return it;
    }

    if (it != end && *it != '}') {
      if (*it != ':') report_error("invalid format specifier");
      detail::maybe_set_debug_format(underlying_, false);
      ++it;
    }

    ctx.advance_to(it);
    return underlying_.parse(ctx);
  }

  template <typename Output, typename Iter, typename IterEnd, typename U = T,
            FMT_ENABLE_IF(std::is_same<U, Char>::value)>
  auto write_debug_string(Output& out, Iter& it, IterEnd& end) const -> Output {
    auto buf = basic_memory_buffer<Char>();
    for (; it != end; ++it) {
      buf.push_back(*it);
    }
    format_specs spec_str;
    spec_str.type = presentation_type::debug;
    return detail::write<Char>(
        out, basic_string_view<Char>(buf.data(), buf.size()), spec_str);
Repository: fmtlib/fmt
File: include/fmt/chrono.h (C/C++)

Code before:

#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907
using weekday = std::chrono::weekday;
using day = std::chrono::day;
using month = std::chrono::month;
using year = std::chrono::year;
#else
// A fallback version of weekday.
class weekday {
 private:
  unsigned char value;

 public:
  weekday() = default;
  explicit constexpr weekday(unsigned int wd) noexcept
      : value(static_cast<unsigned char>(wd != 7 ? wd : 0)) {}
  constexpr auto c_encoding() const noexcept -> unsigned int { return value; }
};

class day {
 private:
  unsigned char value;

 public:
  day() = default;
  explicit constexpr day(unsigned int d) noexcept
      : value(static_cast<unsigned char>(d)) {}
  constexpr explicit operator unsigned int () const noexcept { return value; }
};

class month {
 private:
  unsigned char value;

 public:
  month() = default;
  explicit constexpr month(unsigned int m) noexcept
      : value(static_cast<unsigned char>(m)) {}
  constexpr explicit operator unsigned int() const noexcept { return value; }
};

class year {
 private:
  int value;

 public:
  year() = default;
  explicit constexpr year(int y) noexcept : value(y) {}
  constexpr explicit operator int() const noexcept { return value; }
};


Review comment (suggestion):
nit: let's use consistent order of `constexpr` and `explicit`, i.e. change `explicit constexpr` to `constexpr explicit` here and in other places.

Code after:

#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907
using weekday = std::chrono::weekday;
using day = std::chrono::day;
using month = std::chrono::month;
using year = std::chrono::year;
#else
// A fallback version of weekday.
class weekday {
 private:
  unsigned char value_;

 public:
  weekday() = default;
  constexpr explicit weekday(unsigned wd) noexcept
      : value_(static_cast<unsigned char>(wd != 7 ? wd : 0)) {}
  constexpr auto c_encoding() const noexcept -> unsigned { return value_; }
};

class day {
 private:
  unsigned char value_;

 public:
  day() = default;
  constexpr explicit day(unsigned d) noexcept
      : value_(static_cast<unsigned char>(d)) {}
  constexpr explicit operator unsigned() const noexcept { return value_; }
};

class month {
 private:
  unsigned char value_;

 public:
  month() = default;
  constexpr explicit month(unsigned m) noexcept
      : value_(static_cast<unsigned char>(m)) {}
  constexpr explicit operator unsigned() const noexcept { return value_; }
};

class year {
 private:
  int value_;

 public:
  year() = default;
  constexpr explicit year(int y) noexcept : value_(y) {}
  constexpr explicit operator int() const noexcept { return value_; }
};
Repository: fmtlib/fmt
File: include/fmt/format-inl.h (C/C++)

Code before:
// Formatting library for C++ - implementation
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.

#ifndef FMT_FORMAT_INL_H_
#define FMT_FORMAT_INL_H_

#ifndef FMT_IMPORT_STD
#  include <algorithm>
#  include <climits>
#  include <cmath>
#  include <exception>
#endif
#include <cerrno>  // errno

#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD)
#  include <locale>
#endif

#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)
#  include <io.h>  // _isatty
#endif

#include "format.h"

FMT_BEGIN_NAMESPACE
namespace detail {

FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
  // Use unchecked std::fprintf to avoid triggering another assertion when
  // writing to stderr fails
  std::fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message);
  // Chosen instead of std::abort to satisfy Clang in CUDA mode during device
  // code pass.
  std::terminate();

Review comment (suggestion):
Here and elsewhere: `climits` only exports macros so it should be moved outside of the ifndef block.

Code after:
// Formatting library for C++ - implementation
//
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.

#ifndef FMT_FORMAT_INL_H_
#define FMT_FORMAT_INL_H_

#ifndef FMT_IMPORT_STD
#  include <algorithm>
#  include <cmath>
#  include <exception>
#endif
#include <cerrno>  // errno
#include <climits>

#if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) && !defined(FMT_IMPORT_STD)
#  include <locale>
#endif

#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE)
#  include <io.h>  // _isatty
#endif

#include "format.h"

FMT_BEGIN_NAMESPACE
namespace detail {

FMT_FUNC void assert_fail(const char* file, int line, const char* message) {
  // Use unchecked std::fprintf to avoid triggering another assertion when
  // writing to stderr fails
  std::fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message);
  // Chosen instead of std::abort to satisfy Clang in CUDA mode during device
  // code pass.
  std::terminate();
Repository: fmtlib/fmt
File: include/fmt/base.h (C/C++)

Code before:
#else
#  define FMT_CONSTEVAL
#  define FMT_CONSTEXPR20
#endif

#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
// Use the provided definition.
#elif defined(__NVCOMPILER)
#  define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L
#  define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
#elif defined(__cpp_nontype_template_args) && \
    __cpp_nontype_template_args >= 201911L
#  define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
#else
#  define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
#endif

// Detect C++20 concepts
#ifdef __cpp_concepts
#  define FMT_USE_CONCEPTS 1
#else
#  define FMT_USE_CONCEPTS 0
#endif

// Check if exceptions are disabled.
#ifdef FMT_EXCEPTIONS
// Use the provided definition.
#elif defined(__GNUC__) && !defined(__EXCEPTIONS)
#  define FMT_EXCEPTIONS 0
#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS
#  define FMT_EXCEPTIONS 0
#else
#  define FMT_EXCEPTIONS 1
#endif
#if FMT_EXCEPTIONS
#  define FMT_TRY try
#  define FMT_CATCH(x) catch (x)
#else
#  define FMT_TRY if (true)
#  define FMT_CATCH(x) if (false)
#endif

#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
#  define FMT_FALLTHROUGH [[fallthrough]]
#elif defined(__clang__)
#  define FMT_FALLTHROUGH [[clang::fallthrough]]
#elif FMT_GCC_VERSION >= 700 && \
    (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520)
#  define FMT_FALLTHROUGH [[gnu::fallthrough]]
#else

Review comment (suggestion):
The usual pattern is to first check if `FMT_USE_*` is provided by the user, see e.g. `FMT_USE_NONTYPE_TEMPLATE_ARGS`. Let's do the same here.

Code after:
#else
#  define FMT_CONSTEVAL
#  define FMT_CONSTEXPR20
#endif

#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS)
// Use the provided definition.
#elif defined(__NVCOMPILER)
#  define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L
#  define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
#elif defined(__cpp_nontype_template_args) && \
    __cpp_nontype_template_args >= 201911L
#  define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
#else
#  define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
#endif

// Detect C++20 concepts
#ifdef FMT_USE_CONCEPTS
// Use the provided definition.
#elif defined(__cpp_concepts)
#  define FMT_USE_CONCEPTS 1
#else
#  define FMT_USE_CONCEPTS 0
#endif

// Check if exceptions are disabled.
#ifdef FMT_EXCEPTIONS
// Use the provided definition.
#elif defined(__GNUC__) && !defined(__EXCEPTIONS)
#  define FMT_EXCEPTIONS 0
#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS
#  define FMT_EXCEPTIONS 0
#else
#  define FMT_EXCEPTIONS 1
#endif
#if FMT_EXCEPTIONS
#  define FMT_TRY try
#  define FMT_CATCH(x) catch (x)
#else
#  define FMT_TRY if (true)
#  define FMT_CATCH(x) if (false)
#endif

#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough)
#  define FMT_FALLTHROUGH [[fallthrough]]
#elif defined(__clang__)
#  define FMT_FALLTHROUGH [[clang::fallthrough]]
#elif FMT_GCC_VERSION >= 700 && \
    (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520)
Repository: fmtlib/fmt
File: include/fmt/base.h (C/C++)

Code before:
// Formatting library for C++ - the base API for char/UTF-8
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.

#ifndef FMT_BASE_H_
#define FMT_BASE_H_

#include <climits>  // CHAR_BIT
#include <cstdio>   // FILE
#include <cstring>  // strlen

#ifndef FMT_IMPORT_STD
// <cstddef> is also included transitively from <type_traits>.
#  include <cstddef>      // std::byte
#  include <type_traits>  // std::enable_if
#else
import std;
#endif

// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 100202

// Detect compiler versions.
#if defined(__clang__) && !defined(__ibmxl__)
#  define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#else
#  define FMT_CLANG_VERSION 0
#endif
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
#  define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
#else
#  define FMT_GCC_VERSION 0
#endif
#if defined(__ICL)
#  define FMT_ICC_VERSION __ICL

Review comment (performance):
We intentionally use `.h` headers here since C++ wrappers add some build time overhead (small but nonzero) and `fmt/base.h` is optimized for build speed.

Code after:
// Formatting library for C++ - the base API for char/UTF-8
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.

#ifndef FMT_BASE_H_
#define FMT_BASE_H_

// c headers are preferable for performance reasons
#ifndef FMT_MODULE
#  include <limits.h>  // CHAR_BIT
#  include <stdio.h>   // FILE
#  include <string.h>  // strlen
#endif

#ifndef FMT_IMPORT_STD
// <cstddef> is also included transitively from <type_traits>.
#  include <cstddef>      // std::byte
#  include <type_traits>  // std::enable_if
#else
import std;
#endif

// The fmt library version in the form major * 10000 + minor * 100 + patch.
#define FMT_VERSION 100202

// Detect compiler versions.
#if defined(__clang__) && !defined(__ibmxl__)
#  define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#else
#  define FMT_CLANG_VERSION 0
#endif
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
#  define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
#else
#  define FMT_GCC_VERSION 0