Reduce minimum standard from 23 to 20
This commit is contained in:
parent
8fdeb354a3
commit
5bbe94f279
2 changed files with 28 additions and 13 deletions
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.27)
|
||||||
project(utempl)
|
project(utempl)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
find_package(fmt REQUIRED)
|
find_package(fmt REQUIRED)
|
||||||
set(CMAKE_CXX_STANDART 23)
|
set(CMAKE_CXX_STANDART 20)
|
||||||
add_library(utempl INTERFACE)
|
add_library(utempl INTERFACE)
|
||||||
target_link_libraries(utempl INTERFACE fmt::fmt-header-only)
|
target_link_libraries(utempl INTERFACE fmt::fmt-header-only)
|
||||||
target_include_directories(utempl INTERFACE include)
|
target_include_directories(utempl INTERFACE include)
|
||||||
|
|
|
@ -6,6 +6,22 @@
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <fmt/compile.h>
|
#include <fmt/compile.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace utempl::utils {
|
||||||
|
template <std::size_t>
|
||||||
|
struct ConstexprString;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <std::size_t Size>
|
||||||
|
struct fmt::formatter<utempl::utils::ConstexprString<Size>> : public fmt::formatter<std::string_view> {
|
||||||
|
constexpr auto parse(format_parse_context& ctx) const {
|
||||||
|
return ctx.begin();
|
||||||
|
};
|
||||||
|
inline constexpr auto format(const utempl::utils::ConstexprString<Size>& str, auto& ctx) const {
|
||||||
|
return fmt::formatter<std::string_view>::format({str.data.begin()}, ctx);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
namespace utempl {
|
namespace utempl {
|
||||||
|
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
@ -26,12 +42,9 @@ struct ConstexprString {
|
||||||
inline constexpr auto size() const {
|
inline constexpr auto size() const {
|
||||||
return Size == 0 ? 0 : Size - 1;
|
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()};
|
return {this->data.begin()};
|
||||||
};
|
};
|
||||||
inline constexpr operator std::string() const {
|
|
||||||
return static_cast<std::string>(static_cast<std::string_view>(*this));
|
|
||||||
};
|
|
||||||
inline constexpr bool operator==(std::string_view other) const {
|
inline constexpr bool operator==(std::string_view other) const {
|
||||||
return static_cast<std::string_view>(*this) == other;
|
return static_cast<std::string_view>(*this) == other;
|
||||||
};
|
};
|
||||||
|
@ -296,15 +309,17 @@ inline auto Run(Menu&& menu) {
|
||||||
constexpr auto messagesCount = utils::kTupleSize<std::remove_cv_t<decltype(Cleared::kMessages)>>;
|
constexpr auto messagesCount = utils::kTupleSize<std::remove_cv_t<decltype(Cleared::kMessages)>>;
|
||||||
[&]<auto... Is, auto messages = Cleared::kMessages>(std::index_sequence<Is...>){
|
[&]<auto... Is, auto messages = Cleared::kMessages>(std::index_sequence<Is...>){
|
||||||
constexpr auto message = ([&]<auto I>(utils::Wrapper<I>){
|
constexpr auto message = ([&]<auto I>(utils::Wrapper<I>){
|
||||||
static constexpr auto message = get<I>(messages);
|
constexpr auto message = get<I>(messages);
|
||||||
constexpr std::size_t s = maxSize - (message.need ? message.need->size() : utils::countDigits(I));
|
constexpr std::size_t s = maxSize - (message.need ? message.need->size() : utils::countDigits(I));
|
||||||
static constexpr auto str = utils::createStringWith<s>(' ');
|
constexpr auto str3 = utils::createStringWith<s>(' ');
|
||||||
constexpr std::string_view str1{[&] {
|
constexpr auto str2 = message.message;
|
||||||
static constexpr auto st = utils::toString<I>();
|
constexpr auto str1 = [&] {
|
||||||
return message.need ? std::string_view(*message.need) : std::string_view(st);
|
if constexpr(message.need) {
|
||||||
}()}
|
return *message.need;
|
||||||
,str2{message.message}
|
} else {
|
||||||
,str3{str};
|
return utils::toString<I>();
|
||||||
|
};
|
||||||
|
}();
|
||||||
// + 1 - NULL Terminator
|
// + 1 - NULL Terminator
|
||||||
constexpr auto size = fmt::formatted_size(FMT_COMPILE(fmt.data.begin())
|
constexpr auto size = fmt::formatted_size(FMT_COMPILE(fmt.data.begin())
|
||||||
,str1
|
,str1
|
||||||
|
|
Loading…
Reference in a new issue