9#ifndef PQXX_H_RESULT_ITER
10#define PQXX_H_RESULT_ITER
14#include "pqxx/strconv.hxx"
26template<
typename... TYPE>
class result_iter
29 using value_type = std::tuple<TYPE...>;
35 m_home{&home}, m_size{std::size(home)}
37 if (not std::empty(home))
45 if (m_index >= m_size)
55 return m_home == rhs.m_home;
57 bool operator!=(
result_iter const &rhs)
const {
return not(*
this == rhs); }
59 value_type const &operator*()
const {
return m_value; }
62 void read() { (*m_home)[m_index].convert(m_value); }
64 result
const *m_home{
nullptr};
65 result::size_type m_index{0};
66 result::size_type m_size;
77 constexpr auto tup_size{
sizeof...(TYPE)};
80 "Tried to extract ", to_string(tup_size),
81 " field(s) from a result with ", to_string(home.
columns()),
86 if (std::size(m_home) == 0)
105template<
typename CALLABLE>
109 constexpr auto sz{std::tuple_size_v<args_tuple>};
112 "Callback for for_each must take parameters, one for each column in the "
115 auto const cols{this->columns()};
118 "Callback to for_each takes ", sz,
"parameter", (sz == 1) ?
"" :
"s",
119 ", but result set has ", cols,
"field", (cols == 1) ?
"" :
"s",
".")};
122 for (
auto const r : *
this) std::apply(func, r.as_tuple<pass_tuple>());
Iterator for looped unpacking of a result.
Definition row.hxx:28
bool operator==(result_iter const &rhs) const
Comparison only works for comparing to end().
Definition result_iter.hxx:53
result_iter()=default
Construct an "end" iterator.
Definition result_iter.hxx:72
Result set containing data returned by a query or command.
Definition result.hxx:73
PQXX_PURE row_size_type columns() const noexcept
Number of columns in result.
Definition result.cxx:493
void for_each(CALLABLE &&func) const
Run func on each row, passing the row's fields as parameters.
Definition result_iter.hxx:106
auto iter() const
Iterate rows, reading them directly into a tuple of "TYPE...".
Definition result_iter.hxx:99
Error in usage of libpqxx library, similar to std::logic_error.
Definition except.hxx:249
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
std::string concat(TYPE... item)
Efficiently combine a bunch of items into one big string.
Definition concat.hxx:31
decltype(args_f(std::declval< CALLABLE >())) args_t
A callable's parameter types, as a tuple.
Definition util.hxx:616
decltype(strip_types(std::declval< TYPES... >())) strip_types_t
Take a tuple type and apply strip_t to its component types.
Definition util.hxx:629
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
strip_t< decltype(*std::begin(std::declval< CONTAINER >()))> value_type
The type of a container's elements.
Definition types.hxx:94