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

Backports made available by cxxomfort. More...

Classes

struct  array
 C++11 array class. More...
 
class  basic_string_view
 Read-only view of a string or string-like object, from C++17. See also string/basic_string_view @ cppreference . More...
 
class  bool_constant
 A bool compile time equivalent of integral_constant , as per C++17. More...
 
struct  byte
 Implements the backport for std::byte. More...
 
struct  default_delete
 
struct  index_sequence
 Integer sequence of size_t. More...
 
struct  integer_sequence
 C++14 integer_sequence utility. More...
 
struct  is_invocable
 Trait that describes if a functor of type F is invocable. More...
 
struct  linear_congruential_engine
 Backports std::linear_congruential_engine to compilers that miss it or use a different name. More...
 
struct  make_index_sequence
 
struct  make_integer_sequence
 
struct  make_void
 Metaprogramming helper that exposes void as a type, for transformations. More...
 
struct  pointer_traits
 API to refer to properties of pointer types. More...
 
struct  reference_wrapper
 std::reference_wrapper<T> implementation More...
 
struct  subtract_with_carry_engine
 Backports std::subtract_with_carry_engine to compilers that miss it or use a different name. More...
 
struct  timespec
 Struct timespec, from POSIX / C++17. Basically it stores a time_t value plus an offset in nanoseconds, where available. More...
 
class  tuple
 std::tuple<T...> implementation More...
 
class  type_index
 
class  unique_ptr
 unique_ptr: a scoped, movable smart pointer. More...
 

Typedefs

typedef basic_string_view< char, std::char_traits< char > > string_view
 Name for a strng view of char .
 
typedef basic_string_view< wchar_t, std::char_traits< wchar_t > > wstring_view
 Name for a string view of wchar_t .
 
typedef std::ranlux24_base default_random_engine
 cxxomfort uses ranlux24_base as its "default random engine". More...
 

Functions

template<typename It , typename T >
CXXO_CONSTEXPR14 void fill (It ini, It fin, T const &tv)
 Fills a sequence with a given value. More...
 
template<typename It , typename Numeric , typename T >
CXXO_CONSTEXPR14 void fill_n (It ini, Numeric n, T const &tv)
 Fills a sequence with a given value. More...
 
template<typename InpI , typename OutI , typename Predicate >
OutI copy_if (InpI ini, InpI fin, OutI dest, Predicate f)
 Copy elements conditionally to dest if they fulfill f .Copy elements from one sequence to another. More...
 
template<typename InpI , typename Integral , typename OutI >
OutI copy_n (InpI ini, Integral n, OutI dest)
 Copy a given amount of elements to dest . More...
 
template<typename InpI , typename OutI1 , typename OutI2 , typename Predicate >
std::pair< OutI1, OutI2 > partition_copy (InpI ini, InpI const fin, OutI1 Dtrue, OutI2 Dfalse, Predicate f)
 Conditionally copy from sequence [ini,fin) to either sequence starting at Dtrue or Dfalsef . More...
 
template<class It , class Pred >
CXXO_CONSTEXPR14 It find_if (It ini, It fin, Pred f)
 Finds an element in a sequence that matches a predicate. More...
 
template<class It , class Pred >
CXXO_CONSTEXPR14 It find_if_not (It ini, It fin, Pred f)
 Finds like find_if but the predicate is reversed. More...
 
template<class It , class Pred >
CXXO_CONSTEXPR14 std::iterator_traits< It >::difference_type count_if (It ini, It fin, Pred p)
 Counts the number of times in a sequence the criteria p is matched. More...
 
template<class It , typename T >
CXXO_CONSTEXPR14 std::iterator_traits< It >::difference_type count (It ini, It fin, T const &tv)
 Counts the number of times in a sequence a given value is found. More...
 
template<class RAIterator , class URNG >
void shuffle (RAIterator ini, RAIterator fin, URNG &g)
 Shuffles a sequence according to a generator call g(). More...
 
template<typename Iterator , typename Compare >
bool is_sorted (Iterator ini, Iterator fin, Compare less)
 Determines if a sequence is sorted according to a given criteria. More...
 
template<typename Iterator >
bool is_sorted (Iterator ini, Iterator fin)
 
template<class II , class Size , class UnaryFunction >
II for_each_n (II first, Size n, UnaryFunction f)
 Executes a function once for each element in a sequence, using it as an argument. More...
 
template<typename T , size_t N>
constexpr auto to_array (T(&arr)[N]) -> std::array< typename std::remove_cv< T >::type, N >
 Creates a std::array from a native C array. More...
 
template<typename T >
reference_wrapper< T > ref (T &t) CXXO_NOEXCEPTNOTHROW
 Wraps an object in a reference_wrapper . More...
 
template<typename T >
reference_wrapper< T const > cref (T const &t) CXXO_NOEXCEPTNOTHROW
 Wraps an object in a reference_wrapper to const . More...
 
template<typename T >
T * addressof (T &arg)
 Returns the address of an object. More...
 
template<typename It1 , typename ItA >
bool is_permutation (It1 ini1, It1 fin1, ItA iniA)
 Returns true if range [iniA,finA] (with internally calculated finA) is a permutation of range [ini1,fin1). More...
 
template<typename BidirIt , typename Compare >
bool next_permutation (BidirIt ini, BidirIt fin, Compare Less)
 
template<typename BidirIt , typename Compare >
bool prev_permutation (BidirIt ini, BidirIt fin, Compare less)
 
template<typename NativeType >
std::string to_string (NativeType)
 Converts an integral variable into a std::string . More...
 
template<typename RangeIt1 , typename RangeIt2 , typename Compare >
bool equal (RangeIt1 ini1, RangeIt1 fin1, RangeIt2 ini2, RangeIt2 fin2, Compare eq)
 Compare two sequences [ini1,fin1) and [ini2,fin2) for equality given comparator eq . Four-iterators overload. More...
 
