xo-umbrella2/xo-ppsink/include/xo/ppsink/tostr0.hpp
Roland Conybeare 3600b17cff
All checks were successful
cmake-docker / cmake-build (clang, clang++) (push) Successful in 56m21s
cmake-docker / cmake-build (gcc, g++) (push) Successful in 54m7s
CI / smoke-test (push) Successful in 1h12m17s
xo-ppsink: PpSinkFactory to own .*pp files [TIDY]
2026-09-11 08:31:23 -04:00

38 lines
1.1 KiB
C++

/** @file tostr0.hpp
*
* @author Roland Conybeare, Jul 2026
*
* xo::pp::tostr(args...): build a std::string by rendering @p args, in order,
* through a FlatSink wrapping a std::stringstream.
*
* Implementation here is tactical: it is superseded by xo-indentlog2
* functions xo::pp::tostr / xo::pp::pptostr
*
* Reserve tostr0() for subsystems that cannot use the xo-indentlog2
* because of leveling topology:
* xo-testutil xo-arena xo-subsys xo-randomgen
* Also a couple of unforced choices for principle of least surprise:
* xo-refcnt xo-flatstring
**/
#pragma once
#include "FlatSink.hpp"
//#include "pretty_ostream.hpp" /* pretty() + <ostream> for the operator<< fallback */
#include "pretty.hpp"
#include <sstream>
#include <string>
namespace xo::pp {
/** render @p args (concatenated, no separator) to a std::string **/
template <typename... Ts>
std::string
tostr0(const Ts &... args) {
std::stringbuf sbuf;
FlatSink sink(&sbuf);
(sink.pp(args), ...);
return sbuf.str();
}
} /*namespace xo::pp*/
/* end tostr0.hpp */