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
55 std::size_t budget{0};
56 for (ITER cnt{begin}; cnt != end; ++cnt)
59 static_cast<std::size_t
>(std::distance(begin, end)) * std::size(sep);
62 result.resize(budget);
64 char *here{result.data()};
65 char *stop{here + budget};
66 here = traits::into_buf(here, stop, access(begin)) - 1;
67 for (++begin; begin != end; ++begin)
69 here += sep.copy(here, std::size(sep));
70 here = traits::into_buf(here, stop, access(begin)) - 1;
72 result.resize(static_cast<std::size_t>(here - result.data()));
78 template<
typename ITER>
79 [[nodiscard]]
inline std::string
87 template<
typename CONTAINER>
88 [[nodiscard]]
inline auto 95 ->
typename std::enable_if<
96 (not std::is_void<decltype(std::begin(c))>::value and
97 not std::is_void<decltype(std::end(c))>::value),
106 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
107 typename std::enable_if<
108 (INDEX == std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
110 std::string_view , TUPLE
const &t, ACCESS
const &access)
112 return to_string(access(&std::get<INDEX>(t)));
116 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
117 typename std::enable_if<
118 (INDEX < std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
119 [[nodiscard]]
inline std::string
122 std::string out{
to_string(access(&std::get<INDEX>(t)))};
124 out.append(separated_list<TUPLE, INDEX + 1>(sep, t, access));
129 typename TUPLE, std::size_t INDEX = 0,
130 typename std::enable_if<
131 (INDEX <= std::tuple_size<TUPLE>::value),
int>::type = 0>
132 [[nodiscard]]
inline std::string
136 return separated_list(sep, t, [](TUPLE
const &tup) {
return *tup; });
141 #include "pqxx/internal/compiler-internal-post.hxx" std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:147
Traits class for use in string conversions.
Definition: strconv.hxx:148
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
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:364
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:503
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
Result set containing data returned by a query or command.
Definition: result.hxx:70