libpqxx
The C++ client library for PostgreSQL
Toggle main menu visibility
Loading...
Searching...
No Matches
concat.hxx
Go to the documentation of this file.
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
9
namespace
pqxx::internal
10
{
12
template
<
typename
TYPE>
13
void
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
30
template
<
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
PQXX_ASSUME
#define PQXX_ASSUME(condition)
Definition
header-pre.hxx:189
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:527
strconv.hxx
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.
include
pqxx
internal
concat.hxx
Generated by
1.17.0