feat: add compile time concatting capabilities for string building in

parsing traits for hints.
This commit is contained in:
2026-05-05 10:36:12 +04:00
parent e1d72aaea7
commit 7caeb20dfa
3 changed files with 39 additions and 1 deletions

View File

@@ -2,6 +2,8 @@
#ifndef ARGPARSE_HPP #ifndef ARGPARSE_HPP
#define ARGPARSE_HPP #define ARGPARSE_HPP
#include <argument_parser.hpp> #include <argument_parser.hpp>
#include <parser_v2.hpp>
#include <argument_builder.hpp>
#include "macros.h" #include "macros.h"
#ifdef __linux__ #ifdef __linux__

View File

@@ -5,7 +5,7 @@
#include <string> #include <string>
namespace argument_parser::parsing_traits { namespace argument_parser::parsing_traits {
using hint_type = const char *; using hint_type = const char*;
template <typename T_> struct parser_trait { template <typename T_> struct parser_trait {
using type = T_; using type = T_;
@@ -50,6 +50,42 @@ namespace argument_parser::parsing_traits {
static constexpr hint_type format_hint = "3.14"; static constexpr hint_type format_hint = "3.14";
static constexpr hint_type purpose_hint = "double precision floating point number"; static constexpr hint_type purpose_hint = "double precision floating point number";
}; };
constexpr hint_type comma = ",";
template <const hint_type* PtrAddr>
struct hint_provider {
static constexpr hint_type value = *PtrAddr;
};
template<typename... Providers>
struct joiner {
static constexpr auto get_combined() {
constexpr size_t total_len = (std::string_view{Providers::value}.length() + ... + 0);
std::array<char, total_len + 1> arr{};
size_t offset = 0;
auto append = [&](hint_type s) {
std::string_view sv{s};
for (char c : sv) arr[offset++] = c;
return 0;
};
(append(Providers::value), ...);
arr[total_len] = '\0';
return arr;
}
static constexpr auto storage = get_combined();
static constexpr hint_type value = storage.data();
};
template<typename... Providers>
constexpr hint_type concat = joiner<Providers...>::value;
} // namespace argument_parser::parsing_traits } // namespace argument_parser::parsing_traits
#endif #endif