From 5ac1dd41aabbaff89109383933301cfc1dd495b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3n=20Bjarni=20Bjarnason?= Date: Fri, 13 Oct 2023 09:40:30 +0000 Subject: [PATCH] generating right sized constexpr string_view of unit_symbol --- src/core/include/mp-units/unit.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/core/include/mp-units/unit.h b/src/core/include/mp-units/unit.h index f381d3701..b5163195b 100644 --- a/src/core/include/mp-units/unit.h +++ b/src/core/include/mp-units/unit.h @@ -819,19 +819,17 @@ template template struct const_unit_symbol { - static constexpr std::size_t size{255}; + static consteval auto unit_symbol_len() -> std::size_t { return unit_symbol(U{}, fmt).size(); } static constexpr auto impl() noexcept { - std::array array{}; - auto out_it{mp_units::unit_symbol_to(array.begin(), U{}, fmt)}; - auto len = std::distance(array.begin(), out_it); - return std::make_pair(array, len); + std::array buffer{}; + mp_units::unit_symbol_to(std::begin(buffer), U{}, fmt); + return buffer; } // Give the joined string static storage static constexpr auto arr = impl(); - static_assert(arr.second < size); // View as a std::string_view - static constexpr std::basic_string_view value{arr.first.data(), arr.second}; + static constexpr std::basic_string_view value{arr.data(), arr.size() - 1}; }; template