cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
Classes | Namespaces | Typedefs | Functions | Variables
cxxo-utils.hpp File Reference

Small utilities used by various components of cxxomfort, but low-level and generic enough that they don't get categorized into the backport headers. More...

Classes

struct  noop_t
 noop function More...
 
class  outp< T >
 denotes a reference used as an output argument to a function. More...
 
struct  prio< I >
 priority tag struct, for ordering of function specializations. More...
 
struct  constexpr_t
 Tag type for constexpr. More...
 
struct  OpaqueNative< Ty, Tag >
 Wraps and tags a native C type as an opaque type. More...
 

Namespaces

 cxxomfort
 Namespace of the cxxomfort library.
 

Typedefs

typedef rvoid None_t
 

Functions

template<typename T >
CXXO_CONSTEXPRmin (constexpr_t, T a, T b) CXXO_NOEXCEPTNOTHROW
 
template<typename T >
CXXO_CONSTEXPRmax (constexpr_t, T a, T b) CXXO_NOEXCEPTNOTHROW
 
bool bool_once (bool &flag) CXXO_NOEXCEPTNOTHROW
 Evaluates a bool variable and "unchecks" it, returnnig its old value. More...
 
template<typename T >
T const * coalesce_ptrs (T *... ptrs) noexcept
 Examines a series of pointers and returns the value in the first non-NULL element among them. More...
 
template<typename Iter >
Iter coalesce (Iter ini, Iter fin) CXXO_NOEXCEPTNOTHROW
 Coalesces a sequence, returning the first non-NULL element, or the last element. More...
 

Variables

const noop_t noop
 noop functor - when evaluated with arguments, it does nothing
 

Detailed Description

Small utilities used by various components of cxxomfort, but low-level and generic enough that they don't get categorized into the backport headers.

Utilities:
Header File

Including this header brings up the base cxxomfort utilities as well.


Class Documentation

◆ cxxomfort::constexpr_t

struct cxxomfort::constexpr_t

Tag type for constexpr.

This is used by some cxxomfort utilities to disambiguate provided function calls that only differ on whether they can work in constexpr context.

◆ cxxomfort::OpaqueNative

struct cxxomfort::OpaqueNative

template<typename Ty, typename Tag>
struct cxxomfort::OpaqueNative< Ty, Tag >

Wraps and tags a native C type as an opaque type.

See also
https://nullptr.nl/2018/02/phantom-types/

OpaqueNative takes a native C type, like int or float and wraps it with a Tag type as an opaque (named) type. The result is a type that can be used by explicitly accessing the underlying type where desired.

The wrapper provides access to the underlying object via the value member, but the opaque interface is used via the value() and opaque() functions.

typedef OpaqueNative<double, height_tag> Height;
typedef OpaqueNativ<unsigned, age_tag> Age;
Handle_type match_person (string name, Height h, Age a) { ... }
match_person("John Doe", 32, 33); // fails
match_person("John Doe", opaque<Height>(32), opaque<Age>(33) ); // works
match_person("John Doe", opaque<Age>(33), opaque<Age>(33) ); // fails