From 2adaaa4c52b731dc7d796baa978ea86fd26d24b8 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 18 Aug 2026 14:28:04 +0200 Subject: kstd: enable formatting and decay for bytes --- libs/kstd/kstd/bits/basic_unit.hpp | 4 ++-- libs/kstd/kstd/units.hpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/kstd/kstd/bits/basic_unit.hpp b/libs/kstd/kstd/bits/basic_unit.hpp index c7f794ea..750b0da6 100644 --- a/libs/kstd/kstd/bits/basic_unit.hpp +++ b/libs/kstd/kstd/bits/basic_unit.hpp @@ -8,7 +8,7 @@ namespace kstd { //! A basic template for strongly typed units. - template + template struct basic_unit { using value_type = ValueType; @@ -22,7 +22,7 @@ namespace kstd {} template - explicit constexpr operator T() const noexcept + explicit(!ImplicitDecay) constexpr operator T() const noexcept { return value; } diff --git a/libs/kstd/kstd/units.hpp b/libs/kstd/kstd/units.hpp index 61224336..95e531b8 100644 --- a/libs/kstd/kstd/units.hpp +++ b/libs/kstd/kstd/units.hpp @@ -2,6 +2,7 @@ #define KSTD_UNITS_HPP #include +#include #include #include @@ -11,7 +12,7 @@ namespace kstd { - using bytes = basic_unit; + using bytes = basic_unit; using offset = basic_unit; @@ -127,4 +128,13 @@ namespace kstd } // namespace kstd +template<> +struct kstd::formatter : kstd::formatter +{ + constexpr auto format(kstd::bytes const & id, kstd::format_context & ctx) const -> void + { + kstd::formatter::format(id.value, ctx); + ctx.push(" bytes"); + } +}; #endif -- cgit v1.2.3