11#ifndef PQXX_H_SEPARATED_LIST
12#define PQXX_H_SEPARATED_LIST
14#if !defined(PQXX_HEADER_PRE)
15# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
21#include "pqxx/strconv.hxx"
41template<
typename ITER,
typename ACCESS>
42[[nodiscard]]
inline std::string
53 using elt_type =
strip_t<
decltype(access(begin))>;
56 std::size_t budget{0};
57 for (ITER cnt{begin}; cnt != end; ++cnt)
58 budget += traits::size_buffer(access(cnt));
60 static_cast<std::size_t
>(std::distance(begin, end)) * std::size(sep);
65 char *
const data{
result.data()};
67 char *stop{data + budget};
68 here = traits::into_buf(here, stop, access(begin)) - 1;
69 for (++begin; begin != end; ++begin)
71 here += sep.copy(here, std::size(sep));
72 here = traits::into_buf(here, stop, access(begin)) - 1;
74 result.resize(
static_cast<std::size_t
>(here - data));
80template<
typename ITER>
81[[nodiscard]]
inline std::string
89template<
typename CONTAINER>
90[[nodiscard]]
inline auto
97 ->
typename std::enable_if<
98 (not std::is_void<
decltype(std::begin(c))>::value and
99 not std::is_void<
decltype(std::end(c))>::value),
108 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
109 typename std::enable_if<
110 (INDEX == std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
112 std::string_view , TUPLE
const &t, ACCESS
const &access)
114 return to_string(access(&std::get<INDEX>(t)));
118 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
119 typename std::enable_if<
120 (INDEX < std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
121[[nodiscard]]
inline std::string
122separated_list(std::string_view sep, TUPLE
const &t, ACCESS
const &access)
124 std::string out{
to_string(access(&std::get<INDEX>(t)))};
126 out.append(separated_list<TUPLE, INDEX + 1>(sep, t, access));
131 typename TUPLE, std::size_t INDEX = 0,
132 typename std::enable_if<
133 (INDEX <= std::tuple_size<TUPLE>::value),
int>::type = 0>
134[[nodiscard]]
inline std::string
138 return separated_list(sep, t, [](TUPLE
const &tup) {
return *tup; });
The home of all libpqxx classes, functions, templates, etc.
Definition array.hxx:27
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:43
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition types.hxx:91
std::string to_string(field const &value)
Convert a field to a string.
Definition result.cxx:533
Result set containing data returned by a query or command.
Definition result.hxx:74
Traits class for use in string conversions.
Definition strconv.hxx:155