mimic++ v9.2.1
Loading...
Searching...
No Matches
mimicpp::util Namespace Reference

Namespaces

namespace  stacktrace
 

Classes

struct  always_false
 
struct  pass_key
 A helper type that enables fine-grained access control to specific functions without using friend declarations. More...
 
struct  priority_tag
 
struct  priority_tag< 0u >
 
class  SourceLocation
 A thin wrapper around general source-location info. More...
 
class  Stacktrace
 A simple type-erased stacktrace abstraction. More...
 
class  StaticString
 
class  StaticString< Char, 0u >
 
struct  type_list
 A very basic type-list template. More...
 
struct  type_list_index_of
 
struct  type_list_index_of< type_list< First, Elements... >, T >
 
struct  type_list_index_of< type_list< T, Elements... >, T >
 
struct  type_list_pop_back
 
struct  type_list_populate
 
struct  type_list_populate< Template, type_list< Args... > >
 
struct  type_list_reverse
 

Concepts

concept  explicitly_convertible_to
 Determines, whether From can be explicitly converted to To.
 
concept  nothrow_explicitly_convertible_to
 Determines, whether From can be explicitly converted to To, without throwing.
 
concept  same_as_any
 Determines, whether T is the same as any type of the pack Others.
 
concept  satisfies
 Determines, whether T satisfies the specified trait type.
 
concept  boolean_testable
 Determines, whether B behaves as a the builtin type bool.
 
concept  weakly_equality_comparable_with
 Determines, whether T can be equality compared with U.
 

Typedefs

template<std::indirectly_readable I, std::indirectly_regular_unary_invocable< I > Projection>
using projected_value_t
 The alias template projected_value_t obtains the value type by stripping any reference and its topmost cv-qualifiers of the result type of applying Proj to std::iter_value_t<I>&.
 
template<typename TypeList>
using type_list_reverse_t = typename type_list_reverse<TypeList>::type
 
template<typename TypeList>
using type_list_pop_back_t = typename type_list_pop_back<TypeList>::type
 
template<template< typename... > typename Template, typename TypeList>
using type_list_populate_t = typename type_list_populate<Template, TypeList>::type
 

Functions

template<std::ranges::random_access_range Target, std::ranges::random_access_range Control, typename Projection = std::identity, std::indirect_unary_predicate< std::projected< std::ranges::iterator_t< Control >, Projection > > Predicate>
requires std::ranges::sized_range<Target> && std::ranges::sized_range<Control>
constexpr std::ranges::borrowed_subrange_t< Target > partition_by (Target &&targetRange, Control &&controlRange, Predicate predicate, Projection projection={})
 Partitions the target range by the predicate results on the control range.
 
template<std::ranges::borrowed_range Range>
constexpr std::ranges::borrowed_iterator_t< Range > find_closing_token (Range &&str, std::ranges::range_value_t< Range > const &openingToken, std::ranges::range_value_t< Range > const &closingToken)
 Finds the next closing token in the given string.
 
template<std::ranges::borrowed_range Range>
constexpr std::ranges::borrowed_subrange_t< Range > find_next_unwrapped_token (Range &&str, std::string_view const token, std::ranges::forward_range auto &&opening, std::ranges::forward_range auto &&closing)
 Finds the next unwrapped token in the given string.
 
template<std::ranges::forward_range Range, std::ranges::forward_range Prefix>
requires std::totally_ordered_with<std::ranges::range_value_t<Range>, Prefix>
constexpr std::ranges::borrowed_subrange_t< Range > prefix_range (Range &&range, Prefix &&prefix)
 Returns a view containing all elements, which start with the given prefix.
 
template<std::copyable T, std::size_t firstN, std::size_t secondN>
constexpr std::array< T, firstN+secondN > concat_arrays (std::array< T, firstN > const &first, std::array< T, secondN > const &second)
 Concatenates the given arrays by copying all elements into a new array.
 
template<std::copyable T, std::size_t firstN, typename... Others>
requires (... && std::same_as<T, std::ranges::range_value_t<Others>>) && (... && (0u <= std::tuple_size_v<Others>))
constexpr auto concat_arrays (std::array< T, firstN > const &first, Others const &... others)
 Concatenates the given arrays by copying all elements into a new array.
 
template<typename To, typename From>
std::enable_if_t< sizeof(To)==sizeof(From) &&std::is_trivially_copyable_v< From > &&std::is_trivially_copyable_v< To >, To > bit_cast (From const &src) noexcept
 