template<typename RangeIt1 , typename RangeIt2 >
bool equal (RangeIt1 ini1, RangeIt1 fin1, RangeIt2 ini2, RangeIt2 fin2)
 
template<class InputIt1 , class InputIt2 , class BinaryPredicate >
std::pair< InputIt1, InputIt2 > mismatch (InputIt1 ini1, InputIt1 fin1, InputIt2 ini2, InputIt2 fin2, BinaryPredicate p)
 Finds the first difference (dif1,dif2) between two sequences [ini1,fin1) and [ini2,fin2), given comparator eq . Four-iterator overload. More...
 
template<class InputIt1 , class InputIt2 >
std::pair< InputIt1, InputIt2 > mismatch (InputIt1 ini1, InputIt1 fin1, InputIt2 ini2, InputIt2 fin2)
 
template<typename T , typename ... Args>
std::unique_ptr< T > make_unique (Args &&... args)
 Creates a unique_ptr holding a constructed object. More...
 
template<typename T , typename... TupleArgs>
T & get (std::tuple< TupleArgs... > &)
 Return a member of a tuple given its type as a template argument. More...
 
template<typename T , typename... TupleArgs>
T const & get (std::tuple< TupleArgs... > const &)
 
template<typename T >
constexpr std::add_const< T >::type & as_const (T &t) noexcept
 returns a const view of object t . A C++17 Backports . More...
 
template<typename T >
constexpr std::add_const< T >::type * as_ptr_const (T *const t) noexcept
 returns a const view of a pointer t . An extension to as_const() . More...
 
bool operator== (byte, byte)
 Compares the numerical expression of two bytes.
 
bool operator!= (byte, byte)
 Compares the numerical expression of two bytes.
 
template<typename Integral >
Integral to_integer (byte b)
 Converts the byte value into an Integral . More...
 
unsigned char to_value (byte b)
 Converts the byte value into an unsigned char.
 
template<class T , class Compare >
constexpr T const & clamp (T const &val, T const &lo, T const &hi, Compare comp)
 Clamps a value. More...
 
template<class T >
CXXO_CONSTEXPR T const & clamp (T const &val, T const &lo, T const &hi)
 
template<typename F , typename... Args>
dependent_type_t invoke (F &&callable, Args &&... args)
 Invokes a callable. See also invoke_r() . More...
 
template<typename R , typename F , typename... Args>
invoke_r (F &&callable, Args &&... args)
 Invokes a callable and specifies a return type. See also invoke() . More...
 
template<typename C >
C::size_type size (C &c)
 Returns the size (number of elements) of a sequence / container expression. More...
 
template<typename C >
constexpr auto data (C &container) -> decltype(container.data())
 provides access to an internal "<code>.data()</code>" member. More...
 
template<typename C >
bool data (C const &container)
 provides access to an internal "<code>.empty()</code>" member. More...
 
template<typename C >
bool empty (C const &c)
 Accesses and returns the .empty() member of the container. More...
 
template<typename C >
size_t size (C const &c)
 Accesses and returns the .size() member of the container. More...
 
template<typename C >
C::pointer data (C const &c)
 Accesses and returns the .data() member of the container. More...
 
template<typename T , typename... TupleArgs>
make_from_tuple (std::tuple< TupleArgs... > &&Tuple)
 Create an object from a tuple expression. More...
 
template<typename F , typename Tuple >
implementation_defined_t apply (F f, Tuple &t)
 Applies the tuple t as the arguments to the functionlike / callable f . More...
 
template<typename Fn , typename... Binds>
implementation_defined_t bind_front (Fn &&callable, Binds &&... args)
 Wraps a function and its first n arguments in a callable object. More...
 
template<typename T , typename U = T>
exchange (T &obj, CXXO_RV_REF(U) nval)
 Replaces a variable's value, returns the old value. More...
 
template<typename Fn >
not_fn_t< Fn > not_fn (Fn &&f)
 Creates a function wrapper that returns the negation of a given function-like / callable. More...
 
