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

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
 
rangeoperator= (range const &)=default
 
rangeoperator= (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...
 

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

◆ range() [2/4]

template<typename TYPE>
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.

◆ 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>
bool pqxx::range< TYPE >::contains ( TYPE  value) const

Does this range encompass value?

◆ contains() [2/2]

template<typename TYPE>
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.

◆ empty()

template<typename TYPE>
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==().

◆ lower_bound()

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

◆ operator &()

template<typename TYPE>
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().

◆ 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>
bool pqxx::range< TYPE >::operator!= ( range< TYPE > const &  rhs) const

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ operator==()

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

◆ upper_bound()

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

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