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"
44 template<
typename ITER,
typename ACCESS>
45 [[nodiscard]]
inline std::string
59 std::size_t budget{0};
60 for (ITER cnt{begin}; cnt != end; ++cnt)
63 static_cast<std::size_t
>(std::distance(begin, end)) * std::size(sep);
66 result.resize(budget);
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));
83 template<
typename ITER>
84 [[nodiscard]]
inline std::string
93 template<
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
126 separated_list(std::string_view sep, TUPLE
const &t, ACCESS
const &access)
128 std::string out{
to_string(access(&std::get<INDEX>(t)))};
130 out.append(separated_list<TUPLE, INDEX + 1>(sep, t, access));
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; });
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::size_t size_buffer(TYPE const &...value) noexcept
Estimate how much buffer space is needed to represent values as a string.
Definition: strconv.hxx:526
Result set containing data returned by a query or command.
Definition: result.hxx:91
PQXX_LIBEXPORT std::string to_string(field const &value)
Convert a field to a string.
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
Traits class for use in string conversions.
Definition: strconv.hxx:153
std::remove_cv_t< std::remove_reference_t< TYPE >> strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: types.hxx:80