template<typename Char >
implementation_defined_t quoted (Char const *str, Char delim='\"', Char escape='\)
 Outputs a string to a stream, quoted. More...
 
template<typename Char >
implementation_defined_t quoted (std::basic_string_view< Char > str, Char delim='\"', Char escape='\)
 
template<typename It >
CXXO_CONSTEXPR14 std::reverse_iterator< It > make_reverse_iterator (It i)
 Constructs the reverse_iterator for a given iterator. More...
 
template<typename FwIt , typename T >
FwIt iota (FwIt ini, FwIt fin, T i0)
 Fills a sequence with a sequentially growing set of values. "Numeric" iota. More...
 
template<typename FwIt , typename Integer , typename T >
FwIt iota_n (FwIt ini, Integer n, T i0)
 Fills a sequence with a sequentially growing set of values. More...
 
template<typename Num1 , typename Num2 >
CXXO_CONSTEXPR Num1 gcd (Num1 n1, Num2 n2) CXXO_NOEXCEPT
 Calculates the greatest common divisor. More...
 
template<typename Num1 , typename Num2 >
CXXO_CONSTEXPR Num1 lcm (Num1 n1, Num2 n2) CXXO_NOEXCEPT
 Calculates the lowest common multiple. More...
 
template<typename Numeric >
CXXO_CONSTEXPR Numeric midpoint (Numeric n1, Numeric n2) CXXO_NOEXCEPTNOTHROW
 Returns the midpoint between two numeric values, avoiding overflows. More...
 
template<typename Pointer >
Pointer midpoint (Pointer p1, Pointer p2) CXXO_NOEXCEPTNOTHROW
 Returns the midpoint between two pointers. More...
 
template<typename T >
T & declval ()
 Expression for an unevaluated context. "Type Utilities" declval. More...
 
template<typename U >
constexpr U bit_width (U u) noexcept
 
template<typename U >
constexpr U bit_floor (U u) noexcept
 
template<typename U >
constexpr U bit_ceil (U u) noexcept
 
template<typename U >
constexpr int popcount (U u) noexcept
 
int timespec_get (struct timespec *ts, int base)
 Returns timespec information from the system clock and writes it into ts . More...
 
template<size_t I, typename T , size_t N>
CXXO_CONSTEXPR14 T & get (array< T, N > &a) CXXO_NOEXCEPTNOTHROW
 Tuple-like interface to access an element in an array . More...
 
template<size_t I, typename T , size_t N>
CXXO_CONSTEXPR14 T const & get (array< T, N > const &a) CXXO_NOEXCEPTNOTHROW
 
template<typename Iter , typename Predicate >
bool all_of (Iter ini, Iter fin, Predicate f)
 Checks if all elements of a sequence fit a given predicate. More...
 
template<typename Iter , typename Predicate >
bool any_of (Iter ini, Iter fin, Predicate f)
 Checks if any one element of a sequence fit a given predicate. More...
 
template<typename Iter , typename Predicate >
bool none_of (Iter ini, Iter fin, Predicate f)
 Checks if no elements of a sequence fit a given predicate. More...
 
template<typename T , typename Comparator >
std::pair< T const &, T const & > minmax (T const &a, T const &b, Comparator Less)
 Return a pair(min,max) from two arguments and a comparator Less . More...
 
template<typename T >
std::pair< T const &, T const & > minmax (T const &a, T const &b)
 
template<typename FIterator , typename Comparator >
std::pair< FIterator, FIterator > minmax_element (FIterator ini, FIterator fin, Comparator less)
 Returns the pair (minimum,maximum) for the given sequence and comparator less . More...
 
template<typename FIterator >
std::pair< FIterator, FIterator > minmax_element (FIterator ini, FIterator fin)
 
template<typename T >
void destroy_at (T *p) CXXO_NOEXCEPTNOTHROW
 Destructs an object, as if the destructor was invoked via Type::~Type(). More...
 
template<typename Iter , typename Iter2 >
void destroy (Iter ini, Iter2 fin)
 Destructs a sequence of objects. More...
 
template<typename Iter , typename Integer >
void destroy_n (Iter ini, Integer n)
 Destructs a sequence of objects. More...
 
template<typename It >
void uninitialized_default_construct (It ini, It fin)
 Default-constructs objects in uninitialized memory. More...
 
template<typename It , typename Integer >
void uninitialized_default_construct_n (It ini, Integer n)
 Default-constructs objects in uninitialized memory. More...
 

Detailed Description

Backports made available by cxxomfort.

Namespace that holds the library's backports of named C++ features.


Class Documentation

◆ cxxomfort::cxxostd::default_delete

struct cxxomfort::cxxostd::default_delete

template<typename T>
struct cxxomfort::cxxostd::default_delete< T >

default_delete (stateless deleter for default new allocations ) Default deleter for utilities like unique_ptr .

◆ cxxomfort::cxxostd::is_invocable

struct cxxomfort::cxxostd::is_invocable

template<typename F, typename... Args>
struct cxxomfort::cxxostd::is_invocable< F, Args >

Trait that describes if a functor of type F is invocable.

◆ cxxomfort::cxxostd::linear_congruential_engine

struct cxxomfort::cxxostd::linear_congruential_engine

template<typename...>
struct cxxomfort::cxxostd::linear_congruential_engine<... >

Backports std::linear_congruential_engine to compilers that miss it or use a different name.

C++03/TR1 Backports:
<random> backports.
<random>:
<random> backports.

◆ cxxomfort::cxxostd::make_index_sequence

struct cxxomfort::cxxostd::make_index_sequence

template<typename T, size_t N>
struct cxxomfort::cxxostd::make_index_sequence< T, N >

Helper for index_sequence

C++14 Backports:

◆ cxxomfort::cxxostd::make_integer_sequence

struct cxxomfort::cxxostd::make_integer_sequence

template<typename T, size_t N>
struct cxxomfort::cxxostd::make_integer_sequence< T, N >

Helper for integer_sequence

C++14 Backports:

◆ cxxomfort::cxxostd::make_void

struct cxxomfort::cxxostd::make_void

template<typename... Arglist>
struct cxxomfort::cxxostd::make_void< Arglist >

Metaprogramming helper that exposes void as a type, for transformations.

C++17 Backports:
Constructs void from an instantiation.

◆ cxxomfort::cxxostd::pointer_traits

struct cxxomfort::cxxostd::pointer_traits

template<typename Ptr>
struct cxxomfort::cxxostd::pointer_traits< Ptr >

API to refer to properties of pointer types.

◆ cxxomfort::cxxostd::subtract_with_carry_engine

struct cxxomfort::cxxostd::subtract_with_carry_engine

template<typename...>
struct cxxomfort::cxxostd::subtract_with_carry_engine<... >

Backports std::subtract_with_carry_engine to compilers that miss it or use a different name.

C++03/TR1 Backports:
<random> backports.
<random>:
<random> backports.

◆ cxxomfort::cxxostd::timespec

struct cxxomfort::cxxostd::timespec

Struct timespec, from POSIX / C++17. Basically it stores a time_t value plus an offset in nanoseconds, where available.

C++17 Backports:
timespec, from POSIX.
See also
chrono/c/timespec @ cppreference

Typedef Documentation

◆ default_random_engine

cxxomfort uses ranlux24_base as its "default random engine".

<random>:
Provides ranlux24_base as the default PRNG in cxxomfort.

Function Documentation

◆ fill()

CXXO_CONSTEXPR14 void cxxomfort::cxxostd::fill ( It  ini,
It  fin,
T const &  tv 
)

Fills a sequence with a given value.

C++03/TR1 Backports:
Fills a sequence with a given value
Fills a sequence with a given value
Parameters
tvThe value to use to fill.
See also
algorithm/fill @ cppreference
Note
This algorithm is already provided in C++03. It is provided here only for enhancements in later Standards or for compilers that lack it, and is otherwise not directly used.

◆ fill_n()

CXXO_CONSTEXPR14 void cxxomfort::cxxostd::fill_n ( It  ini,
Numeric  n,
T const &  tv 
)

Fills a sequence with a given value.

Parameters
nHow many elements to fill.
tvThe value to use to fill.
C++03/TR1 Backports:
Fills a sequence with a given value
Fills a sequence with a given value
See also
algorithm/fill @ cppreference

◆ copy_if()

OutI cxxomfort::cxxostd::copy_if ( InpI  ini,
InpI  fin,
OutI  dest,
Predicate  f 
)

Copy elements conditionally to dest if they fulfill f .Copy elements from one sequence to another.

Parameters
fA predicate that will evaluate elements in the sequence.
Returns
the advanced dest iterator.
See also
algorithm/copy_if @ cppreference
algorithm/copy @ cppreference

Given the sequence [ini, fin), copies those elements e inside it to dest for which the evlauation f(e) is true .

◆ copy_n()

OutI cxxomfort::cxxostd::copy_n ( InpI  ini,
Integral  n,
OutI  dest 
)
inline

Copy a given amount of elements to dest .

Returns
the iterated dest iterator. Copy "n" elements from one sequence to another
See also
algorithm/copy_n @ cppreference
algorithm/copy @ cppreference

Copies n elements from ini to , unconditionally.

Referenced by array_ref< CharTy const >::back(), and cxxomfort::library::algorithm::copy_leftmost_n().

◆ partition_copy()

std::pair<OutI1,OutI2> cxxomfort::cxxostd::partition_copy ( InpI  ini,
InpI const  fin,
OutI1  Dtrue,
OutI2  Dfalse,
Predicate  f 
)

Conditionally copy from sequence [ini,fin) to either sequence starting at Dtrue or Dfalsef .

Parameters
fA predicate that maps InpI::value_type -> bool.
Returns
the advanced std::pair (Dtrue , Dfalse ).
Conditionally copy data to either of two destinations. Copy elements to two locations conditionally.
See also
algorithm/partition_copy @ cppreference
algorithm/copy_if @ cppreference

This algorithm is a variation of copy_if() . Where copy_if copies to one destination dest if the condition is true , partition_copy() copies elements e in [ini,fin) to either Dtrue or Dfalse depending on the return value of f(e).

◆ find_if()

CXXO_CONSTEXPR14 It cxxomfort::cxxostd::find_if ( It  ini,
It  fin,
Pred  f 
)

Finds an element in a sequence that matches a predicate.

Parameters
fA predicate that maps It::value_type -> bool.
C++11 Backports:
Find an element matching a predicate
See also
algorithm/find_if @ cppreference
Note
This algorithm is already provided in C++03. It is provided here only for enhancements in later Standards that might be desirable to invoke backports for explicitly.
This algorithm is constexpr starting C++20; here it is tentatively marked constexpr for C++14 as well. We can't modify the C++17 version.

Referenced by cxxomfort::library::algorithm::find(), cxxomfort::fix::find_if(), and cxxomfort::library::algorithm::find_if_not().

◆ find_if_not()

CXXO_CONSTEXPR14 It cxxomfort::cxxostd::find_if_not ( It  ini,
It  fin,
Pred  f 
)

Finds like find_if but the predicate is reversed.

Parameters
fA predicate that maps It::value_type -> bool.
C++11 Backports:
Find an element not matching a predicate
See also
algorithm/find_if @ cppreference
Note
This algorithm is constexpr starting C++20; here it is tentatively marked constexpr for C++14 as well. We can't modify the C++17 version.

◆ count_if()

CXXO_CONSTEXPR14 std::iterator_traits<It>::difference_type cxxomfort::cxxostd::count_if ( It  ini,
It  fin,
Pred  p 
)

Counts the number of times in a sequence the criteria p is matched.

Parameters
fA predicate that maps It::value_type -> bool.
C++17 Backports:
Count the number of elements matching a predicate
See also
algorithm/count @ cppreference
count
Note
This algorithm is constexpr starting C++20; here it is tentatively marked constexpr for C++14 as well. We can't modify the C++17 version.

Referenced by cxxomfort::fix::count_if().

◆ count()

CXXO_CONSTEXPR14 std::iterator_traits<It>::difference_type cxxomfort::cxxostd::count ( It  ini,
It  fin,
T const &  tv 
)

Counts the number of times in a sequence a given value is found.

C++17 Backports:
Count the number of elements matching a given value
See also
algorithm/count @ cppreference
count_if
Note
This algorithm is constexpr starting C++20; here it is tentatively markes constexpr for C++14 as well. We can't modify the C++17 version.

Referenced by array_ref< CharTy const >::back(), cxxomfort::string::compare(), cxxomfort::fix::count_if(), is_permutation(), and array_ref< CharTy const >::rightmost().

◆ shuffle()

void cxxomfort::cxxostd::shuffle ( RAIterator  ini,
RAIterator  fin,
URNG &  g 
)

Shuffles a sequence according to a generator call g().

Parameters
gA writable object that acts like a (P)RNG and returns a value via operator().
C++11 Backports:
Randomly shuffle elements in a sequence
Note
Requires support from <random>.

◆ is_sorted() [1/2]

bool cxxomfort::cxxostd::is_sorted ( Iterator  ini,
Iterator  fin,
Compare  less 
)
inline

Determines if a sequence is sorted according to a given criteria.

Parameters
lessCriteria for sorting, a binary function f(x,y) that returns true if x<y.
Returns
A bool response about if the sequence is sorted.
C++11 Backports:
Check if a given sequence is sorted by a given criteria
See also
algorithm/is_sorted @ cppreference

Referenced by is_sorted().

◆ is_sorted() [2/2]

bool cxxomfort::cxxostd::is_sorted ( Iterator  ini,
Iterator  fin 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ for_each_n()

II cxxomfort::cxxostd::for_each_n ( II  first,
Size  n,
UnaryFunction  f 
)

Executes a function once for each element in a sequence, using it as an argument.

Parameters
fA function that takes arguments and can modify them.
C++17 Backports:
Invoke a function over the elements of a sequence.
Invoke a function over the elements of a sequence.
Parameters
fA function object that is executed as f(i) for each i in the sequence.
See also
algorithm/for_each @ cppreference
Note
The return value of f is ignored. The "non-ignoring" equivalent is accumulate() .

◆ to_array()

constexpr auto cxxomfort::cxxostd::to_array ( T(&)  arr[N]) -> std::array< typename std::remove_cv< T >::type, N >

Creates a std::array from a native C array.

C++20 Backports:
Creates a std::array from a native C array.
<array>:
Creates a std::array from a native C array.
Note
This is backported down to full C++11 support only. For a more generic solution in cxxomfort, see make_array() or make_cxxo_array() .

◆ bit_width()

constexpr U cxxomfort::cxxostd::bit_width ( u)
noexcept
C++20 Backports:
Bit operations

Returns the number of bits required to represent the value of u .

Precondition
std::is_unsigned<U>::value

◆ bit_floor()

constexpr U cxxomfort::cxxostd::bit_floor ( u)
noexcept

Returns u rounded down to a power of 2.

Precondition
std::is_unsigned<U>::value

◆ bit_ceil()

constexpr U cxxomfort::cxxostd::bit_ceil ( u)
noexcept

Returns u rounded up to a power of 2.

Precondition
std::is_unsigned<U>::value

◆ popcount()

constexpr int cxxomfort::cxxostd::popcount ( u)
noexcept

Returns the number of 1 bits in u .

Precondition
std::is_unsigned<U>::value

◆ timespec_get()

int cxxomfort::cxxostd::timespec_get ( struct timespec ts,
int  base 
)

Returns timespec information from the system clock and writes it into ts .

C++17 Backports:
Fetches timespec information from the system clock.
See also
POSIX timespec_get() .
time/timespec_get @ cppreference

◆ get() [1/4]

CXXO_CONSTEXPR14 T& cxxomfort::cxxostd::get ( array< T, N > &  a)

Tuple-like interface to access an element in an array .

Template Parameters
IIndex to be accessed.
Returns
Direct access to the element in the array.

◆ get() [2/4]

CXXO_CONSTEXPR14 T const& cxxomfort::cxxostd::get ( array< T, N > const &  a)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ref()

reference_wrapper<T> cxxomfort::cxxostd::ref ( T &  t)

Wraps an object in a reference_wrapper .

Returns
reference_wrapper<T> holding the named object t .
C++03/TR1 Backports:
"std::reference_wrapper"
<functional>:
"std::reference_wrapper"
See also
reference_wrapper

◆ cref()

reference_wrapper<T const> cxxomfort::cxxostd::cref ( T const &  t)

Wraps an object in a reference_wrapper to const .

Returns
reference_wrapper<T const> holding the named object t .
C++03/TR1 Backports:
"std::reference_wrapper"
<functional>:
"std::reference_wrapper"
See also
reference_wrapper

◆ addressof()

T * addressof ( T &  arg)
inline

Returns the address of an object.

C++11 Backports:
Take the address of an object, even in presence of overloaded & unary. memory/addressof @ cppreference

Referenced by destroy(), and destroy_n().

◆ all_of()

bool cxxomfort::cxxostd::all_of ( Iter  ini,
Iter  fin,
Predicate  f 
)

Checks if all elements of a sequence fit a given predicate.

Returns
true if for all elements e in [ini,fin), f(e) == true.

Referenced by none_of().

◆ any_of()

bool cxxomfort::cxxostd::any_of ( Iter  ini,
Iter  fin,
Predicate  f 
)

Checks if any one element of a sequence fit a given predicate.

Returns
true if for at least one elements e in [ini,fin), f(e) == true.

Referenced by none_of().

◆ none_of()

bool cxxomfort::cxxostd::none_of ( Iter  ini,
Iter  fin,
Predicate  f 
)

Checks if no elements of a sequence fit a given predicate.

Returns
true if for no elements e in [ini,fin), f(e) == true.

◆ minmax() [1/2]

std::pair<T const&, T const&> cxxomfort::cxxostd::minmax ( T const &  a,
T const &  b,
Comparator  Less 
)

Return a pair(min,max) from two arguments and a comparator Less .

C++11 Backports:
Find the minimum and maximum elements in a sequence
Find the minimum and maximum elements in a sequence
Returns
A pair (min, max)
See also
algorithm/minmax @ cppreference

Referenced by minmax_element().

◆ minmax() [2/2]

std::pair<T const&, T const&> cxxomfort::cxxostd::minmax ( T const &  a,
T const &  b 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Referenced by minmax_element().

◆ minmax_element() [1/2]

std::pair<FIterator,FIterator> cxxomfort::cxxostd::minmax_element ( FIterator  ini,
FIterator  fin,
Comparator  less 
)

Returns the pair (minimum,maximum) for the given sequence and comparator less .

Parameters
lessA comparator object with the same semantics as std::less .
C++11 Backports:
minmax_elements
Returns
A std::pair containing the minimum and maximum.

Referenced by minmax_element().

◆ minmax_element() [2/2]

std::pair<FIterator,FIterator> cxxomfort::cxxostd::minmax_element ( FIterator  ini,
FIterator  fin 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ is_permutation()

bool cxxomfort::cxxostd::is_permutation ( It1  ini1,
It1  fin1,
ItA  iniA 
)

Returns true if range [iniA,finA] (with internally calculated finA) is a permutation of range [ini1,fin1).

C++11 Backports:
Checks if a sequence is a permutation of another. Source: cppreference.com

Referenced by prev_permutation().

◆ next_permutation()

bool cxxomfort::cxxostd::next_permutation ( BidirIt  ini,
BidirIt  fin,
Compare  Less 
)

Shuffles the sequence to become the next_permutation

◆ prev_permutation()

bool cxxomfort::cxxostd::prev_permutation ( BidirIt  ini,
BidirIt  fin,
Compare  less 
)

Shuffles the sequence to become the previous permutation

◆ to_string()

std::string cxxomfort::cxxostd::to_string ( NativeType  )

Converts an integral variable into a std::string .

Parameters
integerA variable of one of C++'s integer ("integral") types (see overloads).
Returns
a std::string
<string>:

◆ equal() [1/2]

bool cxxomfort::cxxostd::equal ( RangeIt1  ini1,
RangeIt1  fin1,
RangeIt2  ini2,
RangeIt2  fin2,
Compare  eq 
)
inline

Compare two sequences [ini1,fin1) and [ini2,fin2) for equality given comparator eq . Four-iterators overload.

Parameters
[in]ini1,fin1Delimiters for the first sequence argument to compare.
[in]ini2,fin2Delimiters for the second sequence argument to compare.
eqAn equality compare object.
C++14 Backports:
Full-ranges implementation of std::equal .
Returns
true if both ranges have equal elements.

Referenced by mismatch().

◆ equal() [2/2]

bool cxxomfort::cxxostd::equal ( RangeIt1  ini1,
RangeIt1  fin1,
RangeIt2  ini2,
RangeIt2  fin2 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ mismatch() [1/2]

std::pair<InputIt1, InputIt2> cxxomfort::cxxostd::mismatch ( InputIt1  ini1,
InputIt1  fin1,
InputIt2  ini2,
InputIt2  fin2,
BinaryPredicate  p 
)

Finds the first difference (dif1,dif2) between two sequences [ini1,fin1) and [ini2,fin2), given comparator eq . Four-iterator overload.

Parameters
pAn equality compare object.
C++14 Backports:
Full-ranges implementation of std::mismatch .

Referenced by is_permutation(), and mismatch().

◆ mismatch() [2/2]

std::pair<InputIt1, InputIt2> cxxomfort::cxxostd::mismatch ( InputIt1  ini1,
InputIt1  fin1,
InputIt2  ini2,
InputIt2  fin2 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ make_unique()

std::unique_ptr<T> cxxomfort::cxxostd::make_unique ( Args &&...  args)
inline

Creates a unique_ptr holding a constructed object.

C++14 Backports:
Create a unique_ptr holding a T constructed by the given arguments
Note
For compilers in pre-C++11 mode, the function can copy (forward) up to 6 arguments to the T constructor.

◆ get() [3/4]

T& cxxomfort::cxxostd::get ( std::tuple< TupleArgs... > &  )

Return a member of a tuple given its type as a template argument.

C++14 Backports:
Get a tuple element by type, as per get< type >(std::tuple&& sometuple)
Template Parameters
Ta type, such that it exists in the type pack TupleArgs... .
Precondition
The type T exists in TupleArgs

Given a std::tuple type with component types TupleArgs... , the new C++14 overload of std::get() is provided that gives access to the element of type T in the tuple, assuming there is one element in TupleArgs with type T .

tuple<int, string, float> tu (...);
get<string>(tu); // gets get<1>(tu), which is the std::string member
get<bool>(tu); // does not compile, no bool type in tu
Note
This functionality is backported mostly to C++03 compatible compilers with high template support. The macro CXXOMFORT_IMPLEMENTS_tuple_get_type notifies if this function can be enabled.

◆ get() [4/4]

T const& cxxomfort::cxxostd::get ( std::tuple< TupleArgs... > const &  )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ as_const()

constexpr std::add_const< T >::type& cxxomfort::cxxostd::as_const ( T &  t)
inlinenoexcept

returns a const view of object t . A C++17 Backports .

Returns
A reference to its argument with const qualifier added.
See also
{n4380}
<utility>:

Referenced by as_ptr_const().

◆ as_ptr_const()

constexpr std::add_const< T >::type* cxxomfort::cxxostd::as_ptr_const ( T *const  t)
inlinenoexcept

returns a const view of a pointer t . An extension to as_const() .

Returns
A pointer to a const view of the argument.
C++17 Backports:
"Type Utilities" as_const
<utility>:
See also
{p1011r0} , as_const()

◆ to_integer()

Integral cxxomfort::cxxostd::to_integer ( byte  b)

Converts the byte value into an Integral .

C++17 Backports:
Converts a byte to an integral value.
Converts a byte value to an Integral type.

◆ clamp() [1/2]

constexpr T const & clamp ( T const &  val,
T const &  lo,
T const &  hi,
Compare  comp 
)

Clamps a value.

Returns
An altered value from val to fit into the open interval (lo , hi ).
C++17 Backports:
Clamps a value val within a range
See also
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4536.html
Note
Behaviour is undefined if hi < lo.
Pre-C++14, constexpr functions can not perform assert or throw checks in their code. As such in C++11, while clamp() is constexpr it has no precondition checks.

Referenced by clamp(), and cxxomfort::fix::clamp().

◆ clamp() [2/2]

CXXO_CONSTEXPR T const& cxxomfort::cxxostd::clamp ( T const &  val,
T const &  lo,
T const &  hi 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ invoke()

dependent_type_t cxxomfort::cxxostd::invoke ( F &&  callable,
Args &&...  args 
)

Invokes a callable. See also invoke_r() .

C++17 Backports:
Invokes callables via callable( args... ), accounting for eg.: member-pointer callables.
<functional>:
Invokes callables via callable( args... ), accounting for eg.: member-pointer callables.
See also
utility/functional/invoke @ cppreference
invoke_r()
is_invocable

invoke() calls a functionlike or callable f with the given arguments args... , taking care of forwarding, member function pointers, etc.

invoke(f, 1, 2, 3, ...) is in general equivalent to f(1, 2, 3, ...).

With member functions, invoke(C::*f, a, b, c, ...) is in general equivalent to a.*f(b, c, ...).

The invoke() feature is backported down to C++11 with full support, and down to C++03 with partial support. The macro CXXOMFORT_IMPLEMENTS_invoke informs about implementation status.

Note
In C++11 and C++14 mode, invoke() may not necessarily be constexpr .
Pre-C++11, invoke() is partially supported; in particular, invoke() is mostly / only supported for compilers that have CXXO_COMPILER_SUPPORT_typeof == true so return type deduction can be provided, and only supports object callables. Older compilers without typeof or any other similar measure should be using invoke_r() instead.
For pre-C++11 compilers without typeof, if invoke() is supported, invoke() only supports object-like callables. To use with eg.: member function pointers, wrap those in mem_fn(), std::function, etc.
Starting with C++11, enabling invoke() support will also set the SD6 macro __cpp_lib_invoke where necessary.

Referenced by apply(), bind_front(), and not_fn().

◆ invoke_r()

R cxxomfort::cxxostd::invoke_r ( F &&  callable,
Args &&...  args 
)

Invokes a callable and specifies a return type. See also invoke() .

C++23 Backports:
Invoke callables via (R)callable( args... ), specifying the return type.
<functional>:
Invoke callables via (R)callable( args... ), specifying the return type.
See also
utility/functional/invoke @ cppreference
invoke()
is_invocable

invoke_r() calls a functionlike or callable f with the given arguments args... , taking care of forwarding, member function pointers, and implicitly converts the resulting value to type R during return.

invoke_r<R>(f, 1, 2, 3, ...) is in general equivalent to static_cast<R>(f(1, 2, 3, ...)).

The invoke_r() feature is backported down to C++11 with full support, and down to C++98 with partial support. Unlike invoke() which requires type deduction for return, invoke_r() can be used even in compilers that lack typeof . The macro CXXOMFORT_IMPLEMENTS_invoke_r informs about implementation status.

Note
In C++11 and C++14 mode, invoke_r() may not necessarily be constexpr .
Pre-C++11, invoke_r() only supports object-like callables. To use with eg.: member function pointers, wrap those in mem_fn(), std::function, etc.

◆ size() [1/2]

C::size_type cxxomfort::cxxostd::size ( C &  c)
inline

Returns the size (number of elements) of a sequence / container expression.

C++17 Backports:
Invokes c.size() or an equivalent construct for a sequence.

Referenced by array< T, N >::at(), cxxomfort::at_or(), and cxxomfort::atindex_or().

◆ data() [1/3]

constexpr auto cxxomfort::cxxostd::data ( C &  container) -> decltype(container.data())

provides access to an internal "<code>.data()</code>" member.

C++17 Backports:
Invoked c.data() or a similar construct for contiguous-storage sequences.

data(c) invokes c.data() for container for which it exists. The result type is assumed to be a pointer type or equivalent that provides direct access to a contiguous storage.

Warning
For C++ pre-C++11, this relies on the container type declaring this pointer type as the member types pointer and const_pointer.

◆ data() [2/3]

bool cxxomfort::cxxostd::data ( C const &  container)

provides access to an internal "<code>.empty()</code>" member.

C++17 Backports:
"Iterators" empty

empty(c) invokes c.empty() for container for which it exists. The result type is assumed to be a bool .

Warning
For C++ pre-C++11, this relies on the container type declaring a value_type member type.

◆ empty()

bool cxxomfort::cxxostd::empty ( C const &  c)

Accesses and returns the .empty() member of the container.

Returns
A bool, equal to calling .empty() on the container.

Referenced by data().

◆ size() [2/2]

size_t cxxomfort::cxxostd::size ( C const &  c)

Accesses and returns the .size() member of the container.

Returns
A numeric type, equal to calling .size() on the container.

◆ data() [3/3]

C::pointer cxxomfort::cxxostd::data ( C const &  c)

Accesses and returns the .data() member of the container.

Returns
A pointer, likely of type {containertype}::pointer .

Referenced by data().

◆ make_from_tuple()

T cxxomfort::cxxostd::make_from_tuple ( std::tuple< TupleArgs... > &&  Tuple)

Create an object from a tuple expression.

C++17 Backports:
Constructs an object of type T using the tuple's elements for the constructor.
Returns
An object of type T , constructed via a constructor call using a tuple as arguments.
See also
 utility/make_from_tuple @ cppreference

The call make_from_tuple<T>( footuple ) is equivalent to the call T (get<0>(footuple), get<1>(footuple), get<2>(footuple), ...).

◆ apply()

implementation_defined_t cxxomfort::cxxostd::apply ( f,
Tuple &  t 
)

Applies the tuple t as the arguments to the functionlike / callable f .

Parameters
fA callable / function-like argument.
tA std::tuple or similar construct.
C++17 Backports:
Invokes a callable f using the elements of the tuple t as arguments.
Returns
Whatever f(t...) returns.
See also
utility/apply @ cppreference

Example usage:

auto logdata= make_tuple("Handle %x code %u with result %s", 0x10, 300, "Hello World");
invoke(printf, logdata);
// prints:
// "Handle 0x10 code 300 with result Hello World"

Referenced by bind_front().

◆ bind_front()

implementation_defined_t cxxomfort::cxxostd::bind_front ( Fn &&  callable,
Binds &&...  args 
)

Wraps a function and its first n arguments in a callable object.

Parameters
argsA sequence of arguments that are bound to the callable.
C++20 Backports:
Wraps a function and its first n arguments as a callable.
See also
utility/functional/bind_front @ cppreference

Given a callable object or function fn taking n arguments and a sequence args of at most n arguments, bind_front(fn,args...) returns a callable object wf of undetermined type that wraps fn and args such as at a later point of use the invocation wf(call_args...), fn is invoked via invoke() with the lists of arguments args and call_args in sequence.

In other words, bind_front() functions exactly like bind() except that it only binds the first few arguments.

auto wf = bind_front(fn, a1, a2, a3);
wf(b1, b2); // calls fn(a1, a2, a3, b1, b2);
Note
This feature from C++20 is backported down to at most C++11.

◆ not_fn()

not_fn_t<Fn> cxxomfort::cxxostd::not_fn ( Fn &&  f)

Creates a function wrapper that returns the negation of a given function-like / callable.

Parameters
fA function-like callable with operator().
Returns
A function object wrapper nf of undetermined type such that nf(args...) == !(f(args...)).
C++17 Backports:
not_fn() from Fundamentals v2: a generic functor negator.
See also
utility/functional/not_fn @ cppreference

The macro CXXOMFORT_IMPLEMENTS_not_fn informs about the implementation status. Additionally in C++>=11 mode, cxxomfort sets the macro __cpp_lib_not_fn if this facility is backported.

Note
In C++03 mode, this wrapper can take function-likes of up to 5 arguments.
In C++03 mode, this wrapper can only take named ("l-value") arguments.

◆ destroy_at()

void cxxomfort::cxxostd::destroy_at ( T *  p)

Destructs an object, as if the destructor was invoked via Type::~Type().

<memory>:
See also
{p0040r2}
<memory>:
See also
{p0040r2}

Referenced by destroy(), destroy_n(), and uninitialized_default_construct_n().

◆ destroy()

void cxxomfort::cxxostd::destroy ( Iter  ini,
Iter2  fin 
)

◆ destroy_n()

void cxxomfort::cxxostd::destroy_n ( Iter  ini,
Integer  n 
)

◆ uninitialized_default_construct()

void cxxomfort::cxxostd::uninitialized_default_construct ( It  ini,
It  fin 
)

Default-constructs objects in uninitialized memory.

<memory>:
Exceptions
<tt>bad_alloc</tt>.
See also
{p0040r0} .

◆ uninitialized_default_construct_n()

void cxxomfort::cxxostd::uninitialized_default_construct_n ( It  ini,
Integer  n 
)

Default-constructs objects in uninitialized memory.

<memory>:
Exceptions
<tt>bad_alloc</tt>.
See also
{p0040r0} .

◆ quoted() [1/2]

implementation_defined_t cxxomfort::cxxostd::quoted ( Char const *  str,
Char  delim = '\"',
Char  escape = '\ 
)
inline

Outputs a string to a stream, quoted.

C++14 Backports:
Inserts a string into a stream, quoted.
See also
io/manip/quoted @ cppreference

◆ quoted() [2/2]

implementation_defined_t cxxomfort::cxxostd::quoted ( std::basic_string_view< Char >  str,
Char  delim = '\"',
Char  escape = '\ 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ make_reverse_iterator()

CXXO_CONSTEXPR14 std::reverse_iterator<It> cxxomfort::cxxostd::make_reverse_iterator ( It  i)

Constructs the reverse_iterator for a given iterator.

C++14 Backports:
"Iterators" make_reverse_iterator
See also
iterator/make_reverse_iterator @ cppreference

◆ iota()

FwIt cxxomfort::cxxostd::iota ( FwIt  ini,
FwIt  fin,
i0 
)

Fills a sequence with a sequentially growing set of values. "Numeric" iota.

Given the sequence [ini, fin), iota assigns the values i0, i0+1, i0+2, ... to the elements of the sequence until it has been filled.

Precondition
The range [ini, fin) is valid and writable.
See also
cppref{algoritm/iota}

◆ iota_n()

FwIt cxxomfort::cxxostd::iota_n ( FwIt  ini,
Integer  n,
i0 
)

Fills a sequence with a sequentially growing set of values.

Given the sequence starting at ini , iota assigns the values i0, i0+1, i0+2, ... to the n elements of the sequence until the n -th element has been reached.

Precondition
The range [ini, ini+n) is valid and writable.
See also
cppref{algoritm/iota}

◆ gcd()

CXXO_CONSTEXPR Num1 cxxomfort::cxxostd::gcd ( Num1  n1,
Num2  n2 
)

Calculates the greatest common divisor.

C++17 Backports:
"Numeric" gcd
Returns
A numeric value of type Num1 . Compare also: lcm
See also
numeric/gcd @ cppreference
Note
As a backport, the return type is the same as the first argument.

Referenced by lcm().

◆ lcm()

CXXO_CONSTEXPR Num1 cxxomfort::cxxostd::lcm ( Num1  n1,
Num2  n2 
)

Calculates the lowest common multiple.

C++17 Backports:
"Numeric" lcm
Returns
A numeric value of type Num1 . Compare also: gcd
See also
numeric/lcm @ cppreference

◆ midpoint() [1/2]

CXXO_CONSTEXPR Numeric cxxomfort::cxxostd::midpoint ( Numeric  n1,
Numeric  n2 
)
inline

Returns the midpoint between two numeric values, avoiding overflows.

Returns
(n1 + n2)/2, avoiding overflows.
See also
{P0811R3}

Referenced by midpoint().

◆ midpoint() [2/2]

Pointer cxxomfort::cxxostd::midpoint ( Pointer  p1,
Pointer  p2 
)

Returns the midpoint between two pointers.

Template Parameters
TA pointer type (not a member pointer type).
Returns
A pointer p half the distance away from p1 in the direction towards p2 .
See also
{P0811R3}
Precondition
Pointer is a pointer type-
Note
Because operating on pointers, results are undefined if taking the difference between pointers is undefined (for example, for pointers pointing to elements in different arrays, or in different memory regions).

◆ declval()

T& cxxomfort::cxxostd::declval ( )

Expression for an unevaluated context. "Type Utilities" declval.

<utility>:
declval