44 std::copy_n(str, N, data);
51 constexpr operator const char*()
const {
return data; }
54 constexpr operator std::string_view()
const {
return std::string_view(data, N - 1); }
60 constexpr size_t size()
const {
return N - 1; }
67 template <
auto... Strs>
68 constexpr auto join() const noexcept
71 constexpr std::size_t total_len = (N - 1) + (Strs.size() + ... + 0);
75 std::copy_n(data, N, result.data);
77 auto append = [i=N-1, &result](
auto const& s)
mutable
79 std::copy_n(s.data, s.size(), result.data+i);
84 result.data[total_len] =
'\0';
97[[nodiscard]]
inline std::string
to_string(T&& t)
noexcept
105 return std::string{t};
109 return std::to_string(t);
113 std::stringstream ss;
119 std::stringstream ss;
121 std::for_each(t.cbegin(), t.cend(), [&](
auto&& e){ ss << std::format(
"'{}',", e); });
127 static_assert(
false,
"Cannot convert type to string");
140[[nodiscard]] std::string
from_container(T&& t, std::optional<char> sep = std::nullopt)
noexcept
142 std::stringstream ret;
143 for(
auto it = t.begin(); it != t.end(); ++it )
146 if ( std::next(it) != t.end() and sep ) { ret << *sep; }
160template<std::input_iterator It>
161[[nodiscard]] std::string
from_container(It&& begin, It&& end, std::optional<char> sep = std::nullopt)
noexcept
177template<
typename... Args>
180 std::vector<std::string> replacements;
182 ((replacements.push_back(
to_string(std::forward<Args>(args)))), ...);
185 std::size_t arg_index = 0;
186 while (arg_index < replacements.size())
188 size_t pos = str.find(
"{}");
189 if (pos == std::string::npos)
break;
190 str.replace(pos, 2, replacements[arg_index++]);
Custom C++ concepts for type constraints and compile-time validation.
Concept for iterable containers (has begin() and end())
Concept for numeric types (integral or floating-point)
Concept for types that support stream insertion (operator<<)
Concept for types that can construct a std::string.
Concept for types implicitly convertible to std::string.
String manipulation and conversion utilities.
std::string to_string(T &&t) noexcept
Converts a type to a string.
std::string placeholders_replace(std::string str, Args &&... args)
Replace all occurrences of "{}" placeholders in a string with provided values.
std::string from_container(T &&t, std::optional< char > sep=std::nullopt) noexcept
Converts a container into a string if it has string convertible elements.
constexpr static_string()=default
Default constructor.
constexpr size_t size() const
Returns the size of the string (excluding null terminator)
constexpr static_string(const char(&str)[N])
Constructs a static string from a string literal.
constexpr auto join() const noexcept
Concatenates this string with other static strings.