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

Fixes for implementation issues in std. More...

Classes

struct  integral_limits
 An extension to numeric_limits that deals specifically with integer-like types. More...
 
struct  is_contiguous_access_iterator
 Tags an iterator as a contiguous access type iterator. More...
 
struct  malloc_deleter
 Deleter operator that uses free() for malloc-reserved blocks. More...
 
struct  shuffle_order_engine
 Forwarder for std::shuffle_order_engine. More...
 

Typedefs

typedef shuffle_order_engine< minstd_rand, 256 > knuth_b
 Forwarder for the std::knuth_b specialization of shuffle_order_engine .See shuffle_order_engine above.
 

Functions

template<typename T >
constexpr T clamp (cxxomfort::constexpr_t, T x, T Min, T Max) noexcept
 
template<typename It , typename T >
constexpr It find (cxxomfort::constexpr_t const, It ini, It fin, T const &value)
 
template<typename It , typename Fn >
constexpr It find_if (cxxomfort::constexpr_t const, It ini, It fin, Fn &&fn)
 
template<typename It , typename T >
constexpr size_t count (cxxomfort::constexpr_t const, It ini, It fin, T const &value) noexcept
 
template<typename It , typename Fn >
constexpr size_t count_if (cxxomfort::constexpr_t const, It ini, It fin, Fn &&fn) noexcept
 
template<typename Integral >
constexpr std::byte to_byte (Integral i) noexcept
 Constructs a std::byte using an integral value. More...
 
template<typename T >
auto cdata (C const &container) -> decltype(container.data())
 Returns container.data() as a const-pointer for a given container. More...
 
template<typename It , typename = typename std::enable_if<std::is_pointer<It>::value, bool>>
constexpr It static_next (It const p) noexcept
 Given a compile-time const (or constexpr ) iterator, returns the iterator to the next position.
 
template<typename It , typename = typename std::enable_if<std::is_pointer<It>::value, bool>>
constexpr It static_prev (It const p) noexcept
 Given a compile-time const (or constexpr ) iterator, returns the iterator to the previous position. More...
 
template<typename T >
bool to_bool (std::shared_ptr< T > const &p) noexcept
 
template<typename T >
bool to_bool (std::unique_ptr< T > const &p) noexcept
 
template<class Ty , Ty u>
CXXO_CONSTEXPR Ty to_integer (std::integral_constant< Ty, u > const) CXXO_NOEXCEPTNOTHROW
 Returns the value corresponding to a integral_constant.-utils Recovers the value corresponding to a integral_constant. More...
 
template<class Ty , Ty u>
CXXO_CONSTEXPR Ty to_value (std::integral_constant< Ty, u > const) CXXO_NOEXCEPTNOTHROW
 Returns the value corresponding to a integral_constant. More...
 

Detailed Description

Fixes for implementation issues in std.

Namespace that holds fixes and alternative implementations or names for stuff in C++ std that can not be modified or reimplemented.

See "Implementation Fixes" for more details.


Class Documentation

◆ cxxomfort::fix::integral_limits

struct cxxomfort::fix::integral_limits

template<typename T>
struct cxxomfort::fix::integral_limits< T >

An extension to numeric_limits that deals specifically with integer-like types.

Compile-time constants for integral limits

For a given integral or integer-like type Ty , integral_limits<Ty> provides an interface to std::numeric_limits<Ty> and in fact inherits from the latter. The interface is expanded to add some useful information about the integral type that is only available at compile time as macros pre-C++11.

integral_limits provides the following new members:

  • const_min - minimum value as a value (min is constexpr function in C++>=11).
  • const_max - maximum value as a value (max is constexpr function in C++>=11).
  • digits_base<N> - the total number of digits required to represent any value in the given base.

Pending members :

  • narrower_type - an alias to the next smaller integral type of the same signedness.
  • wider_type - an alias to the next larger integral type of the same signedness.
  • lo_mask - an integral value that can be AND-ed with this type to keep only the lower bits.
  • hi_mask - an integral value that can be AND-ed with this type to keep only the higher bits.

cxxomfort provides specializations of the new integral_limits for all the types that are defined as integral. The list explicitly includes:

short, int, long, long long in their signed and unsigned variants.

◆ cxxomfort::fix::is_contiguous_access_iterator

struct cxxomfort::fix::is_contiguous_access_iterator

template<typename Iterator, typename Tag = typename std::iterator_traits<Iterator>::iterator_category>
struct cxxomfort::fix::is_contiguous_access_iterator< Iterator, Tag >

Tags an iterator as a contiguous access type iterator.

Given an iterator type I, indicates whether the type either:

  • matches the contiguous_iterator_tag tag
  • or represents access to a contiguous area of memory, like an array

Pre C++17, this can only be implemented as an heuristic and can not determine contiguousness of storage types where the iterator is being wrapped, in which cases it will always declare false .

