Repository: google/flatbuffers
File: include/flatbuffers/stl_emulation.h (C/C++)

Code before:
#include <string>
#include <type_traits>
#include <vector>
#include <memory>
#include <limits>

#ifndef FLATBUFFERS_USE_STD_OPTIONAL
  // Detect C++17 compatible compiler.
  // __cplusplus >= 201703L - a compiler has support of 'static inline' variables.
  #if (defined(__cplusplus) && __cplusplus >= 201703L) \
      || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
    #define FLATBUFFERS_USE_STD_OPTIONAL 1
  #else
    #define FLATBUFFERS_USE_STD_OPTIONAL 0
  #endif // (defined(__cplusplus) && __cplusplus >= 201703L) ...
#endif // FLATBUFFERS_USE_STD_OPTIONAL

#if FLATBUFFERS_USE_STD_OPTIONAL
  #include <optional>
#endif

#ifndef FLATBUFFERS_USE_STD_SPAN
  #if defined(__cplusplus) && __cplusplus >= 202002L
    #define FLATBUFFERS_USE_STD_SPAN 1
  #endif
#endif // FLATBUFFERS_USE_STD_SPAN

#if defined(FLATBUFFERS_USE_STD_SPAN)
  #include <array>
  #include <span>
#else
  // Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined.
  #if !defined(FLATBUFFERS_TEMPLATES_ALIASES)
    #define FLATBUFFERS_SPAN_MINIMAL
  #else
    // Enable implicit construction of a span<T,N> from a std::array<T,N>.
    #include <array>
  #endif
#endif // defined(FLATBUFFERS_USE_STD_SPAN)

// This header provides backwards compatibility for older versions of the STL.
namespace flatbuffers {

#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
  template <typename T>
  using numeric_limits = std::numeric_limits<T>;
#else
  template <typename T> class numeric_limits :
    public std::numeric_limits<T> {};
#endif  // defined(FLATBUFFERS_TEMPLATES_ALIASES)


Review comment (refactor):
Can you leave a doc comment here, perhaps with a link (https://en.cppreference.com/w/cpp/utility/feature_test)

Code after:
#include <string>
#include <type_traits>
#include <vector>
#include <memory>
#include <limits>

#ifndef FLATBUFFERS_USE_STD_OPTIONAL
  // Detect C++17 compatible compiler.
  // __cplusplus >= 201703L - a compiler has support of 'static inline' variables.
  #if (defined(__cplusplus) && __cplusplus >= 201703L) \
      || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
    #define FLATBUFFERS_USE_STD_OPTIONAL 1
  #else
    #define FLATBUFFERS_USE_STD_OPTIONAL 0
  #endif // (defined(__cplusplus) && __cplusplus >= 201703L) ...
#endif // FLATBUFFERS_USE_STD_OPTIONAL

#if FLATBUFFERS_USE_STD_OPTIONAL
  #include <optional>
#endif

#ifndef FLATBUFFERS_USE_STD_SPAN
  // Testing __cpp_lib_span requires including either <version> or <span>,
  // both of which were added in C++20.
  // See: https://en.cppreference.com/w/cpp/utility/feature_test
  #if defined(__cplusplus) && __cplusplus >= 202002L
    #define FLATBUFFERS_USE_STD_SPAN 1
  #endif
#endif // FLATBUFFERS_USE_STD_SPAN

#if defined(FLATBUFFERS_USE_STD_SPAN)
  #include <array>
  #include <span>
#else
  // Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined.
  #if !defined(FLATBUFFERS_TEMPLATES_ALIASES)
    #define FLATBUFFERS_SPAN_MINIMAL
  #else
    // Enable implicit construction of a span<T,N> from a std::array<T,N>.
    #include <array>
  #endif
#endif // defined(FLATBUFFERS_USE_STD_SPAN)

// This header provides backwards compatibility for older versions of the STL.
namespace flatbuffers {

#if defined(FLATBUFFERS_TEMPLATES_ALIASES)
  template <typename T>
  using numeric_limits = std::numeric_limits<T>;
#else
  template <typename T> class numeric_limits :