void unreachable ()
 Invokes undefined behavior.
 
template<typename T>
requires std::is_enum_v<T>
constexpr std::underlying_type_t< T > to_underlying (T const value) noexcept
 
template<typename Char, std::size_t length>
 StaticString (Char const(&)[length]) -> StaticString< Char, length - 1u >
 

Variables

constexpr detail::binary_find_fn binary_find {}
 Finds the specified value within the container and returns an iterator pointing to it. If the value is not found, it returns an iterator to the end of the container.
 
constexpr detail::contains_fn contains {}
 Determines, whether the specified value is contained in the given range.
 
template<typename TypeList, typename T>
constexpr std::size_t type_list_index_of_v = type_list_index_of<TypeList, T>::value
 

Typedef Documentation

◆ projected_value_t

template<std::indirectly_readable I, std::indirectly_regular_unary_invocable< I > Projection>
using mimicpp::util::projected_value_t
Initial value:
std::remove_cvref_t<
std::invoke_result_t<Projection&, std::iter_value_t<I>&>>

The alias template projected_value_t obtains the value type by stripping any reference and its topmost cv-qualifiers of the result type of applying Proj to std::iter_value_t<I>&.

Template Parameters
Ian indirectly readable type.
Projectionprojection applied to an lvalue reference to value type of I.
See also
https://en.cppreference.com/w/cpp/iterator/projected_value_t
Note
Implementation directly taken from https://en.cppreference.com/w/cpp/iterator/projected_value_t

◆ type_list_pop_back_t

template<typename TypeList>
using mimicpp::util::type_list_pop_back_t = typename type_list_pop_back<TypeList>::type

◆ type_list_populate_t

template<template< typename... > typename Template, typename TypeList>
using mimicpp::util::type_list_populate_t = typename type_list_populate<Template, TypeList>::type

◆ type_list_reverse_t

template<typename TypeList>
using mimicpp::util::type_list_reverse_t = typename type_list_reverse<TypeList>::type

Function Documentation

◆ bit_cast()

template<typename To, typename From>
std::enable_if_t< sizeof(To)==sizeof(From) &&std::is_trivially_copyable_v< From > &&std::is_trivially_copyable_v< To >, To > mimicpp::util::bit_cast ( From const & src)
noexcept

◆ concat_arrays() [1/2]

template<std::copyable T, std::size_t firstN, typename... Others>
requires (... && std::same_as<T, std::ranges::range_value_t<Others>>) && (... && (0u <= std::tuple_size_v<Others>))
auto mimicpp::util::concat_arrays ( std::array< T, firstN > const & first,
Others const &... others )
nodiscardconstexpr

Concatenates the given arrays by copying all elements into a new array.

Template Parameters
TThe element type.
firstNThe size of the first array.
OthersOther array types which share the same element-type.
Parameters
firstThe first array.
othersThe second array.
Returns
A newly constructed arrays with copied elements.
Here is the call graph for this function:

◆ concat_arrays() [2/2]

template<std::copyable T, std::size_t firstN, std::size_t secondN>
std::array< T, firstN+secondN > mimicpp::util::concat_arrays ( std::array< T, firstN > const & first,
std::array< T, secondN > const & second )
nodiscardconstexpr

Concatenates the given arrays by copying all elements into a new array.

Template Parameters
TThe element type.
firstNThe size of the first array.
secondNThe size of the second array.
Parameters
firstThe first array.
secondThe second array.
Returns
A newly constructed arrays with copied elements.
Here is the caller graph for this function:

◆ find_closing_token()

template<std::ranges::borrowed_range Range>
std::ranges::borrowed_iterator_t< Range > mimicpp::util::find_closing_token ( Range && str,
std::ranges::range_value_t< Range > const & openingToken,
std::ranges::range_value_t< Range > const & closingToken )
nodiscardconstexpr

Finds the next closing token in the given string.

Template Parameters
RangeThe string type.
Parameters
strThe string to operate on.
openingTokenThe symmetrical opening token.
closingTokenThe symmetrical closing token.
Returns
Returns the iterator to the next closing token, or std::ranges::end(str) if no such token exist.

This algorithm determines the first closing-token, for which no corresponding opening-token where found. E.g. for the input ()) an iterator to the second ) will be returned.

Note
The algorithm assumes, that the corresponding opening-token is not part of the string.

◆ find_next_unwrapped_token()