One such example is <array> and <vector> iterators in MSVC, in versions that don't support disabling the debug iterator mode.

◆ cxxomfort::fix::shuffle_order_engine

struct cxxomfort::fix::shuffle_order_engine

template<typename Engine, unsigned K>
struct cxxomfort::fix::shuffle_order_engine< Engine, K >

Forwarder for std::shuffle_order_engine.

<random>:
Forwarder.

Some compilers, such as MSVC 2008, 2010, don't implement shuffle_order_engine , and some other compilers don't implement it at all. This name will redirect to cxxomfort's implementation in those cases, or to std::shuffle_order_engine otherwise.

Function Documentation

◆ clamp()

constexpr T cxxomfort::fix::clamp ( cxxomfort::constexpr_t  ,
x,
Min,
Max 
)
inlinenoexcept

Implementation of std::clamp with constexpr

Referenced by cxxomfort::library::algorithm::is_clamped().

◆ find()

constexpr It cxxomfort::fix::find ( cxxomfort::constexpr_t  const,
It  ini,
It  fin,
T const &  value 
)
C++20 Backports:
Adding constexpr capability to std::find()

Adds an "overload" to std::find() so that pre-C++20 can invoke it in constexpr in contexts where the compiler makes it possible.

constexpr int Data[N] = { ...};
constexpr int const* p = find( cxxomfort::constexpr_tag, Data, Data+N, 9);
Note
This is defined only starting with C++11.

Referenced by basic_string_view< Ch, ChT >::find(), find_if(), and cxxomfort::cxxostd::is_permutation().

◆ find_if()

constexpr It cxxomfort::fix::find_if ( cxxomfort::constexpr_t  const,
It  ini,
It  fin,
Fn &&  fn 
)
C++20 Backports:
Adding constexpr capability to std::find_if()

Adds an "overload" to std::find_if() so that pre-C++20 can invoke it in constexpr in contexts where the compiler makes it possible.

Note
This is defined only starting with C++11.

◆ count()

constexpr size_t cxxomfort::fix::count ( cxxomfort::constexpr_t  const,
It  ini,
It  fin,
T const &  value 
)
noexcept
C++20 Backports:
Adding constexpr capability to std::count()

Adds an "overload" to std::count() so that pre-C++20 can invoke it in constexpr in contexts where the compiler makes it possible.

constexpr int Data[N] = { ...};
constexpr int const* p = count( cxxomfort::constexpr_tag, Data, Data+N, 9);
Note
This is defined only starting with C++11.

◆ count_if()

constexpr size_t cxxomfort::fix::count_if ( cxxomfort::constexpr_t  const,
It  ini,
It  fin,
Fn &&  fn 
)
noexcept
C++20 Backports:
Adding constexpr capability to std::count_if()

Adds an "overload" to std::count_if() so that pre-C++20 can invoke it in constexpr in contexts where the compiler makes it possible.

Note
This is defined only starting with C++11.

◆ to_byte()

constexpr std::byte cxxomfort::fix::to_byte ( Integral  i)
noexcept

Constructs a std::byte using an integral value.

Precondition
Integral is a C++ integral type.
Converts an integral value to byte .Create byte values.

Referenced by to_byte().

◆ cdata()

auto cxxomfort::fix::cdata ( C const &  container) -> decltype(container.data())

Returns container.data() as a const-pointer for a given container.

Parameters
containerA container or expression representing one.
Returns
An iterator of the type of container.data(); pre-C++11, a Container::const_pointer .
Precondition
The argument implements the .data() member with the required semantics (contiguous storage).
cdata()

◆ static_prev()

constexpr It cxxomfort::fix::static_prev ( It const  p)
noexcept

Given a compile-time const (or constexpr ) iterator, returns the iterator to the previous position.

static_prev

◆ to_bool() [1/2]

bool cxxomfort::fix::to_bool ( std::shared_ptr< T > const &  p)
inlinenoexcept

Returns true if the shared_ptr currently hosts a value.

Referenced by to_value().

◆ to_bool() [2/2]

bool cxxomfort::fix::to_bool ( std::unique_ptr< T > const &  p)
inlinenoexcept

Returns true if the unique_ptr currently hosts a value.

◆ to_integer()

CXXO_CONSTEXPR Ty cxxomfort::fix::to_integer ( std::integral_constant< Ty, u >  const)
inline

Returns the value corresponding to a integral_constant.-utils Recovers the value corresponding to a integral_constant.

This function is a helper for versions of C++ pre-C++14 which introduced the integral_constant conversion operator and function call.

See also
types/integral_constant @ cppreference

◆ to_value()

CXXO_CONSTEXPR Ty cxxomfort::fix::to_value ( std::integral_constant< Ty, u >  const)
inline

Returns the value corresponding to a integral_constant.

Value corresponding to a integral_constant.

This function is a helper for versions of C++ pre-C++14 which introduced the integral_constant conversion operator and function call.

See also
types/integral_constant @ cppreference