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"
44template<
typename ITER,
typename ACCESS>
45[[nodiscard]]
inline std::string
53 return to_string(access(begin));
56 using elt_type =
strip_t<
decltype(access(begin))>;
59 std::size_t budget{0};
60 for (ITER cnt{begin}; cnt != end; ++cnt)
61 budget += traits::size_buffer(access(cnt));
63 static_cast<std::size_t
>(std::distance(begin, end)) * std::size(sep);
68 char *
const data{
result.data()};
70 char *stop{data + budget};
71 here = traits::into_buf(here, stop, access(begin)) - 1;
72 for (++begin; begin != end; ++begin)
74 here += sep.copy(here, std::size(sep));
75 here = traits::into_buf(here, stop, access(begin)) - 1;
77 result.resize(
static_cast<std::size_t
>(here - data));
83template<
typename ITER>
84[[nodiscard]]
inline std::string
93template<
typename CONTAINER>
94[[nodiscard]]
inline auto
101 ->
typename std::enable_if<
102 (not std::is_void<
decltype(std::begin(c))>::value and
103 not std::is_void<
decltype(std::end(c))>::value),
112 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
113 typename std::enable_if<
114 (INDEX == std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
116 std::string_view , TUPLE
const &t, ACCESS
const &access)
118 return to_string(access(&std::get<INDEX>(t)));
122 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
123 typename std::enable_if<
124 (INDEX < std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
125[[nodiscard]]
inline std::string
126separated_list(std::string_view sep, TUPLE
const &t, ACCESS
const &access)
128 std::string out{to_string(access(&std::get<INDEX>(t)))};
135 typename TUPLE, std::size_t INDEX = 0,
136 typename std::enable_if<
137 (INDEX <= std::tuple_size<TUPLE>::value),
int>::type = 0>
138[[nodiscard]]
inline std::string
142 return separated_list(sep, t, [](TUPLE
const &tup) {
return *tup; });
Result set containing data returned by a query or command.
Definition result.hxx:73
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx: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:46
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition types.hxx:78
Traits class for use in string conversions.
Definition strconv.hxx:153