#include <format>
#include <iostream>
#include <sstream>
#include <string>
// Write elements of a container to std::out
void PrintContainer(const auto& container, const std::string_view info = "")
{
if (info.size()) std::cout << std::format("{}: ", info);
for (auto e : container)
std::cout << std::format("{} ", e);
std::cout << '\n';
}
// Writing elements of a range or container with configurable separators to a stream or string.
namespace MyUtils
{
// Provide separator between string elements, write result to stream
template<typename I>
std::ostream& join(I it, I end_it, std::ostream& o, std::string_view sep = "")
{
if (it != end_it) o << *it++;
while (it != end_it) o << sep << *it++;
return o;
}
// Provide separator between string elements, write result to string
template<typename I>
std::string join(I it, I end_it, std::string_view sep = "")
{
std::ostringstream o;
join(it, end_it, o, sep);
return o.str();
}
// Overload for container, stream version
template<typename Container>
std::ostream& join(Container& c, std::ostream& o, std::string_view sep = "")
{
return join(std::begin(c), std::end(c), o, sep);
}
// Overload for container, string version
template<typename Container>
std::string join(Container& c, std::string_view sep = "")
{
return join(std::begin(c), std::end(c), sep);
}
}