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" 38 template<
typename ITER,
typename ACCESS>
39 [[nodiscard]]
inline std::string
51 std::remove_const_t<std::remove_reference_t<decltype(access(begin))>>;
52 using traits = string_traits<elt_type>;
55 for (ITER cnt{begin}; cnt != end; ++cnt)
56 budget += traits::size_buffer(access(cnt));
57 budget += static_cast<size_t>(std::distance(begin, end)) * sep.size();
60 result.resize(budget);
62 char *here{result.data()};
63 char *stop{here + budget};
64 here = traits::into_buf(here, stop, access(begin)) - 1;
65 for (++begin; begin != end; ++begin)
67 here += sep.copy(here, sep.size());
68 here = traits::into_buf(here, stop, access(begin)) - 1;
70 result.resize(static_cast<size_t>(here - result.data()));
76 template<
typename ITER>
77 [[nodiscard]]
inline std::string
85 template<
typename CONTAINER>
86 [[nodiscard]]
inline auto 93 ->
typename std::enable_if<
94 (not std::is_void<decltype(std::begin(c))>::value and
95 not std::is_void<decltype(std::end(c))>::value),
104 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
105 typename std::enable_if<
106 (INDEX == std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
108 std::string_view , TUPLE
const &t, ACCESS
const &access)
110 return to_string(access(&std::get<INDEX>(t)));
114 typename TUPLE, std::size_t INDEX = 0,
typename ACCESS,
115 typename std::enable_if<
116 (INDEX < std::tuple_size<TUPLE>::value - 1),
int>::type = 0>
117 [[nodiscard]]
inline std::string
120 std::string out{
to_string(access(&std::get<INDEX>(t)))};
122 out.append(separated_list<TUPLE, INDEX + 1>(sep, t, access));
127 typename TUPLE, std::size_t INDEX = 0,
128 typename std::enable_if<
129 (INDEX <= std::tuple_size<TUPLE>::value),
int>::type = 0>
130 [[nodiscard]]
inline std::string
133 return separated_list(sep, t, [](TUPLE
const &tup) {
return *tup; });
138 #include "pqxx/internal/compiler-internal-post.hxx" std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:478
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:40
Dedicated namespace for helper types related to prepared statements.
Definition: array.hxx:25