aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd')
-rw-r--r--libs/kstd/kstd/bits/basic_unit.hpp4
-rw-r--r--libs/kstd/kstd/units.hpp12
2 files changed, 13 insertions, 3 deletions
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<typename ValueType, typename Tags>
+ template<typename ValueType, typename Tags, bool ImplicitDecay = false>
struct basic_unit
{
using value_type = ValueType;
@@ -22,7 +22,7 @@ namespace kstd
{}
template<std::integral T>
- 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 <kstd/bits/basic_unit.hpp>
+#include <kstd/format.hpp>
#include <kstd/result.hpp>
#include <kstd/system_error.hpp>
@@ -11,7 +12,7 @@
namespace kstd
{
- using bytes = basic_unit<std::size_t, struct bytes_tag>;
+ using bytes = basic_unit<std::size_t, struct bytes_tag, true>;
using offset = basic_unit<std::ptrdiff_t, struct byte_offset_tag>;
@@ -127,4 +128,13 @@ namespace kstd
} // namespace kstd
+template<>
+struct kstd::formatter<kstd::bytes> : kstd::formatter<std::size_t>
+{
+ constexpr auto format(kstd::bytes const & id, kstd::format_context & ctx) const -> void
+ {
+ kstd::formatter<std::size_t>::format(id.value, ctx);
+ ctx.push(" bytes");
+ }
+};
#endif