![]() |
BRICKS
Small, useful blocks of code, to build bigger things.
|
Classes | |
class | bad_result_access |
This is the type of the error thrown when accessing a bad result. More... | |
struct | deleter |
A deleter is a function that deletes a pointer. More... | |
struct | has_find |
Checks if a type has a find method taking a specific type. More... | |
struct | is_iterator |
Checks if a type is an iterator. More... | |
class | mutex |
A mutual exclusion primitive that can be used to protect shared data. More... | |
class | result |
A class to represent the result of an operation. More... | |
class | rw_lock |
A reader-writer lock. More... | |
class | timer |
A timer that can be started and aborted. More... | |
Typedefs | |
template<typename T , auto fn> | |
using | handle = std::unique_ptr<T, deleter<T, fn>> |
A handle is a unique_ptr with a custom deleter. | |
template<typename T > | |
using | ok = detail::value_container<T, detail::ok_tag> |
template<typename E > | |
using | err = detail::value_container<E, detail::err_tag> |
Functions | |
template<class Container > | |
auto | keys (const Container &input_map) -> std::vector< typename Container::key_type > |
Get the keys of an associative container. | |
template<class Container > | |
auto | values (const Container &input_map) -> std::vector< typename Container::mapped_type > |
Get the values of an associative container. | |
template<typename F , typename... FrontArgs> | |
constexpr auto | bind_front (F &&f, FrontArgs &&... front_args) |
Bind arguments to the front of a function. | |
template<class Container , class Value > | |
constexpr auto | contains (const Container &container, const Value &value) noexcept -> bool |
Checks whether a container contains a specific value. | |
template<class Container , class UnaryPredicate > | |
constexpr auto | contains_if (const Container &container, const UnaryPredicate &predicate) -> bool |
Checks if a container contains a value that satisfies a predicate. | |
template<class Container , class Value > | |
constexpr auto | index_of (const Container &container, const Value &value) noexcept -> std::optional< size_t > |
Get the index of the first occurence of a value in a container. | |
template<class Container , class UnaryPredicate > | |
constexpr auto | index_of_if (const Container &container, const UnaryPredicate &predicate) -> std::optional< size_t > |
Get the index of the first element in a container for which a predicate is true. | |
template<class T , class Rep , class Period > | |
auto | is_ready_after (const std::future< T > &future, const std::chrono::duration< Rep, Period > &timeout) noexcept -> bool |
Check whether a future is ready after a timeout. | |
template<class T , class Clock , class Duration > | |
auto | is_ready_at (const std::future< T > &future, const std::chrono::time_point< Clock, Duration > &timeout) noexcept -> bool |
Check whether a future is ready at a specific time. | |
template<typename T > | |
auto | to_string (const T &value, std::size_t buffer_size=(std::numeric_limits< T >::digits10+2)) noexcept -> result< std::string, std::errc > |
Exceptionlessly convert a number to a string. | |
template<typename T > | |
auto | from_string (const std::string_view &str) noexcept -> result< T, std::errc > |
Exceptionlessly convert a string to a number. | |
template<typename Range > | |
auto | enumerate (Range &range) |
Enumerate a range. | |
template<typename Range , typename UnaryPredicate > | |
auto | filter (Range &range, UnaryPredicate predicate) -> detail::filterer< Range, UnaryPredicate > |
Filter a range. | |
template<typename Range > | |
auto | reverse (Range &range) |
Create a reverse iterator from a range. | |
template<typename... Ranges> | |
auto | zip (Ranges &&... t) |
A zip iterator adapter. | |
Variables | |
template<class > | |
constexpr bool | always_false_v = false |
Helper variable template for static assertions. | |
template<typename T > | |
constexpr bool | is_iterator_v = is_iterator<T>::value |
Helper variable template to check if a type is an iterator. | |
using bricks::err = detail::value_container<E, detail::err_tag> |
using bricks::handle = std::unique_ptr<T, deleter<T, fn>> |
A handle is a unique_ptr with a custom deleter.
Example:
T | The type of the handle. |
fn | The deleter function. |
using bricks::ok = detail::value_container<T, detail::ok_tag> |
|
constexpr |
Bind arguments to the front of a function.
C++17 implementation of the C++20 std::bind_front(...)
function.
Example:
f | The function to bind front arguments to. |
front_args | The front arguments to bind. |
|
constexprnoexcept |
Checks whether a container contains a specific value.
If the container has a find
method, it will be used to check if the container contains the value. Otherwise, the container will be searched using std::find
. If std::find
is used, the container must have a begin
and end
method. If the container has a find
method, the container must have a key_type
type alias. If std::find
throws an exception, std::terminate
will be called.
Example:
Container | The type of the container. |
Value | The type of the value. |
container | The container. |
value | The value to check for. |
|
constexpr |
Checks if a container contains a value that satisfies a predicate.
Example:
Container | The type of the container. |
UnaryPredicate | The type of the predicate. |
container | The container. |
predicate | The predicate. |
auto bricks::enumerate | ( | Range & | range | ) |
Enumerate a range.
This function creates an iterator adapter that enumerates the values of a range. The range can be any type that has a begin and end function. Each element in the enumerator is a pair of the index and the value.
Example:
Range | The type of range to enumerate. |
range | The range to enumerate. |
auto bricks::filter | ( | Range & | range, |
UnaryPredicate | predicate ) -> detail::filterer<Range, UnaryPredicate> |
Filter a range.
This function creates an iterator adapter that filters the values of a range. The range can be any type that has a begin and end function. Each element in the iterator adapter is a value that satisfies the predicate.
Example:
range | The range to filter. |
predicate | The predicate to filter with. |
|
noexcept |
Exceptionlessly convert a string to a number.
This function is a wrapper around std::from_chars
and will return the same error codes. It, however, will return std::errc::invalid_argument
if the string contains characters that are not part of the number.
Example:
T | The type of number to convert. |
str | The string to convert. |
|
constexprnoexcept |
Get the index of the first occurence of a value in a container.
If the container has a find
method, it will be used to get the index of the value. Otherwise, the container will be searched using std::find
. If std::find
is used, the container must have a begin
and end
method. If the container has a find
method, the container must have a key_type
type alias. If std::find
throws an exception, std::terminate
will be called.
Example:
Container | The type of the container. |
Value | The type of value to search for. |
container | The container. |
value | The value to get the index of. |
|
constexpr |
Get the index of the first element in a container for which a predicate is true.
Example:
Container | The type of the container. |
UnaryPredicate | The type of the predicate. |
container | The container. |
predicate | The predicate. |
|
noexcept |
Check whether a future is ready after a timeout.
Example:
T | The type of the future. |
future | The future. |
timeout | The timeout. |
|
noexcept |
Check whether a future is ready at a specific time.
Example:
T | The type of the future. |
future | The future. |
timeout | The timeout. |
auto bricks::keys | ( | const Container & | input_map | ) | -> std::vector<typename Container::key_type> |
Get the keys of an associative container.
Example:
Container | The type of the container. |
input_map | The container. |
auto bricks::reverse | ( | Range & | range | ) |
Create a reverse iterator from a range.
This function creates a reverse iterator from a range. The range can be any type that has a rbegin and rend function.
Example:
Range | The type of range to reverse. |
range | The range to reverse. |
|
noexcept |
Exceptionlessly convert a number to a string.
This function is a wrapper around std::to_chars
and will return the same error codes.
Example:
T | The type of number to convert. |
value | The number to convert. |
buffer_size | The size of the buffer to use for the conversion. If the buffer is too small the conversion will fail with std::errc::value_too_large . Can be omitted if the type is an integral type. |
auto bricks::values | ( | const Container & | input_map | ) | -> std::vector<typename Container::mapped_type> |
Get the values of an associative container.
Example:
Container | The type of the container. |
input_map | The container. |
auto bricks::zip | ( | Ranges &&... | t | ) |
A zip iterator adapter.
This iterator allows to iterate over multiple containers at the same time. It is similar to the zip function in python. The iterator will iterate over the shortest container. The iterator will dereference to a tuple of references to the elements of the containers.
Example:
|
inlineconstexpr |
Helper variable template for static assertions.
|
inlineconstexpr |
Helper variable template to check if a type is an iterator.
Example:
T |