16 #ifndef GEOS_COMMON_FORMAT_HPP_
17 #define GEOS_COMMON_FORMAT_HPP_
19 #include <type_traits>
22 #if __cplusplus < 202002L
27 #ifndef FMT_HEADER_ONLY
28 #define FMT_HEADER_ONLY
31 #include "../include/fmt/core.h"
32 #include "../include/fmt/chrono.h"
33 #include "../include/fmt/ranges.h"
34 #include "../include/fmt/xchar.h"
35 #define GEOS_FMT_NS fmt
38 #define GEOS_FMT_NS std
47 template<
typename T >
48 struct fmt::formatter< T, std::enable_if_t< std::is_enum< T >::value > >
56 template<
typename ParseContext >
57 constexpr
auto parse( ParseContext & ctx )
69 template<
typename FormatContext >
70 auto format(
const T & value, FormatContext & ctx )
const
72 return fmt::format_to( ctx.out(),
"{}",
static_cast< std::underlying_type_t< T >
>( value ) );
81 #define GEOS_FMT( msg, ... ) GEOS_FMT_NS::format( msg, __VA_ARGS__ )
90 #define GEOS_FMT_TO( iter, size, msg, ... ) *GEOS_FMT_NS::format_to_n( iter, size - 1, msg, __VA_ARGS__ ).out = '\0'
101 template<
typename T >
102 struct GEOS_FMT_NS::formatter< std::optional< T > > : GEOS_FMT_NS::formatter< T >
110 auto format( std::optional< T >
const & opt, format_context & ctx )
const
114 return GEOS_FMT_NS::formatter< T >::format( *opt, ctx );
116 return GEOS_FMT_NS::format_to( ctx.out(),
"" );
132 #ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND
134 constexpr
auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::format_context >( ... ) ->
bool
143 #if __cplusplus < 202002L
145 static constexpr
bool has_formatter_v = fmt::has_formatter< fmt::remove_cvref_t< T >, fmt::format_context >();
147 template<
typename T >
148 concept has_formatter_v = requires ( T& v, std::format_context ctx )
150 std::formatter< std::remove_cvref_t< T > >().format( v, ctx );