libpqxx
The C++ client library for PostgreSQL
Loading...
Searching...
No Matches
concat.hxx
1#if !defined(PQXX_CONCAT_HXX)
2# define PQXX_CONCAT_HXX
3
4# include <string>
5# include <string_view>
6
7# include "pqxx/strconv.hxx"
8
9namespace pqxx::internal
10{
12template<typename TYPE>
13void render_item(TYPE const &item, char *&here, char *end)
14{
15 auto const next = string_traits<TYPE>::into_buf(here, end, item) - 1;
16 PQXX_ASSUME(next >= here);
17 here = next;
18}
19
20
21// C++20: Support non-random_access_range ranges.
23
30template<typename... TYPE>
31[[nodiscard]] inline std::string concat(TYPE... item)
32{
33 std::string buf;
34 // Size to accommodate string representations of all inputs, minus their
35 // terminating zero bytes.
36 buf.resize(size_buffer(item...));
37
38 char *const data{buf.data()};
39 char *here = data;
40 char *end = data + std::size(buf);
41 (render_item(item, here, end), ...);
42
43 buf.resize(static_cast<std::size_t>(here - data));
44 return buf;
45}
46} // namespace pqxx::internal
47#endif
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
std::string concat(TYPE... item)
Efficiently combine a bunch of items into one big string.
Definition concat.hxx:31
void render_item(TYPE const &item, char *&here, char *end)
Convert item to a string, write it into [here, end).
Definition concat.hxx:13
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.