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

Namespace of the cxxomfort library. More...

Namespaces

 cxxostd
 Backports made available by cxxomfort.
 
 fix
 Fixes for implementation issues in std.
 
 library
 Supplements to backports and other utilities.
 
 st_math
 Namespace for compile-time static (template based) arithmetic operations.
 

Classes

class  array
 cxxomfort's implementation of std::array . More...
 
struct  constexpr_t
 Tag type for constexpr. More...
 
struct  enum_sample
 Sample enum that can be used to figure out size and signedness of enums at compiletime. More...
 
struct  info
 
struct  noop_t
 noop function More...
 
struct  OpaqueNative
 Wraps and tags a native C type as an opaque type. More...
 
class  outp
 denotes a reference used as an output argument to a function. More...
 
struct  piecewise_construct_t
 Tag indicator for piecewise construction in pair . More...
 
struct  prio
 priority tag struct, for ordering of function specializations. More...
 
struct  rvoid
 regular void This is basically a "null type": it can only be default-constructed and copy-constructed, it does not hold a value, and it can be returned from functions. More...
 
struct  tm_date
 A storage-only class to store the date component of a struct std::tm . More...
 
struct  tm_time
 A storage-only class to store the time component of a struct std::tm . More...
 

Typedefs

typedef tinyint_< signed char > tinyint
 Numeric type that models a 1-byte signed int (like int8_t ).
 
typedef tinyint_< unsigned char > tinyuint
 Numeric type that models a 1-byte unsigned int (like uint8_t ).
 
typedef rvoid None_t
 

Functions

template<class IIt , class OIt >
OIt move (IIt ini, IIt fin, OIt dest)
 Move-assigns the objects from sequence [ini,fin) to sequence at dest . More...
 
template<class IIt , class OIt >
OIt move_backward (IIt ini, IIt fin, OIt dest)
 Move-assigns the objects from sequence [ini,fin) to sequence at dest , in reverse order. More...
 
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...
 
template<typename R , typename... T>
constexpr std::array< R, sizeof...(T) > make_array (T &&... t)
 Creates a std::array from a list of arguments. More...
 
template<typename R , typename... T>
constexpr cxxomfort::array< R, sizeof...(T) > make_cxxo_array (T &&... t)
 Creates a cxxomfort::array from a list of arguments. More...
 
template<typename T , typename... Args>
std::array< T, sizeof...(Args)> make_array (Args...&&args)
 Makes a std::array from an argument list. More...
 
template<typename A , typename B >
pair< A, B > make_pair (A const &a, B const &b)
 make_pair idiom
 
template<typename C >
C::const_reference at_or (C const &cont, typename C::size_type ind, typename C::const_reference alt) CXXO_NOEXCEPTNOTHROW
 Accesses the ind -th element of cont if it exists, else alt . More...
 
template<typename C >
C::reference at_or (C &cont, typename C::size_type ind, typename C::reference alt) CXXO_NOEXCEPTNOTHROW
 at_or
 
template<typename C >
C::value_type const & atindex_or (C const &cont, typename C::size_type ind, typename C::const_reference alt) CXXO_NOEXCEPTNOTHROW
 Accesses the ind -th element of cont if it exists, else alt . More...
 

Variables

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

Detailed Description

Namespace of the cxxomfort library.

doc} impl/11-minmax.hppdoc} impl/11-permutations.hpp

doc} impl/17-clamp.hpp

Helper utilities to work with tuples.

Interfaces defined here:

doc} "../impl/p0792r0-function_ref.hpp"

doc} "impl/p0040-memory_management.hpp"

"../impl/n3334-array_ref.hpp"}


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

◆ cxxomfort::piecewise_construct_t

struct cxxomfort::piecewise_construct_t

Tag indicator for piecewise construction in pair .

Typedef Documentation

◆ None_t

typedef rvoid None_t

Exposes a generic "None" type.

Utilities:
"None" type

Function Documentation

◆ move()

OIt cxxomfort::move ( IIt  ini,
IIt  fin,
OIt  dest 
)

◆ move_backward()

OIt cxxomfort::move_backward ( IIt  ini,
IIt  fin,
OIt  dest 
)

Move-assigns the objects from sequence [ini,fin) to sequence at dest , in reverse order.

◆ min()

CXXO_CONSTEXPR T cxxomfort::min ( constexpr_t  ,
a,
b 
)

◆ max()

CXXO_CONSTEXPR T cxxomfort::max ( constexpr_t  ,
a,
b 
)

constexpr variant of max()

Utilities:
constexpr version of std::max()

Referenced by splitmix64::splitmix64().

◆ bool_once()

bool cxxomfort::bool_once ( bool &  flag)

Evaluates a bool variable and "unchecks" it, returnnig its old value.

Parameters
flagA writable bool type value.
Returns
The previously held value of flag .
Exceptions
Neverthrows.
Utilities:
Manages a bool flag so that it evaluates to true once.

The use case is such as performing repetitive tasks eg.: inside a loop, but where the very first iteration of the loop has a different, added code path:

// before
// this falls outside of the loop and can cause code desync due to repetition
repetitive_task(x, y, 0);
for (size_t idx= 1; idx < last; ++i) {
separation_task(w);
repetitive_task(x, y, idx);
}
// after
bool first= true;
for (size_t idx= 0; idx < last; ++idx) {
if (!bool_once(first)) {
separation_task(w);
}
// now the task is strictly part of the loop
repetitive_task(x, y, idx);
}

See also std::exchange().

◆ coalesce_ptrs()

T const* cxxomfort::coalesce_ptrs ( T *...  ptrs)
noexcept

Examines a series of pointers and returns the value in the first non-NULL element among them.

Parameters
p1,p2,...A list of pointers to T .
Returns
The first p that is not NULL, or else the last p.
Exceptions
Neverthrows.

The function is variadic in C++≥11; in versions before it can take up to 5 arguments.

The funcion is noexcept in C++≥11, and marked throw() in versions before if the compiler supports it.

◆ coalesce()

Iter cxxomfort::coalesce ( Iter  ini,
Iter  fin 
)

Coalesces a sequence, returning the first non-NULL element, or the last element.

Parameters
ini,finIterators working as pointer-like elements.
Exceptions
Neverthrows.

The function assumes pointer-like interface for the iterator type and thus never throws (is marked noexcept for C++≥11). Attempting to use it with an iterator type that can throw on dereference is unsupported.

◆ make_array() [1/2]

constexpr std::array<R, sizeof...(T) > cxxomfort::make_array ( T &&...  t)

Creates a std::array from a list of arguments.

<array>:
Creates an array (part of experimental/lfv2)

The expression make_array<V>(arguments...) creates an array as follows:

auto myarray = make_array<int> (3, 4, 5, 6, -7, 8);
// type of "myarray" is std::array<int,6>

This is added to namespace std::experimental.

The accessory function make_cxxo_array() creates a cxxomfort::array instead.

Precondition
The arguments... resolve to a type that can be used to construct V .
Note
In C++11 onward, tye type V can be ommitted, in which case it is deduced via std::common_type.

◆ make_cxxo_array()

constexpr cxxomfort::array<R, sizeof...(T) > cxxomfort::make_cxxo_array ( T &&...  t)

Creates a cxxomfort::array from a list of arguments.

<array>:
Creates an array (part of experimental/lfv2)
Creates an array (part of experimental/lfv2)

This function is similar to make_array() except it creates a cxxomfort::array instead. It is part of "Implementation Fixes" .

◆ make_array() [2/2]

std::array<T, sizeof...(Args)> cxxomfort::make_array ( Args...&&  args)

Makes a std::array from an argument list.

Parameters
args...The list of elements that goes into the array.
Template Parameters
TThe element type (value_type ) of the returned array .

make_array() creates a std::array given an argument list and a type to which the arguments are converted for placing them in the array. The array returned has a size equal to the number of arguments passed.

The function takes one template parameter T , which is the element type of the returned array. Starting with C++11, if the type given here is void , the type of the array will be automatically deduced if possible as per std::common_type. Pre-C++11, the type T must be given explicitly.

// here A1 is array<short,4>,
// and some of the elements are narrowed
auto A1 = make_array<short> (1, 2, 30000000UL, 4);
// here A2 is array< (int)(*)(), 3>
// , that is, an array of function pointers
auto A2 = make_array<void>(rand, drand, lrand);

◆ at_or()

C::const_reference cxxomfort::at_or ( C const &  cont,
typename C::size_type  ind,
typename C::const_reference  alt 
)

Accesses the ind -th element of cont if it exists, else alt .

Parameters
contA container or container-like object supporting member .at() .
indAn index.
altAn alternative return value if a suitable element in cont is not found.
Returns
ref A reference to the requested element in cont , or the reference alt if such element doesn't exist.
Exceptions
noexceptNever throws.

This function encapsulates the idiom of accessing the i-th element of C, or a suitable default A if no i-th element is found. Such an idiom already exists for other components in the form of eg.: variant/optional get_if<I>().

at_or() is marked noexcept . It is intended to never throw, as it checks the precondition to access the element in C 's .at() before accessing. No practical implementation of .size() or relational operators could be thought that throws, so this is safe to do.

◆ atindex_or()

C::value_type const& cxxomfort::atindex_or ( C const &  cont,
typename C::size_type  ind,
typename C::const_reference  alt 
)

Accesses the ind -th element of cont if it exists, else alt .

Parameters
contA container or container-like object supporting member .at() .
indAn index.
altAn alternative return value if a suitable element in cont is not found.
Returns
ref A reference to the requested element in cont , or the reference alt if such element doesn't exist.
Exceptions
noexceptNever throws.

This function encapsulates the idiom of accessing the i-th element of C, or a suitable default A if no i-th element is found. Such an idiom already exists for other components in the form of eg.: variant/optional get_if<I>().

atindex_or() is similar to at_or() in all respects but one, including being marked noexcept ; the one difference being that access is performed via member .operator[](); as such, if that access does not exist for cont , compilation fails.