template<std::ranges::borrowed_range Range>
std::ranges::borrowed_subrange_t< Range > mimicpp::util::find_next_unwrapped_token ( Range && str,
std::string_view const token,
std::ranges::forward_range auto && opening,
std::ranges::forward_range auto && closing )
nodiscardconstexpr

Finds the next unwrapped token in the given string.

Template Parameters
RangeThe string type.
Parameters
strThe string to operate on.
tokenThe token to be found.
openingCharacter-range, which will be treated as wrapping start.
closingCharacter-range, which will be treated as wrapping end.
Returns
Returns a subview to the next unwrapped token, or std::ranges::borrowed_subrange_t<Range>{std::ranges::end(str),std::ranges::end(str)} if no such token exist.

This algorithm determines the first unwrapped token. Unwrapped means, that the token does not appear between elements of the opening- and closing-character-range. E.g. the input <t>t will return the second t when < and > are part of the opening- and closing-range.

◆ partition_by()

template<std::ranges::random_access_range Target, std::ranges::random_access_range Control, typename Projection = std::identity, std::indirect_unary_predicate< std::projected< std::ranges::iterator_t< Control >, Projection > > Predicate>
requires std::ranges::sized_range<Target> && std::ranges::sized_range<Control>
std::ranges::borrowed_subrange_t< Target > mimicpp::util::partition_by ( Target && targetRange,
Control && controlRange,
Predicate predicate,
Projection projection = {} )
nodiscardconstexpr

Partitions the target range by the predicate results on the control range.

Template Parameters
TargetThe target range.
ControlThe control range.
ProjectionThe projection type.
PredicateThe predicate type.
Parameters
targetRangeThe range to be partitioned.
controlRangeThe range, which controls the partition.
predicateThe predicate for the projected control-elements.
projectionThe projection into the control-elements.
Returns
A subrange to the elements for which the predicate returned false.

This algorithm partitions the target range by evaluating the associated elements of the control range. This means, that if the predicate evaluates the control-element to false, the associated target-element moves into the second half; otherwise it stays at its position. The association is simply index based => target[i] is associated with control[i].

Note
Due to std::vector<bool>::iterator (and other Proxy-Iterators) not satisfying std::permutable, this requirement is dropped. Nevertheless, the range must semantically still be permutable.
See also
https://stackoverflow.com/questions/63412623/should-c20-stdrangessort-not-need-to-support-stdvectorbool
Here is the caller graph for this function:

◆ prefix_range()

template<std::ranges::forward_range Range, std::ranges::forward_range Prefix>
requires std::totally_ordered_with<std::ranges::range_value_t<Range>, Prefix>
std::ranges::borrowed_subrange_t< Range > mimicpp::util::prefix_range ( Range && range,
Prefix && prefix )
nodiscardconstexpr

Returns a view containing all elements, which start with the given prefix.

Template Parameters
RangeThe range type, which holds elements comparable with Prefix.
PrefixThe prefix type.
Parameters
rangeThe range.
prefixThe prefix.
Returns
A subrange view to range.
Attention
The behaviour is undefined, when range is not sorted.

◆ StaticString()

template<typename Char, std::size_t length>
mimicpp::util::StaticString ( Char const (&)[length]) -> StaticString< Char, length - 1u >

◆ to_underlying()

template<typename T>
requires std::is_enum_v<T>
std::underlying_type_t< T > mimicpp::util::to_underlying ( T const value)
nodiscardconstexprnoexcept

◆ unreachable()

void mimicpp::util::unreachable ( )
inline

Invokes undefined behavior.

See also
https://en.cppreference.com/w/cpp/utility/unreachable
Note
Implementation directly taken from https://en.cppreference.com/w/cpp/utility/unreachable

Variable Documentation

◆ binary_find

detail::binary_find_fn mimicpp::util::binary_find {}
inlineconstexpr

Finds the specified value within the container and returns an iterator pointing to it. If the value is not found, it returns an iterator to the end of the container.

Returns
A borrowed iterator to the element (or end).

◆ contains

detail::contains_fn mimicpp::util::contains {}
inlineconstexpr

Determines, whether the specified value is contained in the given range.

Returns
Returns true, when the value is contained.
Note
This is a backport from c++23 std::ranges::contains.
See also
https://en.cppreference.com/w/cpp/algorithm/ranges/contains

◆ type_list_index_of_v

template<typename TypeList, typename T>
std::size_t mimicpp::util::type_list_index_of_v = type_list_index_of<TypeList, T>::value
inlineconstexpr