25template <
typename T =
void *>
struct list {
26 explicit list(::List *l) : list_(l) {}
29 using iterator_category = std::forward_iterator_tag;
31 using difference_type = std::ptrdiff_t;
33 ::ListCell *cell =
nullptr;
36 if constexpr (std::is_pointer_v<T>) {
37 return static_cast<T
>(lfirst(cell));
38 }
else if constexpr (std::is_same_v<T, ::Oid>) {
39 return lfirst_oid(cell);
41 static_assert(std::is_same_v<T, int>,
"unsupported list element type");
42 return lfirst_int(cell);
55 bool operator==(
const iterator &)
const =
default;
58 iterator begin()
const {
return {list_ == NIL ? nullptr : &list_->elements[0]}; }
59 iterator end()
const {
return {list_ == NIL ? nullptr : &list_->elements[list_->length]}; }
61 size_t size()
const {
return list_ == NIL ? 0 :
static_cast<size_t>(list_->length); }
62 bool empty()
const {
return list_ == NIL; }
64 operator ::List *()
const {
return list_; }
Typed, range-for-iterable view over a PostgreSQL ::List.
Definition: list.hpp:25