libpqxx  7.9.0
pqxx::range< TYPE > Class Template Reference

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

#include <range.hxx>

Public Member Functions

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

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/4]

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

Create a range.

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

References pqxx::range_bound< TYPE >::is_limited(), and pqxx::range_bound< TYPE >::value().

◆ range() [2/4]

template<typename TYPE >
constexpr pqxx::range< TYPE >::range ( )
constexprnoexcept

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.

◆ range() [3/4]

template<typename TYPE >
pqxx::range< TYPE >::range ( range< TYPE > const &  )
default

◆ range() [4/4]

template<typename TYPE >
pqxx::range< TYPE >::range ( range< TYPE > &&  )
default

Member Function Documentation

◆ contains() [1/2]

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

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.

◆ contains() [2/2]

template<typename TYPE >
constexpr bool pqxx::range< TYPE >::contains ( TYPE  value) const
constexprnoexcept

Does this range encompass value?

◆ empty()

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

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().

◆ lower_bound()

template<typename TYPE >
constexpr range_bound<TYPE> const& pqxx::range< TYPE >::lower_bound ( ) const &
constexprnoexcept

◆ operator range< DEST >()

template<typename TYPE >
template<typename DEST >
pqxx::range< TYPE >::operator range< DEST > ( ) const

Convert to another base type.

◆ operator!=()

template<typename TYPE >
constexpr bool pqxx::range< TYPE >::operator!= ( range< TYPE > const &  rhs) const
constexprnoexcept

◆ operator&()

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

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().

◆ operator=() [1/2]

template<typename TYPE >
range& pqxx::range< TYPE >::operator= ( range< TYPE > &&  )
default

◆ operator=() [2/2]

template<typename TYPE >
range& pqxx::range< TYPE >::operator= ( range< TYPE > const &  )
default

◆ operator==()

template<typename TYPE >
constexpr bool pqxx::range< TYPE >::operator== ( range< TYPE > const &  rhs) const
constexprnoexcept

◆ upper_bound()

template<typename TYPE >
constexpr range_bound<TYPE> const& pqxx::range< TYPE >::upper_bound ( ) const &
constexprnoexcept

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