improved encoding for formating

This commit is contained in:
2025-09-25 21:06:46 +03:00
parent fb0b05d7ef
commit dac3d8e43f
3 changed files with 27 additions and 8 deletions

View File

@@ -39,6 +39,7 @@ else ()
add_library(${PROJECT_NAME} STATIC ${OMATH_SOURCES} ${OMATH_HEADERS})
endif ()
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}")

View File

@@ -4,5 +4,6 @@ if (OMATH_BUILD_TESTS)
endif ()
if (OMATH_BUILD_BENCHMARK)
add_subdirectory(benchmark)
endif()
set(BENCHMARK_ENABLE_TESTING OFF)
add_subdirectory(benchmark)
endif ()

View File

@@ -174,13 +174,30 @@ struct std::formatter<omath::Color> // NOLINT(*-dcl58-cpp)
{
return ctx.begin();
}
template<class FormatContext>
[[nodiscard]]
static auto format(const omath::Color& col, std::format_context& ctx)
static auto format(const omath::Color& col, FormatContext& ctx)
{
if constexpr (std::is_same_v<std::format_context::char_type, char>)
return std::format_to(ctx.out(), "[r:{}, g:{}, b:{}, a:{}]",
static_cast<int>(col.x * 255.f),
static_cast<int>(col.y * 255.f),
static_cast<int>(col.z * 255.f),
static_cast<int>(col.w * 255.f));
if constexpr (std::is_same_v<std::format_context::char_type, wchar_t>)
return std::format_to(ctx.out(), L"[r:{}, g:{}, b:{}, a:{}]",
static_cast<int>(col.x * 255.f),
static_cast<int>(col.y * 255.f),
static_cast<int>(col.z * 255.f),
static_cast<int>(col.w * 255.f));
if constexpr (std::is_same_v<std::format_context::char_type, char8_t>)
return std::format_to(ctx.out(), u8"[r:{}, g:{}, b:{}, a:{}]",
static_cast<int>(col.x * 255.f),
static_cast<int>(col.y * 255.f),
static_cast<int>(col.z * 255.f),
static_cast<int>(col.w * 255.f));
std::unreachable();
}
};