16 #ifndef GEOS_COMMON_FORMAT_HPP_
17 #define GEOS_COMMON_FORMAT_HPP_
19 #include <type_traits>
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
44 template<
typename T >
45 struct fmt::formatter< T, std::enable_if_t< std::is_enum< T >::value > >
53 template<
typename ParseContext >
54 constexpr
auto parse( ParseContext & ctx )
66 template<
typename FormatContext >
67 auto format(
const T & value, FormatContext & ctx )
const
69 return fmt::format_to( ctx.out(),
"{}",
static_cast< std::underlying_type_t< T >
>( value ) );
78 #define GEOS_FMT( msg, ... ) GEOS_FMT_NS::format( msg, __VA_ARGS__ )
84 #define GEOS_FMT_RUNTIME( msg, ... ) GEOS_FMT_NS::format( GEOS_FMT_NS::runtime( msg ), __VA_ARGS__ )
93 #define GEOS_FMT_TO( iter, size, msg, ... ) *GEOS_FMT_NS::format_to_n( iter, size - 1, msg, __VA_ARGS__ ).out = '\0'
104 template<
typename T >
105 struct GEOS_FMT_NS::formatter< std::optional< T > > : GEOS_FMT_NS::formatter< T >
113 auto format( std::optional< T >
const & opt, format_context & ctx )
const
117 return GEOS_FMT_NS::formatter< T >::format( *opt, ctx );
119 return GEOS_FMT_NS::format_to( ctx.out(),
"" );
135 #ifdef GEOS_USE_FMT_CONST_FORMATTER_WORKAROUND
137 constexpr
auto GEOS_FMT_NS::detail::has_const_formatter_impl< GEOS_FMT_NS::format_context >( ... ) ->
bool
147 static constexpr
bool has_formatter_v = fmt::is_formattable< fmt::remove_cvref_t< T > >::value;
149 namespace geos::format
155 if constexpr ( std::is_convertible_v< T, std::string > )
159 else if constexpr ( std::is_convertible_v< T, std::string_view > )
165 std::ostringstream os;
std::string string
String type.
std::string_view string_view
String type.