mirror of
https://github.com/sametersoylu/argument-parser.git
synced 2026-05-28 20:08:10 +00:00
feat: add compile time concatting capabilities for string building in
parsing traits for hints.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#ifndef ARGPARSE_HPP
|
||||
#define ARGPARSE_HPP
|
||||
#include <argument_parser.hpp>
|
||||
#include <parser_v2.hpp>
|
||||
#include <argument_builder.hpp>
|
||||
#include "macros.h"
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
@@ -50,6 +50,42 @@ namespace argument_parser::parsing_traits {
|
||||
static constexpr hint_type format_hint = "3.14";
|
||||
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
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user