11 #ifndef PQXX_H_SEPARATED_LIST
12 #define PQXX_H_SEPARATED_LIST
14 #include "pqxx/compiler-public.hxx"
15 #include "pqxx/internal/compiler-internal-pre.hxx"
20 #include "pqxx/strconv.hxx"
40 template<
typename ITER,
typename ACCESS>
41 [[nodiscard]]
inline std::string
52 using elt_type =
strip_t<decltype(access(begin))>;
55 std::size_t budget{0};
56 for (ITER cnt{begin}; cnt != end; ++cnt)
57 budget += traits::size_buffer(access(cnt));
59 static_cast<std::size_t
>(std::distance(begin, end)) * std::size(sep);
64 char *
const data{
result.data()};
66 char *stop{data + budget};
67 here = traits::into_buf(here, stop, access(begin)) - 1;
68 for (++begin; begin != end; ++begin)
70 here += sep.copy(here, std::size(sep));
71 here = traits::into_buf(here, stop, access(begin)) - 1;
73 result.resize(
static_cast<std::size_t
>(here - data));
79 template<
typename ITER>
80 [[nodiscard]]
inline std::string
88 template<
typename CONTAINER>
89 [[nodiscard]]
inline auto
96 ->
typename std::enable_if<
97 (not std::is_void<decltype(std::begin(c))>::value and
98 not std::is_void<decltype(std::end(c))>::value),
107 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
108 typename std::enable_if<
109 (INDEX == std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
111 std::string_view , TUPLE
const &t, ACCESS
const &access)
113 return to_string(access(&std::get<INDEX>(t)));
117 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
118 typename std::enable_if<
119 (INDEX < std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
120 [[nodiscard]]
inline std::string
121 separated_list(std::string_view sep, TUPLE
const &t, ACCESS
const &access)
123 std::string out{
to_string(access(&std::get<INDEX>(t)))};
125 out.append(separated_list<TUPLE, INDEX + 1>(sep, t, access));
130 typename TUPLE, std::size_t INDEX = 0,
131 typename std::enable_if<
132 (INDEX <= std::tuple_size<TUPLE>::value),
int>::type = 0>
133 [[nodiscard]]
inline std::string
137 return separated_list(sep, t, [](TUPLE
const &tup) {
return *tup; });
142 #include "pqxx/internal/compiler-internal-post.hxx"
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
std::string separated_list(std::string_view sep, ITER begin, ITER end, ACCESS access)
Represent sequence of values as a string, joined by a given separator.
Definition: separated_list.hxx:42
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: types.hxx:87
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:507
Result set containing data returned by a query or command.
Definition: result.hxx:71
Traits class for use in string conversions.
Definition: strconv.hxx:153