cxxomfort  rel.20210622
Simple backports for C++ - http://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. Namespace that holds the library's own implementations, emulations and supplements.
 
 st_math
 Namespace for compile-time static (template based) arithmetic operations.
 

Classes

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

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...
 
static void output_info (std::FILE *const ff=stdout)
 Outputs information about cxxomfort configuration.
 
static std::tm to_tm (tm_time t, tm_date d)
 Composes a std::tm with information from a storage time and a storage date. More...
 
template<typename T >
CXXO_CONSTEXPRmin (constexpr_t, T a, T b) CXXO_NOEXCEPTNOTHROW
 constexpr variant of min()
 
template<typename T >
CXXO_CONSTEXPRmax (constexpr_t, T a, T b) CXXO_NOEXCEPTNOTHROW
 constexpr variant of max()
 
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 T , typename... Args>
std::array< T, sizeof...(Args)> make_array (Args...&&args)
 Makes a std::array from an argument list. More...
 
static CXXO_CONSTEXPR bool operator== (rvoid const, rvoid const) CXXO_NOEXCEPT
 All instances of rvoid compare equal:
 
static CXXO_CONSTEXPR bool operator!= (rvoid const, rvoid const) CXXO_NOEXCEPT
 All instances of rvoid compare equal:
 
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

static constexpr rvoid None = {}
 Generic "keyword" for designating the None_t value.
 
const noop_t noop
 noop functor - when evaluated with arguments, it does nothing
 

Detailed Description

Namespace of the cxxomfort library.

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"}

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.

Data Transfer:

◆ to_tm()

static std::tm cxxomfort::to_tm ( tm_time  t,
tm_date  d 
)
static

Composes a std::tm with information from a storage time and a storage date.

Precondition
t is a valid (hour, minutes, seconds) tuple.
d is a valid (year, month, day) tuple.
Returns
A struct tm object.

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

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

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.