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" 41 template<
typename ITER,
typename ACCESS>
42 [[nodiscard]]
inline std::string
56 std::size_t budget{0};
57 for (ITER cnt{begin}; cnt != end; ++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));
80 template<
typename ITER>
81 [[nodiscard]]
inline std::string
89 template<
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
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; });
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:381
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
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
Traits class for use in string conversions.
Definition: strconv.hxx:154
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
Result set containing data returned by a query or command.
Definition: result.hxx:73
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:533