Loading...
Searching...
No Matches
concat.hxx
#if !defined(PQXX_CONCAT_HXX)
# define PQXX_CONCAT_HXX
# include <string>
# include <string_view>
# include "pqxx/strconv.hxx"
namespace pqxx::internal
{
template<typename TYPE>
void render_item(TYPE const &item, char *&here, char *end)
{
auto const next = string_traits<TYPE>::into_buf(here, end, item) - 1;
PQXX_ASSUME(next >= here);
here = next;
}
// C++20: Support non-random_access_range ranges.
template<typename... TYPE>
[[nodiscard]] inline std::string concat(TYPE... item)
{
std::string buf;
// Size to accommodate string representations of all inputs, minus their
// terminating zero bytes.
buf.resize(size_buffer(item...));
char *const data{buf.data()};
char *here = data;
char *end = data + std::size(buf);
(render_item(item, here, end), ...);
buf.resize(static_cast<std::size_t>(here - data));
return buf;
}
} // namespace pqxx::internal
#endif
pqxx::internal
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
pqxx::internal::concat
std::string concat(TYPE... item)
Efficiently combine a bunch of items into one big string.
Definition concat.hxx:31
pqxx::internal::render_item
void render_item(TYPE const &item, char *&here, char *end)
Convert item to a string, write it into [here, end).
Definition concat.hxx:13
pqxx::size_buffer
std::size_t size_buffer(TYPE const &...value) noexcept
Estimate how much buffer space is needed to represent values as a string.
Definition strconv.hxx:526
pqxx::string_traits::into_buf
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.