Files
core_zero/tjp/core/string/join.hpp
Timothy Prepscius 996151a56a flatten 20260225
2026-02-25 12:43:06 -05:00

73 lines
1.4 KiB
C++
Executable File

// License: Modified MIT (NON-AI)
// See the LICENSE file in the root directory for license information.
// Copyright 2025 Timothy Prepscius
#pragma once
#include "../iterators/is_first.hpp"
#include "to_string.hpp"
#include <string>
namespace tjp::core {
template <typename V, typename T>
void join_(std::string &result, is_first &first, const V &delimiter, const T & sv)
{
for (auto &s : sv)
{
if (!first.check())
result += delimiter;
result.insert(result.end(), s.begin(), s.end());
}
}
template <typename V, typename U, typename T>
void join_(std::string &result, is_first &first, const V &delimiter, const U &u, const T & sv)
{
for (auto &s_ : sv)
{
auto s = u(s_);
if (!first.check())
result += delimiter;
result.insert(result.end(), s.begin(), s.end());
}
}
template <typename V, typename ... T>
std::string join(const V &delimiter, T&& ... t)
{
std::string result;
is_first first;
((join_(result, first, delimiter, t)),...) ;
return result;
}
template <typename V, typename ... T>
std::string join_values(const V &delimiter, T&& ... t)
{
std::string result;
is_first first;
auto u = [](auto &v) { return to_string(v); };
((join_(result, first, delimiter, u, t)),...) ;
return result;
}
template <typename V, typename U, typename ... T>
std::string join_with(const V &delimiter, U &&u, T&& ... t)
{
std::string result;
is_first first;
((join_(result, first, delimiter, u, t)),...) ;
return result;
}
} // namespace