From 5bbe94f2796a0714f1673e282925594dd1c44981 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Thu, 22 Feb 2024 19:41:35 +0000 Subject: [PATCH] Reduce minimum standard from 23 to 20 --- CMakeLists.txt | 2 +- include/utempl/menu.hpp | 39 +++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ca677d..c2da2fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.27) project(utempl) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) find_package(fmt REQUIRED) -set(CMAKE_CXX_STANDART 23) +set(CMAKE_CXX_STANDART 20) add_library(utempl INTERFACE) target_link_libraries(utempl INTERFACE fmt::fmt-header-only) target_include_directories(utempl INTERFACE include) diff --git a/include/utempl/menu.hpp b/include/utempl/menu.hpp index 4b62cfa..76f35e9 100644 --- a/include/utempl/menu.hpp +++ b/include/utempl/menu.hpp @@ -6,6 +6,22 @@ #include #include + +namespace utempl::utils { + template + struct ConstexprString; +}; + +template +struct fmt::formatter> : public fmt::formatter { + constexpr auto parse(format_parse_context& ctx) const { + return ctx.begin(); + }; + inline constexpr auto format(const utempl::utils::ConstexprString& str, auto& ctx) const { + return fmt::formatter::format({str.data.begin()}, ctx); + }; +}; + namespace utempl { namespace utils { @@ -26,12 +42,9 @@ struct ConstexprString { inline constexpr auto size() const { return Size == 0 ? 0 : Size - 1; }; - inline constexpr operator std::string_view() const { + inline constexpr explicit operator std::string_view() const { return {this->data.begin()}; }; - inline constexpr operator std::string() const { - return static_cast(static_cast(*this)); - }; inline constexpr bool operator==(std::string_view other) const { return static_cast(*this) == other; }; @@ -296,15 +309,17 @@ inline auto Run(Menu&& menu) { constexpr auto messagesCount = utils::kTupleSize>; [&](std::index_sequence){ constexpr auto message = ([&](utils::Wrapper){ - static constexpr auto message = get(messages); + constexpr auto message = get(messages); constexpr std::size_t s = maxSize - (message.need ? message.need->size() : utils::countDigits(I)); - static constexpr auto str = utils::createStringWith(' '); - constexpr std::string_view str1{[&] { - static constexpr auto st = utils::toString(); - return message.need ? std::string_view(*message.need) : std::string_view(st); - }()} - ,str2{message.message} - ,str3{str}; + constexpr auto str3 = utils::createStringWith(' '); + constexpr auto str2 = message.message; + constexpr auto str1 = [&] { + if constexpr(message.need) { + return *message.need; + } else { + return utils::toString(); + }; + }(); // + 1 - NULL Terminator constexpr auto size = fmt::formatted_size(FMT_COMPILE(fmt.data.begin()) ,str1