libpqxx
7.7.3
|
A C++ equivalent to PostgreSQL's range types. More...
#include <range.hxx>
Public Member Functions | |
range (range_bound< TYPE > lower, range_bound< TYPE > upper) | |
Create a range. More... | |
range () | |
Create an empty range. More... | |
bool | operator== (range const &rhs) const |
bool | operator!= (range const &rhs) const |
range (range const &)=default | |
range (range &&)=default | |
range & | operator= (range const &)=default |
range & | operator= (range &&)=default |
bool | empty () const |
Is this range clearly empty? More... | |
bool | contains (TYPE value) const |
Does this range encompass value ? More... | |
bool | contains (range< TYPE > const &other) const |
Does this range encompass all of other ? More... | |
constexpr range_bound< TYPE > const & | lower_bound () const &noexcept |
constexpr range_bound< TYPE > const & | upper_bound () const &noexcept |
range | operator & (range const &other) const |
Intersection of two ranges. More... | |
template<typename DEST > | |
operator range< DEST > () const | |
Convert to another base type. More... | |
A C++ equivalent to PostgreSQL's range types.
You can use this as a client-side representation of a "range" in SQL.
PostgreSQL defines several range types, differing in the data type over which they range. You can also define your own range types.
Usually you'll want the server to deal with ranges. But on occasions where you need to work with them client-side, you may want to use pqxx::range. (In cases where all you do is pass them along to the server though, it's not worth the complexity. In that case you might as well treat ranges as just strings.)
For documentation on PostgreSQL's range types, see: https://www.postgresql.org/docs/current/rangetypes.html
The value type must be copyable and default-constructible, and support the less-than (<
) and equals (==
) comparisons. Value initialisation must produce a consistent value.
pqxx::range< TYPE >::range | ( | range_bound< TYPE > | lower, |
range_bound< TYPE > | upper | ||
) |
Create a range.
For each of the two bounds, pass a no_bound, inclusive_bound, or exclusive_bound.
pqxx::range< TYPE >::range | ( | ) |
Create an empty range.
SQL has a separate literal to denote an empty range, but any range which encompasses no values is an empty range.
|
default |
|
default |
bool pqxx::range< TYPE >::contains | ( | TYPE | value | ) | const |
Does this range encompass value
?
bool pqxx::range< TYPE >::contains | ( | range< TYPE > const & | other | ) | const |
Does this range encompass all of other
?
This function is not particularly smart. It does not know, for example, that integer ranges [0,9]
and [0,10)
contain the same values.
bool pqxx::range< TYPE >::empty | ( | ) | const |
Is this range clearly empty?
An empty range encompasses no values.
It is possible to "fool" this. For example, if your range is of an integer type and has exclusive bounds of 0 and 1, it encompasses no values but its empty()
will return false. The PostgreSQL implementation, by contrast, will notice that it is empty. Similar things can happen for floating-point types, but with more subtleties and edge cases.
Referenced by pqxx::string_traits< range< TYPE > >::into_buf(), and pqxx::range< TYPE >::operator==().
|
noexcept |
range pqxx::range< TYPE >::operator& | ( | range< TYPE > const & | other | ) | const |
Intersection of two ranges.
Returns a range describing those values which are in both ranges.
References pqxx::range< TYPE >::lower_bound(), and pqxx::range< TYPE >::upper_bound().
pqxx::range< TYPE >::operator range< DEST > | ( | ) | const |
Convert to another base type.
bool pqxx::range< TYPE >::operator!= | ( | range< TYPE > const & | rhs | ) | const |
|
default |
|
default |
bool pqxx::range< TYPE >::operator== | ( | range< TYPE > const & | rhs | ) | const |
|
noexcept |