![]() |
General Utility Library for C++14
2.7
|
Namespace gul14 contains all functions and classes of the General Utility Library.
Classes | |
class | ConvertingStringView |
A string view that can automatically convert numbers into strings. More... | |
class | FinalAction |
FinalAction allows us to execute something if the FinalAction object leaves the scope. More... | |
class | HexdumpParameterForward |
Helper object used to enable a convenient syntax to dump things to a stream. More... | |
class | optional |
A class template that can either contain a value of a certain type or not. More... | |
class | optional< T & > |
A class template that can either contain a value of a certain type or not. More... | |
class | SlidingBuffer |
A circular data buffer of (semi-)fixed capacity to which elements can be added at the front or at the back. More... | |
class | SlidingBufferExposed |
A variant of SlidingBuffer that exposes the underlying container through its iterator interface. More... | |
class | SmallVector |
A resizable container with contiguous storage that can hold a specified number of elements without allocating memory on the heap. More... | |
class | span |
A view to a contiguous sequence of objects. More... | |
struct | MinMax |
Object that is designed to holds two values: minimum and maximum of something. More... | |
class | StandardDeviationMean |
A struct holding a standard deviation and a mean value. More... | |
class | basic_string_view |
A view to a contiguous sequence of chars or char-like objects. More... | |
struct | IsContainerLike |
Helper type trait object to determine if a type is a container. More... | |
class | Trigger |
A class that allows sending triggers and waiting for them across different threads. More... | |
class | FailToInstantiate |
A helper class to debug types. More... | |
Typedefs | |
template<typename T > | |
using | BitFunctionReturnType = std::enable_if_t< std::is_integral< T >::value and not std::is_same< std::decay_t< T >, bool >::value, std::decay_t< T > > |
Return type of the bit manipulation functions. More... | |
using | statistics_result_type = double |
Type used to return statistic properties. | |
using | string_view = basic_string_view< char > |
A view to a contiguous sequence of chars. More... | |
using | u16string_view = basic_string_view< char16_t > |
A view to a contiguous sequence of char16_ts. More... | |
using | u32string_view = basic_string_view< char32_t > |
A view to a contiguous sequence of char32_ts. More... | |
using | wstring_view = basic_string_view< wchar_t > |
A view to a contiguous sequence of wchar_ts. More... | |
Enumerations | |
enum class | ShrinkBehavior { keep_front_elements , keep_back_elements } |
Determine how a SlidingBuffer handles decreases of its size. More... | |
Functions | |
template<typename T = unsigned, typename ReturnT = BitFunctionReturnType<T>> | |
constexpr auto | bit_set (unsigned bit) noexcept -> ReturnT |
Set a bit in an integral type. More... | |
template<typename T , typename ReturnT = BitFunctionReturnType<T>> | |
constexpr auto | bit_set (T previous, unsigned bit) noexcept -> ReturnT |
Set a bit in an integral value. More... | |
template<typename T , typename ReturnT = BitFunctionReturnType<T>> | |
constexpr auto | bit_reset (T previous, unsigned bit) noexcept -> ReturnT |
Reset a bit in an integral value. More... | |
template<typename T , typename ReturnT = BitFunctionReturnType<T>> | |
constexpr auto | bit_flip (T previous, unsigned bit) noexcept -> ReturnT |
Flip a bit in an integral value. More... | |
template<typename T > | |
constexpr bool | bit_test (T bits, unsigned bit) noexcept |
Test a bit in an integral value. More... | |
constexpr char | lowercase_ascii (char c) noexcept |
Return the ASCII lowercase equivalent of the given character (or the unchanged character, if it is not an ASCII letter). More... | |
GUL_EXPORT std::string | lowercase_ascii (gul14::string_view str) |
Return a copy of the given string in which all ASCII characters are replaced by their lowercase equivalents. More... | |
GUL_EXPORT std::string & | lowercase_ascii_inplace (std::string &str) noexcept |
Replace all ASCII characters in a string by their lowercase equivalents. More... | |
constexpr char | uppercase_ascii (char c) noexcept |
Return the ASCII uppercase equivalent of the given character (or the unchanged character, if it is not an ASCII letter). More... | |
GUL_EXPORT std::string | uppercase_ascii (gul14::string_view str) |
Return a copy of the given string in which all ASCII characters are replaced by their uppercase equivalents. More... | |
GUL_EXPORT std::string & | uppercase_ascii_inplace (std::string &str) noexcept |
Replace all ASCII characters in a string by their uppercase equivalents. More... | |
std::string | cat () |
Efficiently concatenate an arbitrary number of strings and numbers. More... | |
std::string | cat (const ConvertingStringView &s) |
GUL_EXPORT std::string | cat (const ConvertingStringView &s1, const ConvertingStringView &s2) |
GUL_EXPORT std::string | cat (const ConvertingStringView &s1, const ConvertingStringView &s2, const ConvertingStringView &s3) |
GUL_EXPORT std::string | cat (std::initializer_list< ConvertingStringView > pieces) |
template<typename... Args, typename = std::enable_if_t<(sizeof...(Args) > 3)>> | |
std::string | cat (const Args &... args) |
GUL_EXPORT std::string | escape (string_view in) |
Create a new string that looks like an ASCII-only C string literal of the input string. More... | |
GUL_EXPORT std::string | unescape (string_view in) |
Evaluate a string with escaped characters to get the original string back. More... | |
template<typename F > | |
FinalAction< typename std::decay_t< F > > | finally (F &&f) noexcept |
finally() - convenience function to generate a FinalAction More... | |
template<typename IntTypeA , typename IntTypeB > | |
constexpr auto | gcd (IntTypeA a, IntTypeB b) |
Calculate the greatest common divisor of two integers using the Euclidean algorithm. More... | |
template<typename IntTypeA , typename IntTypeB > | |
constexpr auto | lcm (IntTypeA a, IntTypeB b) |
Calculate the least common multiple of two integers. More... | |
template<typename IteratorT , typename = std::enable_if_t<detail::IsHexDumpIterator<IteratorT>::value>> | |
std::string | hexdump (IteratorT begin, IteratorT end, string_view prompt="") |
Generate a hexdump of a data range and return it as a string. More... | |
template<typename ContainerT , typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value>> | |
std::string | hexdump (const ContainerT &cont, string_view prompt="") |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename = std::enable_if_t<detail::IsHexDumpIterator<IteratorT>::value>> | |
HexdumpParameterForward< const IteratorT > | hexdump_stream (const IteratorT &begin, const IteratorT &end, std::string prompt="") |
Generate a hexdump of a data range that can be efficiently written to a stream using operator<<. More... | |
template<typename ContainerT , typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value>> | |
HexdumpParameterForward< const decltype(std::declval< ContainerT >).cbegin())> | hexdump_stream (const ContainerT &cont, std::string prompt="") |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename ContainerT , typename = std::enable_if_t<detail::IsHexDumpContainer<ContainerT>::value, decltype(HexdumpParameterForward<decltype(std::declval<ContainerT>().cbegin()), ContainerT> {}, 0)>> | |
HexdumpParameterForward< decltype(std::declval< ContainerT >).cbegin()), ContainerT > | hexdump_stream (ContainerT &&cont, std::string prompt="") |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename StringContainer = std::vector<std::string>, typename ContainerInsertFct = void (*)(StringContainer&, string_view)> | |
StringContainer | split (string_view text, string_view delimiter, ContainerInsertFct insert_fct=detail::emplace_back< StringContainer >) |
Separate a string at all occurrences of a delimiter, returning the strings between the delimiters in a container. More... | |
template<typename StringContainer = std::vector<std::string>, typename ContainerInsertFct = void (*)(StringContainer&, string_view)> | |
StringContainer | split (string_view text, const std::regex &delimiter, ContainerInsertFct insert_fct=detail::emplace_back< StringContainer >) |
Separate a string at all occurrences of a delimiter described by a regular expression, returning the strings between the delimiters in a container. More... | |
template<typename StringContainer = std::vector<string_view>, typename ContainerInsertFct = void (*)(StringContainer&, string_view)> | |
StringContainer | split_sv (string_view text, string_view delimiter, ContainerInsertFct insert_fct=detail::emplace_back< StringContainer >) |
Separate a string at all occurrences of a delimiter, returning the strings between the delimiters in a vector. More... | |
template<typename StringContainer > | |
std::string | join (const StringContainer &parts, string_view glue) |
Concatenate all strings in a range, placing a delimiter between them. More... | |
template<typename Iterator > | |
std::string | join (Iterator begin, Iterator end, string_view glue) |
Concatenate all strings in a range, placing a delimiter between them. More... | |
template<typename ValueT > | |
constexpr auto | abs (ValueT n) noexcept -> std::enable_if_t< std::is_unsigned< ValueT >::value, ValueT > |
Compute the absolute value of a number. More... | |
template<typename NumT , typename OrderT , typename = std::enable_if_t< std::is_arithmetic<NumT>::value and std::is_arithmetic<OrderT>::value >> | |
bool | within_orders (const NumT a, const NumT b, const OrderT orders) noexcept(false) |
Determine if two numbers are almost equal, comparing only some significant digits. More... | |
template<typename NumT > | |
bool | within_abs (NumT a, NumT b, NumT tol) noexcept |
Determine if two numbers are almost equal, allowing for an absolute difference. More... | |
template<typename NumT , typename = std::enable_if_t<std::is_floating_point<NumT>::value>> | |
bool | within_ulp (NumT a, NumT b, unsigned int ulp) |
Determine if two numbers are almost equal, allowing for a difference of a given number of units-in-the-last-place (ULPs). More... | |
template<class NumT > | |
constexpr const NumT & | clamp (const NumT &v, const NumT &lo, const NumT &hi) |
Coerce a value to be within a given range. More... | |
template<class NumT , class Compare > | |
constexpr const NumT & | clamp (const NumT &v, const NumT &lo, const NumT &hi, Compare comp) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
GUL_EXPORT std::string | replace (string_view haystack, string_view needle, string_view hammer) |
Replace all occurrences of a string within another string, returning the result as a std::string. More... | |
GUL_EXPORT std::string & | replace_inplace (std::string &haystack, string_view needle, string_view hammer) |
Replace all occurrences of a string within another string in-place. More... | |
template<typename ElementT , size_t in_capacity> | |
void | swap (SmallVector< ElementT, in_capacity > &a, SmallVector< ElementT, in_capacity > &b) |
Exchange the contents of one SmallVector with those of another one. More... | |
template<typename ElementType , std::size_t Extent> | |
span< const unsigned char,((Extent==dynamic_extent) ? dynamic_extent :sizeof(ElementType) *Extent)> | as_bytes (span< ElementType, Extent > s) noexcept |
Return a constant view to the byte representation of the elements of a given span. More... | |
template<class ElementType , size_t Extent, typename std::enable_if<!std::is_const< ElementType >::value, int >::type = 0> | |
span< unsigned char,((Extent==dynamic_extent) ? dynamic_extent :sizeof(ElementType) *Extent)> | as_writable_bytes (span< ElementType, Extent > s) noexcept |
Return a writable view to the byte representation of the elements of a given span. More... | |
template<std::size_t N, typename E , std::size_t S> | |
constexpr auto | get (span< E, S > s) -> decltype(s[N]) |
Return a reference to the Nth element of a given span. More... | |
template<typename ElementT > | |
auto | ElementAccessor () |
Return a mock element accessor for containers. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | mean (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
Calculate the arithmetic mean value of all elements in a container. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | rms (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
Calculate the root mean square of all elements in a container. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | median (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
Find the median of all elements in a container. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | maximum (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> DataT |
Return the maximum element value in a container. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | minimum (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> DataT |
Return the minimum element value in a container. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | min_max (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> MinMax< DataT > |
Find the minimum and maximum element values in a container. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | remove_outliers (ContainerT &&cont, std::size_t outliers, Accessor accessor=ElementAccessor< ElementT >()) -> ContainerT & |
Remove elements that are far away from other elements. More... | |
template<typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | remove_outliers (ContainerT const &cont, std::size_t outliers, Accessor accessor=ElementAccessor< ElementT >()) -> std::vector< ElementT > |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The original container is not modified. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | standard_deviation (ContainerT const &container, Accessor accessor=ElementAccessor< ElementT >()) -> StandardDeviationMean< ResultT > |
Calculate the standard deviation of all elements in a container. More... | |
template<typename ResultT = statistics_result_type, typename ContainerT , typename ElementT = typename ContainerT::value_type, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = typename std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename OpClosure , typename = std::enable_if_t<IsContainerLike<ContainerT>::value>> | |
auto | accumulate (ContainerT const &container, OpClosure op, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
Calculate some aggregate value from all elements of a container. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | mean (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | rms (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | median (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | maximum (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> DataT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | minimum (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> DataT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | min_max (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> MinMax< DataT > |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | remove_outliers (IteratorT const &begin, IteratorT const &end, std::size_t outliers, Accessor accessor=ElementAccessor< ElementT >()) -> std::vector< ElementT > |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The original container is not modified. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>> | |
auto | standard_deviation (IteratorT const &begin, IteratorT const &end, Accessor accessor=ElementAccessor< ElementT >()) -> StandardDeviationMean< ResultT > |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename ResultT = statistics_result_type, typename IteratorT , typename ElementT = std::decay_t<decltype(*std::declval<IteratorT>())>, typename Accessor = std::result_of_t<decltype(ElementAccessor<ElementT>())(ElementT)>(*)(ElementT const&), typename DataT = std::decay_t<std::result_of_t<Accessor(ElementT)>>, typename OpClosure > | |
auto | accumulate (IteratorT const &begin, IteratorT const &end, OpClosure op, Accessor accessor=ElementAccessor< ElementT >()) -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename Integer , std::enable_if_t< std::is_integral< Integer >::value, bool > = true> | |
std::string | hex_string (Integer v) |
Return the hexadecimal ASCII representation of an integer value. More... | |
template<typename Iterator > | |
std::string | hex_string (Iterator begin, Iterator end, string_view separator="") |
Return the hexadecimal ASCII representation of a range of integer values. More... | |
template<typename Integer , size_t num_elements, std::enable_if_t< std::is_integral< Integer >::value, bool > = true> | |
std::string | hex_string (const Integer(&array)[num_elements], string_view separator="") |
Return the hexadecimal ASCII representation of an array with integer values. More... | |
template<typename Container , std::enable_if_t< IsContainerLike< Container >::value, bool > = true> | |
std::string | hex_string (const Container &container, string_view separator="") |
Return the hexadecimal ASCII representation of a container with integer values. More... | |
GUL_EXPORT std::string | repeat (gul14::string_view str, std::size_t n) |
Repeat a string N times. More... | |
GUL_EXPORT std::string | safe_string (const char *char_ptr, std::size_t length) |
Safely construct a std::string from a char pointer and a length. More... | |
constexpr bool | contains (string_view haystack, string_view needle) noexcept |
Determine whether a string contains another string. More... | |
constexpr bool | contains (string_view haystack, char needle) noexcept |
Determine whether a string contains a certain character. More... | |
constexpr bool | ends_with (string_view str, string_view suffix) noexcept |
Determine whether a string ends with another string. More... | |
constexpr bool | ends_with (string_view str, char c) noexcept |
Determine whether a string ends with a certain character. More... | |
constexpr bool | starts_with (string_view str, string_view prefix) noexcept |
Determine whether a string starts with another string. More... | |
constexpr bool | starts_with (string_view str, char c) noexcept |
Determine whether a string starts with a certain character. More... | |
constexpr bool | equals_nocase (string_view str1, string_view str2) noexcept |
Determine whether a string is equal to another one, making no distinction between upper and lower case ASCII characters. More... | |
constexpr bool | contains_nocase (string_view haystack, string_view needle) noexcept |
Determine whether a string contains another string. More... | |
constexpr bool | contains_nocase (string_view haystack, char needle) noexcept |
Determine whether a string contains a certain character. More... | |
constexpr bool | ends_with_nocase (string_view str, string_view suffix) noexcept |
Determine whether a string ends with another string. More... | |
constexpr bool | ends_with_nocase (string_view str, char c) noexcept |
Determine whether a string ends with a certain character. More... | |
constexpr bool | starts_with_nocase (string_view str, string_view prefix) noexcept |
Determine whether a string starts with another string. More... | |
constexpr bool | starts_with_nocase (string_view str, char c) noexcept |
Determine whether a string starts with a certain character. More... | |
std::chrono::steady_clock::time_point | tic () |
Return the current time as a std::chrono time_point. More... | |
template<class TimeUnitType = std::chrono::duration<double>> | |
auto | toc (std::chrono::steady_clock::time_point t0) |
Return the elapsed time in seconds (or a different unit) since the given time point. More... | |
template<class Rep , class Period > | |
bool | sleep (const std::chrono::duration< Rep, Period > &duration, const Trigger &trg) |
Sleep for at least the given time span, with the option of being woken up from another thread. More... | |
bool | sleep (double seconds, const Trigger &trg) |
Sleep for a given number of seconds, with the option of being woken up from another thread. More... | |
template<class Rep , class Period > | |
bool | sleep (const std::chrono::duration< Rep, Period > &duration) |
Sleep for a given time span. More... | |
bool | sleep (double seconds) |
Sleep for a given number of seconds. More... | |
template<typename NumberType , std::enable_if_t< std::is_integral< NumberType >::value &&std::is_unsigned< NumberType >::value, int > = 0> | |
constexpr optional< NumberType > | to_number (gul14::string_view str) noexcept |
Convert an ASCII string_view into a number. More... | |
template<typename StringContainer = std::vector<std::string>, typename ContainerInsertFct = void (*)(StringContainer&, string_view)> | |
StringContainer | tokenize (string_view str, string_view delimiters=default_whitespace_characters, ContainerInsertFct insert_fct=detail::emplace_back< StringContainer >) |
Split the given string into a vector of substrings (tokens) delimited by any of the characters in the delimiters string. More... | |
template<typename StringContainer = std::vector<string_view>, typename ContainerInsertFct = void (*)(StringContainer&, string_view)> | |
StringContainer | tokenize_sv (string_view str, string_view delimiters=default_whitespace_characters, ContainerInsertFct insert_fct=detail::emplace_back< StringContainer >) |
Split the given string into a vector of substrings (tokens) delimited by any of the characters in the delimiters string. More... | |
GUL_EXPORT std::string | trim (string_view str, string_view ws_chars=default_whitespace_characters) |
Trim leading and trailing whitespace (or a custom set of characters) from a string, returning a new std::string. More... | |
GUL_EXPORT string_view | trim_sv (string_view str, string_view ws_chars=default_whitespace_characters) |
Trim leading and trailing whitespace (or a custom set of characters) from a string, returning a view into the original string. More... | |
GUL_EXPORT std::string | trim_left (string_view str, string_view ws_chars=default_whitespace_characters) |
Trim leading whitespace (or a custom set of characters) from a string, returning a new std::string. More... | |
GUL_EXPORT string_view | trim_left_sv (string_view str, string_view ws_chars=default_whitespace_characters) |
Trim leading whitespace (or a custom set of characters) from a string, returning a view into the original string. More... | |
GUL_EXPORT std::string | trim_right (string_view str, string_view ws_chars=default_whitespace_characters) |
Trim trailing whitespace (or a custom set of characters) from a string, returning a new std::string. More... | |
GUL_EXPORT string_view | trim_right_sv (string_view str, string_view ws_chars=default_whitespace_characters) |
Trim trailing whitespace (or a custom set of characters) from a string, returning a view into the original string. More... | |
template<class T > | |
constexpr string_view | type_name () |
Generate a human readable string describing a type. More... | |
Variables | |
GUL_EXPORT const string_view | default_whitespace_characters { " \t\r\n\a\b\f\v" } |
The default characters that are treated as whitespace by GUL. More... | |
GUL_EXPORT const std::array< char, 16 > | hex_digits |
The 16 digits for hexadecimal numbers ("0123456789abcdef"). More... | |
GUL_EXPORT char const * | version_git |
Holds the git version tag of the sources that the library has been build with. More... | |
GUL_EXPORT char const * | version_api |
Holds the API version of the library. | |
using gul14::BitFunctionReturnType = typedef std::enable_if_t< std::is_integral<T>::value and not std::is_same<std::decay_t<T>, bool>::value, std::decay_t<T> > |
Return type of the bit manipulation functions.
We want to SFINAE out of all types except integers. Because bools counts as integer type and we don't want that we specifically exclude it here.
The type is then simply the decayed input type, to get rid of const or volatile specifiers.
T | Type specified/deduced by bit_*() user |
using gul14::string_view = typedef basic_string_view<char> |
A view to a contiguous sequence of chars.
This is a backport of std::string_view from libc++ for C++17.
using gul14::u16string_view = typedef basic_string_view<char16_t> |
A view to a contiguous sequence of char16_ts.
This is a backport of std::string_view from libc++ for C++17.
using gul14::u32string_view = typedef basic_string_view<char32_t> |
A view to a contiguous sequence of char32_ts.
This is a backport of std::string_view from libc++ for C++17.
using gul14::wstring_view = typedef basic_string_view<wchar_t> |
A view to a contiguous sequence of wchar_ts.
This is a backport of std::string_view from libc++ for C++17.
|
strong |
Determine how a SlidingBuffer handles decreases of its size.
When the buffer's capacity decreases below the actual size some elements have to be dropped. The user can choose between two strategies:
ShrinkBehavior::keep_front_elements
)ShrinkBehavior::keep_back_elements
)Usually the more recent data shall be preserved, while older data can be dropped.
The behavior is utilized by SlidingBuffer::resize(), SlidingBuffer::reserve(), SlidingBufferExposed::resize(), and SlidingBufferExposed::reserve().
|
constexprnoexcept |
Compute the absolute value of a number.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This function is almost equal to std::abs() with the exception of unsigned integral types, which are returned unchanged and in their original type. This is especially useful in templates, where std::abs() cannot be used for all arithmetic types.
n | The number whose absolute value should be determined. |
Referenced by gcd(), lcm(), remove_outliers(), within_abs(), within_orders(), and within_ulp().
auto gul14::accumulate | ( | ContainerT const & | container, |
OpClosure | op, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
Calculate some aggregate value from all elements of a container.
This is similar to std::accumulate, but
op
to a running sum and each element value,container | Container of the elements to examine |
op | Binary operator to aggregate two values into one value |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result value / accumulator |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References accumulate().
auto gul14::accumulate | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
OpClosure | op, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
op | Binary operator to aggregate two values into one value |
accessor | Helper function to access the numeric value of one container element |
Referenced by accumulate(), maximum(), mean(), min_max(), minimum(), rms(), and standard_deviation().
|
noexcept |
Return a constant view to the byte representation of the elements of a given span.
This is a backport from the C++20 standard library, see: https://en.cppreference.com/w/cpp/container/span/as_bytes
References gul14::span< ElementType, Extent >::data(), and gul14::span< ElementType, Extent >::size_bytes().
|
noexcept |
Return a writable view to the byte representation of the elements of a given span.
This is a backport from the C++20 standard library, see: https://en.cppreference.com/w/cpp/container/span/as_bytes
References gul14::span< ElementType, Extent >::data(), and gul14::span< ElementType, Extent >::size_bytes().
|
inlineconstexprnoexcept |
Flip a bit in an integral value.
Flips the bit number bit in the existing value previous. This inverts the state of the bit: setting the bit if it was previously not set and resetting the bit if it was previously set.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
previous | Existing integral value where the bit shall be modified |
bit | Number of the bit that is to be modified (LSB == 0) |
T | Type of the bit-holding integral value. |
|
inlineconstexprnoexcept |
Reset a bit in an integral value.
Reset (clear) the bit number bit in the existing value previous.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
previous | Existing integral value where the bit shall be modified |
bit | Number of the bit that is to be modified (LSB == 0) |
T | Type of the bit-holding integral value. |
|
inlineconstexprnoexcept |
Set a bit in an integral value.
Set the bit number bit in the existing value previous.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
previous | Existing integral value where the bit shall be modified |
bit | Number of the bit that is to be modified (LSB == 0) |
T | Type of the bit-holding integral value. |
|
inlineconstexprnoexcept |
Set a bit in an integral type.
Return an integral value of type T where the bit number bit and only that bit is set.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
bit | Number of the bit that is to be set (LSB == 0) |
T | Type of the bit-holding integral value. |
|
inlineconstexprnoexcept |
Test a bit in an integral value.
Test the bit number bit in the existing value bits.
When bit is greater or equal to the number of bits in type T, std::abort() is called (via assert()).
bits | Integral value where the bit shall be tested |
bit | Number of the bit that is to be modified (LSB == 0) |
T | Type of the bit-holding integral value. |
|
inline |
Efficiently concatenate an arbitrary number of strings and numbers.
Numbers are converted to strings in the same way as done by std::to_string. cat() reserves the correct amount of space before concatenating the strings and can therefore save several memory allocations compared to concatenation with "+".
Referenced by gul14::SlidingBuffer< ElementT, fixed_capacity, Container >::at(), gul14::SmallVector< ElementT, in_capacity >::at(), and cat().
|
inline |
|
inline |
std::string gul14::cat | ( | const ConvertingStringView & | s1, |
const ConvertingStringView & | s2 | ||
) |
References gul14::ConvertingStringView::data(), and gul14::ConvertingStringView::length().
std::string gul14::cat | ( | const ConvertingStringView & | s1, |
const ConvertingStringView & | s2, | ||
const ConvertingStringView & | s3 | ||
) |
References gul14::ConvertingStringView::data(), and gul14::ConvertingStringView::length().
std::string gul14::cat | ( | std::initializer_list< ConvertingStringView > | pieces | ) |
|
constexpr |
Coerce a value to be within a given range.
Check if value v
is between (including) lo
and hi
. If it is too low, lo
is returned. If it is too high, hi
is returned.
lo
must not be greater than hi
, but they are allowed to be equal.
Only operator<()
is used for this, so it has to be defined for NumT
.
Note that all parameters need to be of the same type. Add the correct suffix if using a literal as shown in the following example:
NumT | Type of the objects to compare. Needs to have operator<() defined. |
v | The value to clamp |
lo | The lower boundary to clamp v to |
hi | The upper boundary to clamp v to |
lo
if v
is less than lo
, a reference to hi
if hi
is less than v
, or a reference to v
otherwise.
|
constexpr |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
NumT | Type of the objects to compare. Needs to have operator<() defined. |
Compare | Type of the comparison function. See notes below. |
v | The value to clamp |
lo | The lower boundary to clamp v to |
hi | The upper boundary to clamp v to |
comp | Comparison function object which returns true if the first argument is less than the second. |
The signature of the comparison function should be equivalent to the following:
While the signature does not explicitly require passing the arguments by const reference, the function must not modify the objects passed to it and must be able to accept all values of type (possibly const) Type1
and Type2
regardless of value category. This means that neither Type1 &
nor Type1
are allowed unless a move is equivalent to a copy for Type1
. The types Type1
and Type2
must be such that an object of type T
can be implicitly converted to both of them.
|
inlineconstexprnoexcept |
Determine whether a string contains a certain character.
The comparison is case sensitive.
haystack | The string in which to search. |
needle | The character that should be searched for. |
haystack
contains at least one occurrence of needle
, false otherwise.
|
inlineconstexprnoexcept |
Determine whether a string contains another string.
The comparison is case sensitive. If the searched-for string is empty, the result is true.
haystack | The string in which to search. |
needle | The string that should be searched for. |
haystack
contains at least one occurrence of needle
, false otherwise.
|
inlineconstexprnoexcept |
Determine whether a string contains a certain character.
The comparison is case insensitive as far as ASCII characters are concerned (C locale).
haystack | The string in which to search. |
needle | The character that should be searched for. |
haystack
contains at least one occurrence of needle
, false otherwise.References lowercase_ascii().
|
inlineconstexprnoexcept |
Determine whether a string contains another string.
The comparison is case insensitive as far as ASCII characters are concerned (C locale). If the searched-for string is empty, the result is true.
haystack | The string in which to search. |
needle | The string that should be searched for. |
haystack
contains at least one occurrence of needle
, false otherwise.References lowercase_ascii().
auto gul14::ElementAccessor | ( | ) |
Return a mock element accessor for containers.
All functions in statistics.h access the elements of the containers they work on through accessor functions. If the container is simple, i.e. contains just the types we want to work on (like double of std::vector<double>) we can automate the generation of the accessor function, so that the user does not need to specify it.
ElementT | Type of the elements in the container |
|
inlineconstexprnoexcept |
Determine whether a string ends with a certain character.
The comparison is case sensitive.
str | The string to be tested. |
c | The character to be looked for at the end of str . |
str
ends with c
, false otherwise.
|
inlineconstexprnoexcept |
Determine whether a string ends with another string.
The comparison is case sensitive. If the searched-for suffix is empty, the result is true.
str | The full string to be tested. |
suffix | The suffix to be looked for at the end of str . |
str
ends with suffix
, false otherwise.
|
inlineconstexprnoexcept |
Determine whether a string ends with a certain character.
The comparison is case insensitive as far as ASCII characters are concerned (C locale).
str | The string to be tested. |
c | The character to be looked for at the end of str . |
str
ends with c
, false otherwise.References lowercase_ascii().
|
inlineconstexprnoexcept |
Determine whether a string ends with another string.
The comparison is case insensitive as far as ASCII characters are concerned (C locale). If the searched-for suffix is empty, the result is true.
str | The full string to be tested. |
suffix | The suffix to be looked for at the end of str . |
str
ends with suffix
, false otherwise.References lowercase_ascii().
|
inlineconstexprnoexcept |
Determine whether a string is equal to another one, making no distinction between upper and lower case ASCII characters.
In other terms, this function performs a case insensitive string comparison using the C locale.
str1,str2 | The two strings that should be compared. |
str1
and str2
are equal, or false otherwise.References lowercase_ascii().
GUL_EXPORT std::string gul14::escape | ( | string_view | in | ) |
Create a new string that looks like an ASCII-only C string literal of the input string.
This is achieved by replacing all non-printable and non-ASCII characters with a hex code escape in the form \x01
.
A few special cases are implemented to give more readable representations for very common control characters, and of course backslash and double quotes are escaped as well:
CR -> \r NL -> \n TAB -> \t \ -> \\ " -> \"
Output (assuming that the string literal was in Latin-1 encoding):
Zwei\tFl\xfcsse\nflie\xdfen ins Meer.
"\x200"
is invalid and not equal to " 0"
from the standard's point of view.in | The input string. |
|
noexcept |
finally() - convenience function to generate a FinalAction
A FinalAction can be used to add RAII like behavior for non RAII object or to do timing measurements. More information given in the FinalAction documentation.
F | The type of the closure/function to be called (normally autodeduced). |
f | The closure or pointer to function to be called on destruction. |
|
inlineconstexpr |
Calculate the greatest common divisor of two integers using the Euclidean algorithm.
If both numbers are zero, the function returns zero. Otherwise, the result is a positive integer.
std::common_type_t<IntTypeA, IntTypeB>
) that both inputs can implicitly be converted to. If either a, b, or the result can not be represented by that type, the result is undefined.std::gcd()
from C++17, the GUL14 version cannot be used with integers of different signedness. This avoids undefined behavior when mixing unsigned integers with negative signed values: References abs().
Referenced by lcm().
|
constexpr |
Return a reference to the Nth element of a given span.
This is a backport from the C++20 standard library, see: https://en.cppreference.com/w/cpp/container/span/get
|
inline |
Return the hexadecimal ASCII representation of a container with integer values.
The letters 'a' to 'f' are used in lowercase, and no separators are inserted between individual values.
container | Input container |
separator | A string that is inserted between the elements to separate them visually (empty by default) |
Container | must be a gul14::IsContainerLike class |
References hex_string().
|
inline |
Return the hexadecimal ASCII representation of an array with integer values.
The letters 'a' to 'f' are used in lowercase, and a user-defined separator can be inserted between individual values.
array | Input array |
separator | A string that is inserted between the elements to separate them visually (empty by default) |
Integer | must be an integral type. |
num_elements | is the number of array elements. |
References hex_string().
|
inline |
Return the hexadecimal ASCII representation of an integer value.
The letters 'a' to 'f' are used in lowercase, and the number of hex digits is twice the number of bytes in the input integer type.
v | Input value |
Integer | must be an integral type. |
References hex_digits.
Referenced by hex_string().
|
inline |
Return the hexadecimal ASCII representation of a range of integer values.
The letters 'a' to 'f' are used in lowercase, and a user-defined separator can be inserted between individual values.
begin | Iterator to the first element of the range |
end | Iterator past the last element of the range |
separator | A string that is inserted between the elements to separate them visually (empty by default) |
Iterator | must be a forward iterator. |
References hex_string().
std::string gul14::hexdump | ( | const ContainerT & | cont, |
string_view | prompt = "" |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
cont | Reference to the container whose contents should be dumped; the container must provide ForwardIterators for .cbegin() and .cend() |
prompt | (optional) String that prefixes the dump text |
References hexdump_stream().
std::string gul14::hexdump | ( | IteratorT | begin, |
IteratorT | end, | ||
string_view | prompt = "" |
||
) |
Generate a hexdump of a data range and return it as a string.
The elements of the data range must be of integral type. They are dumped as unsigned integer values with their native width: Chars as "00" to "ff", 16-bit integers as "0000" to "ffff", and so on. If the elements are of type char, also a textual representation of the printable characters is dumped. An optional prompt can be added in front of the hexdump.
deBug -> 000000: 74 65 73 74 0a 74 68 65 20 c3 84 20 77 65 73 74 test.the .. west 000010: 21 09 0d 0a !...
000000: 00000000 00000001 00000005 00000002 cff00001 00000002 00000005 000007cf
begin | ForwardIterator to the first data element to be dumped |
end | ForwardIterator past the last data element to be dumped |
prompt | (optional) String that prefixes the dump text |
References hexdump_stream().
HexdumpParameterForward<const decltype(std::declval<ContainerT>).cbegin())> gul14::hexdump_stream | ( | const ContainerT & | cont, |
std::string | prompt = "" |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
cont | Reference to the container to dump |
prompt | (optional) String that prefixes the dump text |
HexdumpParameterForward<const IteratorT> gul14::hexdump_stream | ( | const IteratorT & | begin, |
const IteratorT & | end, | ||
std::string | prompt = "" |
||
) |
Generate a hexdump of a data range that can be efficiently written to a stream using operator<<.
Where hexdump() writes all of its output into one monolithic string, hexdump_stream() returns a tiny helper object that can efficiently send its output to an output stream via operator<<. This means that the following two lines produce the exact same output, but the stream version uses less resources:
The elements of the data range must be of integral type. They are dumped as unsigned integer values with their native width: Chars as "00" to "ff", 16-bit integers as "0000" to "ffff", and so on. If the elements are of type char, also a textual representation of the printable characters is dumped. An optional prompt can be added in front of the hexdump.
debug -> 000000: 74 65 73 74 0a 74 68 65 20 c3 84 20 77 65 73 74 test.the .. west 000010: 21 09 0d 0a !...
000000: 00000000 00000001 00000005 00000002 cff00001 00000002 00000005 000007cf
begin | ForwardIterator to the first data to be dumped |
end | ForwardIterator past the last data element to be dumped |
prompt | (optional) String that prefixes the dump text |
HexdumpParameterForward<decltype(std::declval<ContainerT>).cbegin()), ContainerT> gul14::hexdump_stream | ( | ContainerT && | cont, |
std::string | prompt = "" |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
cont | Reference to the container to dump if is a temporary |
prompt | (optional) String that prefixes the dump text |
Referenced by hexdump().
|
inline |
Concatenate all strings in a range, placing a delimiter between them.
This algorithm iterates twice over the range in order to pre-allocate a string of the correct size.
This is the inverse function of split(). It is guaranteed that join(split(text, del), del) == text
(unless del is a std::regex object).
parts | A container holding strings or string views that are to be concatenated |
glue | String that is put between each element of parts |
StringContainer | A container type that holds strings, e.g. std::vector<std::string> or std::list<gul14::string_view>. The container must provide an STL-like forward iterator interface. The string type must support concatenation with std::string using operator+=. |
|
inline |
Concatenate all strings in a range, placing a delimiter between them.
This algorithm iterates twice over the range in order to pre-allocate a string of the correct size.
begin | Iterator pointing to the first string |
end | Iterator pointing past the last string |
glue | String that is put between each element of parts |
Iterator | A forward iterator type that dereferences to a string type. The string type must support concatenation with std::string using operator+=. |
|
inlineconstexpr |
Calculate the least common multiple of two integers.
If both numbers are zero, the function returns zero. Otherwise, the result is a positive integer.
std::common_type_t<IntTypeA, IntTypeB>
) that both inputs can implicitly be converted to. If either a, b, or the result can not be represented by that type, the result is undefined.std::lcm()
from C++17, the GUL14 version cannot be used with integers of different signedness. This avoids undefined behavior when mixing unsigned integers with negative signed values:
|
constexprnoexcept |
Return the ASCII lowercase equivalent of the given character (or the unchanged character, if it is not an ASCII letter).
c | The original character. |
Referenced by contains_nocase(), ends_with_nocase(), equals_nocase(), lowercase_ascii(), lowercase_ascii_inplace(), and starts_with_nocase().
std::string gul14::lowercase_ascii | ( | gul14::string_view | str | ) |
Return a copy of the given string in which all ASCII characters are replaced by their lowercase equivalents.
str | The original string. |
References lowercase_ascii().
|
noexcept |
Replace all ASCII characters in a string by their lowercase equivalents.
This function modifies the original string and returns a reference to it (which may be helpful for chaining function calls).
str | The string to be modified. |
References lowercase_ascii().
auto gul14::maximum | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> DataT |
Return the maximum element value in a container.
The value of each element is determined through the accessor function. The maximum value is returned. Its type (DataT, the return type of the accessor) must provide operator==()
and operator<=()
. If DataT supports not-a-number (NaN) values, such values are ignored. If the container is empty, the return value is NaN (if supported) or std::numeric_limits<DataT>::lowest()
.
Hint: If looking for an iterator to the maximum element instead of its value, use std::max_element()
from the STL algorithm collection.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element. |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References accumulate().
Referenced by within_orders().
auto gul14::maximum | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> DataT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
auto gul14::mean | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
Calculate the arithmetic mean value of all elements in a container.
The mean value is calculated by dividing the sum of all elements by the number of elements: mean -> sum 0..n-1 (element i) / n
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result (this is also the type used for holding the sum of all elements and for the division by the number of elements, so make sure it can hold numbers that are big enough) |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References accumulate().
auto gul14::mean | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
Referenced by remove_outliers().
auto gul14::median | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
Find the median of all elements in a container.
The median element is the element that has an equal number of elements higher and lower in value. If the container has an even number of elements there can be no 'middle' element. In this case the two 'middlemost' elements are taken and the arithmetic mean of the two is returned.
Because all elements need to be sorted, the function works with a temporary copy of the original container.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result value |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
auto gul14::median | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
auto gul14::min_max | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> MinMax<DataT> |
Find the minimum and maximum element values in a container.
The value of each element is determined through the accessor function. The minimum and the maximum of these values are returned. Their type (DataT, the return type of the accessor) must provide operator==(),
operator<=(), and
operator>=()`. If DataT supports not-a-number (NaN) values, such values are ignored. If the container is empty, the return values are NaN (if supported) or std::numeric_limits<DataT>::max()
for the minimum and std::numeric_limits<DataT>::lowest()
for the maximum.
This behaves like (symbolic code):
without constructing a temporary container and without the ownership problems that would arise from minmax_element usage on a temporary container.
Hint: If looking for iterators to the minimum and maximum element instead of their values, use std::minmax_element()
from the STL algorithm collection.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References accumulate().
auto gul14::min_max | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> MinMax<DataT> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
auto gul14::minimum | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> DataT |
Return the minimum element value in a container.
The value of each element is determined through the accessor function. The minimum value is returned. Its type (DataT, the return type of the accessor) must provide operator==()
and operator>=()
. If DataT supports not-a-number (NaN) values, such values are ignored. If the container is empty, the return value is NaN (if supported) or std::numeric_limits<DataT>::max()
.
Hint: If looking for an iterator to the minimum element instead of its value, use std::min_element()
from the STL algorithm collection.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element. |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References accumulate().
auto gul14::minimum | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> DataT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
auto gul14::remove_outliers | ( | ContainerT && | cont, |
std::size_t | outliers, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ContainerT& |
Remove elements that are far away from other elements.
The element whose value differs the most from the arithmetic mean of all elements is removed. This process is repeated if more than one outlier is to be removed; specifically, the mean is recalculated from the remaining elements.
The original container is modified. The container needs to be modifiable and have the erase()
member function.
cont | Container of the elements to examine |
outliers | How many outliers shall be removed |
accessor | Helper function to access the numeric value of one container element |
cont
after removal of outliers.ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
auto gul14::remove_outliers | ( | ContainerT const & | cont, |
std::size_t | outliers, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> std::vector<ElementT> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The original container is not modified.
A copy of the original container without the outlier elements is returned.
References remove_outliers().
auto gul14::remove_outliers | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
std::size_t | outliers, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> std::vector<ElementT> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The original container is not modified.
A copy of the original container with the outerlier elements removed is returned.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
outliers | How many outliers shall be removed |
accessor | Helper function to access the numeric value of one container element |
Referenced by remove_outliers().
std::string gul14::repeat | ( | gul14::string_view | str, |
std::size_t | n | ||
) |
Repeat a string N times.
str | String to be repeated |
n | Number of repetitions |
std::string gul14::replace | ( | string_view | haystack, |
string_view | needle, | ||
string_view | hammer | ||
) |
Replace all occurrences of a string within another string, returning the result as a std::string.
Specifically, replace all occurrences of needle within haystack by hammer.
haystack | The string in which search&replace should take place. |
needle | The string to be searched for. If this is an empty string, a copy of haystack is returned. |
hammer | The replacement string. |
std::string & gul14::replace_inplace | ( | std::string & | haystack, |
string_view | needle, | ||
string_view | hammer | ||
) |
Replace all occurrences of a string within another string in-place.
This function replaces all occurrences of needle within haystack by hammer and returns a reference to the modified haystack.
haystack | The string in which search&replace should take place. |
needle | The string to be searched for. If this is an empty string, haystack is not changed. |
hammer | The replacement string. |
auto gul14::rms | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
Calculate the root mean square of all elements in a container.
The rms value is calculated as the square root of the sum of all squared elements divided by the number of elements: rms -> sqrt (sum 0..n-1 (element i * element i) / n)
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result value |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References accumulate().
auto gul14::rms | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> ResultT |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
std::string gul14::safe_string | ( | const char * | char_ptr, |
std::size_t | length | ||
) |
Safely construct a std::string from a char pointer and a length.
If the pointer is null, an empty string is constructed. If there are no zero bytes in the input range, a string of length length
is constructed. Otherwise, the input string is treated as a C string and the first zero byte is treated as the end of the string.
char_ptr | Pointer to a C string, an unterminated string of at least the specified length, or null. |
length | Maximum length of the generated string. |
bool gul14::sleep | ( | const std::chrono::duration< Rep, Period > & | duration | ) |
Sleep for a given time span.
This is equivalent to a call of std::this_thread::sleep_for(), which means that control is handed back to the operating system's task scheduler. This may result in a somewhat bigger effective delay than expected, especially where very small sleep times are requested and the system load is high.
Example:
duration | Time span to wait, as a std::chrono::duration type. |
bool gul14::sleep | ( | const std::chrono::duration< Rep, Period > & | duration, |
const Trigger & | trg | ||
) |
Sleep for at least the given time span, with the option of being woken up from another thread.
The sleep can be interrupted from another thread via a shared Trigger object.
Calling sleep() may lead to a context switch of the operation system. Under heavy load or resource contention, this can produce a delay that is longer than expected.
duration | Time span to wait, as a std::chrono::duration type. |
trg | Reference to a SleepInterrupt object that can be used to interrupt the delay. If such an interruption occurs, false is returned. |
References gul14::Trigger::wait_for().
Referenced by sleep().
|
inline |
Sleep for a given number of seconds.
This is equivalent to a call of std::this_thread::sleep_for(), which means that control is handed back to the operating system's task scheduler. This may result in a somewhat bigger effective delay than expected, especially where very small sleep times are requested and the system load is high.
Example:
seconds | Seconds to wait. |
References sleep().
|
inline |
Sleep for a given number of seconds, with the option of being woken up from another thread.
The sleep can be interrupted from another thread via a shared Trigger object.
Calling sleep() may lead to a context switch of the operation system. Under heavy load or resource contention, this can produce a delay that is longer than expected.
seconds | Seconds to wait. |
trg | Reference to a SleepInterrupt object that can be used to interrupt the delay. If such an interruption occurs, false is returned. |
References sleep().
|
inline |
Separate a string at all occurrences of a delimiter described by a regular expression, returning the strings between the delimiters in a container.
This function is a variant of split(string_view, string_view, ContainerInsertFct) that accepts a std::regex object to describe the delimiter:
text | The string to be split |
delimiter | A std::regex object describing the delimiters |
insert_fct | Custom container inserter function |
|
inline |
Separate a string at all occurrences of a delimiter, returning the strings between the delimiters in a container.
The result has at least one element. If the delimiter is not present in the text, the whole text is returned. If there are consecutive delimiters, the collected string between them is the empty string. If the delimiter is directly at the end of the input, the collected string between the end of the input and the delimiter is again the empty string.
split() is the inverse function of join(). It is guaranteed that join(split(text, del), del) == text
.
This function returns a std::vector<std::string>
by default, but a compatible container for string/string_view types can be specified via a template parameter:
StringContainer | A container for strings or string_view-like types, e.g. std::vector<std::string> or std::list<gul14::string_view> |
ContainerInsertFct | Type for the insert_fct function parameter. |
text | The string to be split |
delimiter | The delimiting substring |
insert_fct | By default, split() calls the emplace_back() member function on the container to insert strings. This parameter may contain a different function pointer or object with the signature void f(StringContainer&, gul14::string_view) that is called instead. This can be useful for containers that do not provide emplace_back() or for other customizations. |
|
inline |
Separate a string at all occurrences of a delimiter, returning the strings between the delimiters in a vector.
This function is identical to split(string_view, string_view, ContainerInsertFct) except that it returns a std::vector of string_views instead of strings by default:
auto gul14::standard_deviation | ( | ContainerT const & | container, |
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> StandardDeviationMean<ResultT> |
Calculate the standard deviation of all elements in a container.
The corrected sample standard deviation is calculated: standard_deviation -> sqrt (sum 0..n-1 ((element i - mean) * (element i - mean)) / (n - 1))
The returned StandardDeviationMean object can be used like this:
If the container is empty, not-a-number is returned for both the standard deviation and the mean value. If it contains only a single element, not-a-number is returned for the standard deviation and the mean value is the value of the element.
container | Container of the elements to examine |
accessor | Helper function to access the numeric value of one container element |
ResultT | Type of the result value |
ContainerT | Type of the container to examine |
ElementT | Type of an element in the container, i.e. ContainerT::value_type |
Accessor | Type of the accessor function |
DataT | Type returned by the accessor, i.e. numeric value of ElementT |
References accumulate().
auto gul14::standard_deviation | ( | IteratorT const & | begin, |
IteratorT const & | end, | ||
Accessor | accessor = ElementAccessor<ElementT>() |
||
) | -> StandardDeviationMean<ResultT> |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
begin | Iterator to first elements to examine in the container |
end | Iterator past the last element to examine in the container |
accessor | Helper function to access the numeric value of one container element |
|
inlineconstexprnoexcept |
Determine whether a string starts with a certain character.
The comparison is case sensitive.
str | The string to be tested. |
c | The character to be looked for at the beginning of str . |
str
starts with c
, false otherwise.
|
inlineconstexprnoexcept |
Determine whether a string starts with another string.
The comparison is case sensitive. If the searched-for prefix is empty, the result is true.
str | The full string to be tested. |
prefix | The prefix to be looked for at the beginning of str . |
str
starts with prefix
, false otherwise.
|
inlineconstexprnoexcept |
Determine whether a string starts with a certain character.
The comparison is case insensitive as far as ASCII characters are concerned (C locale).
str | The string to be tested. |
c | The character to be looked for at the beginning of str . |
str
starts with c
, false otherwise.References lowercase_ascii().
|
inlineconstexprnoexcept |
Determine whether a string starts with another string.
The comparison is case insensitive as far as ASCII characters are concerned (C locale). If the searched-for prefix is empty, the result is true.
str | The full string to be tested. |
prefix | The prefix to be looked for at the beginning of str . |
str
starts with prefix
, false otherwise.References lowercase_ascii().
void gul14::swap | ( | SmallVector< ElementT, in_capacity > & | a, |
SmallVector< ElementT, in_capacity > & | b | ||
) |
Exchange the contents of one SmallVector with those of another one.
If either this or the other vector have internally stored elements (capacity() <= inner_capacity()), this function falls back to element-wise swapping. Otherwise, the heap-allocated buffers are swapped directly.
References gul14::SmallVector< ElementT, in_capacity >::swap().
|
inline |
Return the current time as a std::chrono time_point.
This function is intended to be used with the sister function toc() to measure elapsed time.
Referenced by toc().
|
inlineconstexprnoexcept |
Convert an ASCII string_view into a number.
This function parses the ASCII representation of a number (e.g. "123" or "1.3e10") into an optional integer or floating-point number.
to_number() shares many characteristics with std::atoi(), std::stod() and the like, but follows its own set of design goals:
The allowed number format depends on the chosen numeric output type.
Recognize additionally
The behavior with surrounding whitespace is undefined, so it should be removed before passing input to this function. This means to_number() accepts a subset of C++17's from_chars() input format; where it supports the input format it is modeled close to from_chars().
NumberType | Destination numeric type |
str | The string to be converted into a number. |
auto gul14::toc | ( | std::chrono::steady_clock::time_point | t0 | ) |
Return the elapsed time in seconds (or a different unit) since the given time point.
This function is intended to be used with the sister function tic() to measure elapsed time. toc() is a function template that returns the elapsed seconds as a double value by default; by specifying a different chrono
type as a template parameter, it can also return other time units and other types.
TimeUnitType | The type to be used for calculating the elapsed time since t0. By default, this is std::chrono::duration<double>, which means that the elapsed time is returned as a double that represents seconds. |
t0 | A time point in the past that should be taken with tic(). |
References tic().
|
inline |
Split the given string into a vector of substrings (tokens) delimited by any of the characters in the delimiters string.
Multiple adjacent delimiters are treated like a single one, and delimiters at the beginning and end of the string are ignored. For example, tokenize(" A B C ") yields a vector with the three entries "A", "B", and "C".
This function returns a std::vector<std::string>
by default, but a compatible container for string/string_view types can be specified via a template parameter:
StringContainer | A container for strings or string_view-like types, e.g. std::vector<std::string> or std::list<gul14::string_view> |
ContainerInsertFct | Type for the insert_fct function parameter. |
str | The string to be split. |
delimiters | String with delimiter characters. Any of the characters in this string marks the beginning/end of a token. By default, a wide variety of whitespace and control characters is used. |
insert_fct | By default, tokenize() calls the emplace_back() member function on the container to insert strings. This parameter may contain a different function pointer or object with the signature void f(StringContainer&, gul14::string_view) that is called instead. This can be useful for containers that do not provide emplace_back() or for other customizations. |
char
s. This can have surprising effects in code such as this:
|
inline |
Split the given string into a vector of substrings (tokens) delimited by any of the characters in the delimiters string.
This function is identical to tokenize(string_view, string_view, ContainerInsertFct) except that it returns a std::vector of string_views instead of strings by default:
std::string gul14::trim | ( | string_view | str, |
string_view | ws_chars = default_whitespace_characters |
||
) |
Trim leading and trailing whitespace (or a custom set of characters) from a string, returning a new std::string.
Which characters are removed can be customized via the ws_chars parameter.
str | The string that should be trimmed. |
ws_chars | A string containing all the characters that should be treated as whitespace (i.e. that are trimmed). If this is empty, no characters are trimmed. |
References trim_sv().
std::string gul14::trim_left | ( | string_view | str, |
string_view | ws_chars = default_whitespace_characters |
||
) |
Trim leading whitespace (or a custom set of characters) from a string, returning a new std::string.
Which characters are removed can be customized via the ws_chars parameter.
str | The string from which leading characters should be trimmed. |
ws_chars | A string containing all the characters that should be treated as whitespace (i.e. that are trimmed). If this is empty, no characters are trimmed. |
References trim_left_sv().
string_view gul14::trim_left_sv | ( | string_view | str, |
string_view | ws_chars = default_whitespace_characters |
||
) |
Trim leading whitespace (or a custom set of characters) from a string, returning a view into the original string.
Which characters are removed can be customized via the ws_chars parameter.
str | The string from which leading characters should be trimmed. |
ws_chars | A string containing all the characters that should be treated as whitespace (i.e. that are trimmed). If this is empty, no characters are trimmed. |
Referenced by trim_left().
std::string gul14::trim_right | ( | string_view | str, |
string_view | ws_chars = default_whitespace_characters |
||
) |
Trim trailing whitespace (or a custom set of characters) from a string, returning a new std::string.
Which characters are removed can be customized via the ws_chars parameter.
str | The string from which trailing characters should be trimmed. |
ws_chars | A string containing all the characters that should be treated as whitespace (i.e. that are trimmed). If this is empty, no characters are trimmed. |
References trim_right_sv().
string_view gul14::trim_right_sv | ( | string_view | str, |
string_view | ws_chars = default_whitespace_characters |
||
) |
Trim trailing whitespace (or a custom set of characters) from a string, returning a view into the original string.
Which characters are removed can be customized via the ws_chars parameter.
str | The string from which trailing characters should be trimmed. |
ws_chars | A string containing all the characters that should be treated as whitespace (i.e. that are trimmed). If this is empty, no characters are trimmed. |
Referenced by trim_right().
string_view gul14::trim_sv | ( | string_view | str, |
string_view | ws_chars = default_whitespace_characters |
||
) |
Trim leading and trailing whitespace (or a custom set of characters) from a string, returning a view into the original string.
Which characters are removed can be customized via the ws_chars parameter.
str | The string that should be trimmed. |
ws_chars | A string containing all the characters that should be treated as whitespace (i.e. that are trimmed). If this is empty, no characters are trimmed. |
Referenced by trim().
|
constexpr |
Generate a human readable string describing a type.
Cuts out the most relevant part of __PRETTY_FUNCTION__
of itself, ignoring all the stuff that contains information on the function itself, leaving just the description of the template parameter.
Note: __FUNCSIG__
with MSVC.
This function can only be constexpr if __PRETTY_FUNCTION__
is constexpr. This function is not constexpr with MSVC because of language limits.
Use like this:
T | Type that shall be described |
GUL_EXPORT std::string gul14::unescape | ( | string_view | in | ) |
Evaluate a string with escaped characters to get the original string back.
Does only know the escape sequences used by gul14::escape() and can be used as in inverse function.
in | The string with escape sequences |
|
constexprnoexcept |
Return the ASCII uppercase equivalent of the given character (or the unchanged character, if it is not an ASCII letter).
c | The original character. |
Referenced by uppercase_ascii(), and uppercase_ascii_inplace().
std::string gul14::uppercase_ascii | ( | gul14::string_view | str | ) |
Return a copy of the given string in which all ASCII characters are replaced by their uppercase equivalents.
str | The original string. |
References uppercase_ascii().
|
noexcept |
Replace all ASCII characters in a string by their uppercase equivalents.
This function modifies the original string and returns a reference to it (which may be helpful for chaining function calls).
str | The string to be modified. |
References uppercase_ascii().
|
noexcept |
Determine if two numbers are almost equal, allowing for an absolute difference.
All arguments must be the same numeric type (floating point or integer).
a | The first number to compare |
b | The second number to compare |
tol | The absolute tolerance |
References abs().
|
noexcept |
Determine if two numbers are almost equal, comparing only some significant digits.
The functions compares the specified number of significant decimal digits of the two values and returns true if they are equal within these digits.
a = 23736384; b = 23736228; within_orders(a, b, 5) => true (first 5 digits equal) a = 23736384; b = 23735384; within_orders(a, b, 5) => false (digit #5 differs)
Unexpected behavior can result when orders is low (< 3) as the simple concept of orders equals digits does not hold so strict anymore.
Remember that any nonzero number has infinite different significant digits compared with 0.00000000. So if one operand is 0.0 while the other is not 0.0 the result must be false.
a | The first number to compare |
b | The second number to compare (same type as a ) |
orders | The number of digits to take for comparison (any numeric type) |
a
and b
are equal or the difference between a
and b
is orders
orders of magnitude lower than the value of a
or b
bool gul14::within_ulp | ( | NumT | a, |
NumT | b, | ||
unsigned int | ulp | ||
) |
Determine if two numbers are almost equal, allowing for a difference of a given number of units-in-the-last-place (ULPs).
One ULP is the spacing between two consecutive floating point representations. There are no possible values in between. Roughly speaking, one ULP is for floating point numbers what the 1 is for integral numbers.
All arguments must be of the same floating point type.
a | The first number to compare |
b | The second number to compare |
ulp | Allowed number of floating point steps in between |
References abs().
const string_view gul14::default_whitespace_characters { " \t\r\n\a\b\f\v" } |
The default characters that are treated as whitespace by GUL.
This is a string view that contains the space and the most common control characters, namely (with their ASCII codes):
const std::array< char, 16 > gul14::hex_digits |
The 16 digits for hexadecimal numbers ("0123456789abcdef").
Referenced by hex_string().
|
extern |
Holds the git version tag of the sources that the library has been build with.
It has the format returned by git describe –tags –always –dirty