libpqxx
The C++ client library for PostgreSQL
Loading...
Searching...
No Matches
pqxx::range< TYPE > Class Template Reference

A C++ equivalent to PostgreSQL's range types. More...

Public Member Functions

constexpr range (range_bound< TYPE > lower, range_bound< TYPE > upper)
 Create a range.
 
constexpr range () noexcept(noexcept(exclusive_bound< TYPE >{TYPE{}}))
 Create an empty range.
 
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()))
 
constexpr bool operator!= (range const &rhs) const noexcept(noexcept(*this==rhs))
 
 range (range const &)=default
 
 range (range &&)=default
 
rangeoperator= (range const &)=default
 
rangeoperator= (range &&)=default
 
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?
 
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?
 
constexpr bool contains (range< TYPE > const &other) const noexcept(noexcept((*this &other)==other))
 Does this range encompass all of other?
 
constexpr range_bound< TYPE > const & lower_bound () const &noexcept
 
constexpr range_bound< TYPE > const & upper_bound () const &noexcept
 
constexpr range operator& (range const &other) const
 Intersection of two ranges.
 
template<typename DEST >
 operator range< DEST > () const
 Convert to another base type.
 

Detailed Description

template<typename TYPE>
class pqxx::range< TYPE >

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.

Constructor & Destructor Documentation

◆ range() [1/2]

template<typename TYPE >
pqxx::range< TYPE >::range ( range_bound< TYPE > lower,
range_bound< TYPE > upper )
inlineconstexpr

Create a range.

For each of the two bounds, pass a no_bound, inclusive_bound, or exclusive_bound.

◆ range() [2/2]

template<typename TYPE >
pqxx::range< TYPE >::range ( )
inlineconstexprnoexcept

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.

Member Function Documentation

◆ contains()

template<typename TYPE >
bool pqxx::range< TYPE >::contains ( range< TYPE > const & other) const
inlineconstexprnoexcept

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.

◆ empty()

template<typename TYPE >
bool pqxx::range< TYPE >::empty ( ) const
inlineconstexprnoexcept

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.

◆ operator&()

template<typename TYPE >
range pqxx::range< TYPE >::operator& ( range< TYPE > const & other) const
inlineconstexpr

Intersection of two ranges.

Returns a range describing those values which are in both ranges.


The documentation for this class was generated from the following file: