4#if !defined(PQXX_HEADER_PRE)
5# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
25 template<
typename TYPE>
30 template<
typename TYPE>
53 throw argument_error{
"Got null value as an inclusive range bound."};
56 [[nodiscard]]
constexpr TYPE
const &
get() const & noexcept
63 noexcept(
noexcept(value < m_value))
65 return not(value < m_value);
70 noexcept(
noexcept(value < m_value))
72 return not(m_value < value);
92 throw argument_error{
"Got null value as an exclusive range bound."};
95 [[nodiscard]]
constexpr TYPE
const &
get() const & noexcept
102 noexcept(
noexcept(m_value < value))
104 return m_value < value;
109 noexcept(
noexcept(value < m_value))
111 return value < m_value;
142 std::declval<inclusive_bound<TYPE>
const &>()}) and
144 std::declval<exclusive_bound<TYPE>
const &>()})) =
default;
149 noexcept(
noexcept(*this->
value() == *rhs.value()))
153 rhs.is_limited() and (this->
is_inclusive() == rhs.is_inclusive()) and
154 (*this->
value() == *rhs.value()));
156 return not rhs.is_limited();
160 noexcept(
noexcept(*
this == rhs))
162 return not(*
this == rhs);
170 return not std::holds_alternative<no_bound>(m_bound);
176 return std::holds_alternative<inclusive_bound<TYPE>>(m_bound);
182 return std::holds_alternative<exclusive_bound<TYPE>>(m_bound);
189 [&
value](
auto const &bound)
noexcept(
noexcept(bound.extends_down_to(
190 value))) { return bound.extends_down_to(value); },
198 [&
value](
auto const &bound)
noexcept(
noexcept(
199 bound.extends_up_to(
value))) { return bound.extends_up_to(value); },
204 [[nodiscard]]
constexpr TYPE
const *
value() const & noexcept
207 [](
auto const &bound)
noexcept {
208 using bound_t = std::decay_t<
decltype(bound)>;
209 if constexpr (std::is_same_v<bound_t, no_bound>)
210 return static_cast<TYPE
const *
>(
nullptr);
252 m_lower{lower}, m_upper{upper}
258 "Range's lower bound (", *lower.
value(),
259 ") is greater than its upper bound (", *upper.
value(),
").")};
272 noexcept(this->
lower_bound() == rhs.lower_bound()) and
273 noexcept(this->
upper_bound() == rhs.upper_bound()) and
274 noexcept(this->
empty()))
276 return (this->
lower_bound() == rhs.lower_bound() and
277 this->upper_bound() == rhs.upper_bound()) or
278 (this->
empty() and rhs.empty());
282 noexcept(
noexcept(*
this == rhs))
284 return not(*
this == rhs);
301 constexpr bool empty() const noexcept(
302 noexcept(m_lower.is_exclusive()) and noexcept(m_lower.is_limited()) and
303 noexcept(*m_lower.value() < *m_upper.value()))
305 return (m_lower.is_exclusive() or m_upper.is_exclusive()) and
306 m_lower.is_limited() and m_upper.is_limited() and
307 not(*m_lower.value() < *m_upper.value());
311 constexpr bool contains(TYPE value)
const noexcept(
312 noexcept(m_lower.extends_down_to(value)) and
313 noexcept(m_upper.extends_up_to(value)))
315 return m_lower.extends_down_to(value) and m_upper.extends_up_to(value);
323 noexcept(
noexcept((*
this & other) == other))
325 return (*
this & other) == other;
351 else if (*other.
lower_bound().value() < *this->lower_bound().value())
363 else if (*other.
upper_bound().value() < *this->upper_bound().value())
373 lower.is_limited() and upper.is_limited() and
374 (*upper.value() < *lower.value()))
377 return {lower, upper};
394 return {lower, upper};
405 [[nodiscard]]
static inline zview
418 char *here = begin + s_empty.copy(begin, std::size(s_empty));
428 (
static_cast<char>(value.
lower_bound().is_inclusive() ?
'[' :
'('));
431 if (lower !=
nullptr)
436 if (upper !=
nullptr)
438 if ((end - here) < 2)
441 static_cast<char>(value.
upper_bound().is_inclusive() ?
']' :
')');
449 if (std::size(
text) < 3)
451 bool left_inc{
false};
454 case '[': left_inc =
true;
break;
461 (std::size(
text) != std::size(s_empty)) or
462 (
text[1] !=
'm' and
text[1] !=
'M') or
463 (
text[2] !=
'p' and
text[2] !=
'P') or
464 (
text[3] !=
't' and
text[3] !=
'T') or
465 (
text[4] !=
'y' and
text[4] !=
'Y'))
475 std::size_t index{0};
477 static constexpr std::size_t last{1};
481 std::optional<TYPE> lower, upper;
483 auto const field_parser{
486 field_parser(index,
text, pos, lower, last);
487 field_parser(index,
text, pos, upper, last);
490 if (pos != std::size(
text))
492 char const closing{
text[pos - 1]};
493 if (closing !=
')' and closing !=
']')
495 bool const right_inc{closing ==
']'};
513 return {lower_bound, upper_bound};
516 [[nodiscard]]
static inline constexpr std::size_t
519 TYPE
const *lower{value.lower_bound().value()},
520 *upper{value.upper_bound().value()};
521 std::size_t
const lsz{
526 return std::size(s_empty) + 1;
528 return 1 + lsz + 1 + usz + 2;
532 static constexpr zview s_empty{
"empty"_zv};
533 static constexpr auto s_overrun{
"Not enough space in buffer for range."_zv};
536 static std::string err_bad_input(std::string_view text)
538 return internal::concat(
"Invalid range input: '", text,
"'");
An exclusive boundary value to a pqxx::range.
Definition range.hxx:82
constexpr bool extends_up_to(TYPE const &value) const noexcept(noexcept(value< m_value))
Would this bound, as an upper bound, include value?
Definition range.hxx:108
constexpr exclusive_bound(TYPE const &value)
Definition range.hxx:89
constexpr TYPE const & get() const &noexcept
Definition range.hxx:95
constexpr bool extends_down_to(TYPE const &value) const noexcept(noexcept(m_value< value))
Would this bound, as a lower bound, include value?
Definition range.hxx:101
An inclusive boundary value to a pqxx::range.
Definition range.hxx:43
constexpr inclusive_bound(TYPE const &value)
Definition range.hxx:50
constexpr bool extends_down_to(TYPE const &value) const noexcept(noexcept(value< m_value))
Would this bound, as a lower bound, include value?
Definition range.hxx:62
constexpr TYPE const & get() const &noexcept
Definition range.hxx:56
constexpr bool extends_up_to(TYPE const &value) const noexcept(noexcept(value< m_value))
Would this bound, as an upper bound, include value?
Definition range.hxx:69
A range boundary value.
Definition range.hxx:121
constexpr bool extends_up_to(TYPE const &value) const
Would this bound, as an upper bound, include value?
Definition range.hxx:195
constexpr range_bound(range_bound const &) noexcept(noexcept(inclusive_bound< TYPE >{ std::declval< inclusive_bound< TYPE > const & >()}) and noexcept(exclusive_bound< TYPE >{ std::declval< exclusive_bound< TYPE > const & >()}))=default
constexpr bool is_exclusive() const noexcept
Is this boundary an exclusive one?
Definition range.hxx:180
constexpr range_bound(inclusive_bound< TYPE > const &bound) noexcept(noexcept(inclusive_bound< TYPE >{bound}))
Definition range.hxx:130
constexpr bool is_limited() const noexcept
Is this a finite bound?
Definition range.hxx:168
constexpr TYPE const * value() const &noexcept
Return bound value, or nullptr if it's not limited.
Definition range.hxx:204
constexpr bool operator!=(range_bound const &rhs) const noexcept(noexcept(*this==rhs))
Definition range.hxx:159
constexpr bool extends_down_to(TYPE const &value) const
Would this bound, as a lower bound, include value?
Definition range.hxx:186
constexpr range_bound(no_bound) noexcept
Definition range.hxx:128
range_bound & operator=(range_bound const &)=default
constexpr bool operator==(range_bound const &rhs) const noexcept(noexcept(*this->value()== *rhs.value()))
Definition range.hxx:148
constexpr range_bound(exclusive_bound< TYPE > const &bound) noexcept(noexcept(exclusive_bound{bound}))
Definition range.hxx:135
constexpr bool is_inclusive() const noexcept
Is this boundary an inclusive one?
Definition range.hxx:174
range_bound & operator=(range_bound &&)=default
constexpr range_bound(range_bound &&)=default
A C++ equivalent to PostgreSQL's range types.
Definition range.hxx:240
constexpr range operator&(range const &other) const
Intersection of two ranges.
Definition range.hxx:342
constexpr bool operator==(range const &rhs) const noexcept(noexcept(this->lower_bound()==rhs.lower_bound()) and noexcept(this->upper_bound()==rhs.upper_bound()) and noexcept(this->empty()))
Definition range.hxx:271
constexpr bool contains(TYPE value) const noexcept(noexcept(m_lower.extends_down_to(value)) and noexcept(m_upper.extends_up_to(value)))
Does this range encompass value?
Definition range.hxx:311
constexpr bool contains(range< TYPE > const &other) const noexcept(noexcept((*this &other)==other))
Does this range encompass all of other?
Definition range.hxx:322
constexpr bool operator!=(range const &rhs) const noexcept(noexcept(*this==rhs))
Definition range.hxx:281
range(range const &)=default
range & operator=(range &&)=default
range & operator=(range const &)=default
constexpr range(range_bound< TYPE > lower, range_bound< TYPE > upper)
Create a range.
Definition range.hxx:251
constexpr range_bound< TYPE > const & upper_bound() const &noexcept
Definition range.hxx:334
constexpr bool empty() const noexcept(noexcept(m_lower.is_exclusive()) and noexcept(m_lower.is_limited()) and noexcept(*m_lower.value()< *m_upper.value()))
Is this range clearly empty?
Definition range.hxx:301
constexpr range_bound< TYPE > const & lower_bound() const &noexcept
Definition range.hxx:329
constexpr range() noexcept(noexcept(exclusive_bound< TYPE >{TYPE{}}))
Create an empty range.
Definition range.hxx:266
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition except.hxx:266
Value conversion failed, e.g. when converting "Hello" to int.
Definition except.hxx:283
Could not convert value to string: not enough buffer space.
Definition except.hxx:313
Something is out of range, similar to std::out_of_range.
Definition except.hxx:326
std::string concat(TYPE... item)
Efficiently combine a bunch of items into one big string.
Definition concat.hxx:31
@ UTF8
Definition encoding_group.hxx:37
composite_field_parser< T > specialize_parse_composite_field(encoding_group enc)
Look up implementation of parse_composite_field for ENC.
Definition array-composite.hxx:274
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition util.hxx:555
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
constexpr bool is_null(TYPE const &value) noexcept
Is value null?
Definition strconv.hxx:515
zview generic_to_buf(char *begin, char *end, TYPE const &value)
Implement string_traits<TYPE>::to_buf by calling into_buf.
Definition strconv.hxx:587
@ text
Definition types.hxx:71
An unlimited boundary value to a pqxx::range.
Definition range.hxx:24
constexpr bool extends_down_to(TYPE const &) const noexcept
Definition range.hxx:26
constexpr bool extends_up_to(TYPE const &) const noexcept
Definition range.hxx:31
Nullness traits describing a type which does not have a null value.
Definition strconv.hxx:113
Traits describing a type's "null value," if any.
Definition strconv.hxx:91
static constexpr std::size_t size_buffer(range< TYPE > const &value) noexcept
Definition range.hxx:517
static char * into_buf(char *begin, char *end, range< TYPE > const &value)
Definition range.hxx:412
static zview to_buf(char *begin, char *end, range< TYPE > const &value)
Definition range.hxx:406
static range< TYPE > from_string(std::string_view text)
Definition range.hxx:447
Traits class for use in string conversions.
Definition strconv.hxx:154
static std::size_t size_buffer(TYPE const &value) noexcept
Estimate how much buffer space is needed to represent value.
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.