OZO 「お象」
Boost.Asio and libpq based asynchronous PostgreSQL unofficial header-only C++17 client library.
Concepts

Description

Library-wide concepts emulation mechanism.

We decide to use Concept-style meta programming to make easy to extend, adapt and test the library. So here is our own reinvented wheel of C++ Concepts built on template constants and std::enable_if.

Classes

interface  OperatorNot
 Negation operator support concept. More...
 
interface  OutputIterator
 Output Iterator concept. More...
 
interface  ForwardIterator
 Forward Iterator concept. More...
 
interface  Iterable
 Iterable concept. More...
 
interface  InsertIterator
 Insert Iterator concept. More...
 
interface  CompletionToken
 Completion token concept. More...
 
interface  Handler
 Handler concept. More...
 
interface  HasDefinition
 Condition indicates if type has corresponding type traits for PostgreSQL. More...
 

Types

template<bool Condition, typename Type = void>
using ozo::Require = Type
 Concept requirement emulation. More...
 

Variables

template<typename T >
constexpr auto ozo::Nullable
 Indicates if type is marked as conformed to nullable requirements. More...
 

Types

◆ Require

template<bool Condition, typename Type = void>
using ozo::Require = typedef Type

Concept requirement emulation.

This is requirement simulation type, which is the alias to std::enable_if_t. It is pretty simple to use it with pseudo-concepts such as OperatorNot, Iterable and so on. E.g. overloading functions via Require:

template <typename T>
decltype(auto) unwrap(T&& c, Require<!Nullable<T>>* = 0) {
return c;
}
template <typename T>
decltype(auto) unwrap(T&& c, Require<Nullable<T>>* = 0) {
return *c;
}
Template Parameters
Condition- logical combination of concepts.
Type- return type, void by default.
Returns
Type if Condition is true

Variable Documentation

◆ Nullable

template<typename T >
constexpr auto ozo::Nullable
constexpr

Indicates if type is marked as conformed to nullable requirements.

These next types are defined as Nullable via External adaptors of the library:

If it is needed to mark type as nullable then ozo::is_nullable from the type should be specialized as std::true_type type. If the type has to be allocated in special way — ozo::allocate_nullable() should be specialized (see std::shared_ptr as an example).

Example

Raw pointers are not supported as Nullable by default, because this library uses RAII model for objects and no special deallocation functions are used. But if it is really needed and you want to deallocate the allocated objects manually you can add them as described below.

//Add raw pointer to nullables
namespace ozo {
// Mark raw pointer as nullable
template <typename T>
struct is_nullable<T*> : std::true_type {};
// Specify allocation function
template <typename T>
struct allocate_nullable_impl<T*> {
template <typename Alloc>
static void apply(T*& out, const Alloc&) {
out = new T();
}
};
}
See also
is_null(), allocate_nullable(), init_nullable(), reset_nullable()
ozo::unwrap
constexpr decltype(auto) unwrap(T &&v) noexcept(noexcept(unwrap_impl< std::decay_t< T >>::apply(std::forward< T >(v))))
Unwraps argument underlying value or forwards the argument.
Definition: unwrap.h:57
ozo::Require
Type Require
Concept requirement emulation.
Definition: concept.h:54
ozo::Nullable
constexpr auto Nullable
Indicates if type is marked as conformed to nullable requirements.
Definition: nullable.h:65