rll namespace

Contract-programming related functions and classes.

Main namespace for the rolly library.

Mimics the canceled C++20 contracts proposal.

introduction

Can be used to check preconditions, postconditions and invariants instead of default C-style assert:

  • rll::precondition - these are conditions that must be true before a function (or code segment) executes, in order for the code to work correctly. E.g., a bisection search will work only if the vector is sorted. Another: Converting to polar form will work only if the cartesian coordinates are valid. It's a good idea to document preconditions.
  • rll::postcondition - these are conditions that are true after a functions returns or at the end of a code segment. Document significant postconditions (i.e., ones that refer to the purpose of the code)
  • rll::invariant - these are conditions that is supposed to be true all the time (except for brief, well-defined intervals). E.g., one invariant would be that if the cartesian and polar flags are both true, then the cartesian and polar member variables must represent the same complex number. Another example: in the selection sort, the part of the vector we have already scanned is sorted. It's a good idea to document significant invariants.
Usage
#include <rll/contracts.h>

You can include contracts.h in your code as follows:

Examples

In first example we use precondition to ensure that second argument, passed to function is not zero:

auto divide(i32 a, i32 b) -> i32 {
  assert_precondition(b != 0, "Cannot divide by zero");
  return a / b;
}

In second example, we ensure that the integer is not overflowed after summing two numbers using postcondition:

auto add(i32 a, i32 b) -> i32 {
  auto sum = a + b;
  assert_postcondition(sum >= a and sum >= b, "Overflow");
  return sum;
}

In third example, we the standard stream is open for writing using invariant:

auto println(std::string_view message) -> void {
  assert_invariant(std::cout);
  std::cout << message << std::endl;
}

Namespaces

namespace comparators inline
namespace crypto
namespace detail
Contracts implementation details.
namespace io
IO-related functions and classes.
namespace literals inline
Inline namespace for literal operators.
namespace meta
Library meta information.
namespace net
namespace numbers
Number numeric constants.
namespace oslayer
Internal namespace for OS-agnostic wrapper functions and classes.
namespace rtti
Runtime type information-related functions and classes.
namespace serialization
Functions and types related to serialization and deserialization.

Classes

template <typename T, typename = std::enable_if_t<is_num_v<T>>>
struct angle
Newtype describing an angle.
class application_dirs
Class for getting location of system directories for a specific application.
class bad_optional_access
template <typename F, typename T, typename = std::enable_if_t<is_serializable<T, F>::value>>
class configuration_file
Configuration file that can be loaded and saved.
template <typename... Args>
struct const_overload_t
struct contract_violation
Contract violation data holder.
template <typename R, typename T, R(*)(T) F>
struct deleter
class dirs
template <std::size_t N>
struct fixed_string
Fixed size string class.
template <>
struct fixed_string<0>
template <typename T, typename... U>
struct is_any_of
template <typename T>
struct is_num
Type trait for checking if T is a number.
template <typename, typename, typename, typename = void>
struct is_partially_serializable
template <typename T, typename F, typename R>
struct is_partially_serializable<T, F, R, std::void_t<decltype(partial_serializer<T, F, R>::serialize), decltype(partial_serializer<T, F, R>::deserialize)>>
template <typename, typename, typename = void>
struct is_serializable
template <typename T, typename F>
struct is_serializable<T, F, std::void_t<decltype(serializer<T, F>::serialize), decltype(serializer<T, F>::deserialize)>>
class library
template <typename... Args>
struct non_const_overload_t
struct noncopyable
Disallows copy operations for a type.
struct nonmovable
Disallows move operations for a type.
struct nullopt_t
A tag type to represent an empty optional.
template <typename T>
class observer_ptr
A smart pointer that holds a pointer to a value, but does not own it.
template <class T>
class optional
template <class T>
class optional<T&>
template <typename... Args>
struct overload_t
template <typename T, typename F, typename R, typename C = char, typename = void>
struct partial_serializer
struct pin
Disallows copy and move operations for a type.
template <typename T>
struct plain_type
Remove all cv qualifiers, references and pointers from a type.
template <typename T = f32>
class point2d
A two-dimensional point tagged with a unit.
template <typename T>
class propagate_const
template <typename T>
struct remove_cvref
Remove all cv qualifiers, references and pointers from a type.
template <typename F, typename T, typename = std::enable_if_t<is_serializable<T, F>::value>>
class savefile
template <typename T, typename F, typename C = char, typename = void>
struct serializer
template <typename T>
struct singleton
Singleton pattern trait.
template <typename T = f32>
struct size2d
A two-dimensional size2d tagged with a unit.
struct source_location
Provides information about the location of the current source file.
class u128
128-bit unsigned integer.
class uuid
128-bit globally unique identifier (GUID).
template <typename T = f32>
struct vector2d
A two-dimensional vector tagged with a unit.
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
struct velocity
Newtype describing a velocity.
struct version

Concepts

template <typename T>
concept enum_
Concept that is true if T is an enum type.
template <typename T, typename Duration, typename TimePoint>
concept timed_lockable
Timed lockable concept.
template <typename T>
concept ptr
Pointer concept.
template <typename T>
concept standard_copyable_and_movable
Concept that is true if T is a standard copyable and movable type.
template <typename T>
concept lockable
Lockable concept.
template <typename T>
concept mutex
Mutex concept.
template <typename T>
concept smart_ptr
Smart pointer concept.
template <typename T, typename Duration, typename TimePoint>
concept timed_mutex
Timed mutex concept.
template <typename T>
concept num
Concept that is true if T is a number.
template <typename T, typename Duration, typename TimePoint>
concept shared_timed_mutex
Shared timed mutex concept.
template <typename T>
concept basic_lockable
Basic lockable concept.
template <typename T, typename Duration, typename TimePoint>
concept shared_timed_lockable
Shared timed lockable concept.
template <typename T>
concept shared_lockable
Shared lockable concept.
template <typename T>
concept ptr_like
Concept that is true if T is a pointer or smart pointer.
template <typename T>
concept c_ptr
Raw pointer concept.
template <typename T>
concept shared_mutex
Shared mutex concept.

Enums

enum class angle_unit: char { degrees, radians }
Measurement unit of the angle.
enum class comparators_option: std::uint8_t { exclude_prerelease, include_prerelease }
enum class contract_type: signed char { precondition, postcondition, invariant }
Type of contract.
enum class endian: signed int { little = 0, big = 1, native = little }
Endianness.
enum class prerelease: std::uint8_t { alpha = 0, beta = 1, rc = 2, none = 3 }
enum class saving_policy: u8 { autosave, explicit_ }
Determines the policy used for autosaving configuration files.
enum class velocity_unit: char { kmph = 0, mps = 1, kilometers_per_hour = kmph, meters_per_second = mps }
Measurement unit.

Typedefs

using big_endian_t = std::integral_constant<int, static_cast<signed int>(endian::big)>
using contract_violation_handler = std::function<void(contract_violation const &)>
Contract violation handler type.
using f128 = long double
Float with 128-bit precision.
using f32 = float
Float with 32-bit precision.
using f64 = double
Float with 64-bit precision.
using i16 = std::int16_t
16-bit signed integer
using i32 = std::int32_t
32-bit signed integer
using i64 = std::int64_t
64-bit signed integer
using i8 = std::int8_t
8-bit signed integer
using isize = std::make_signed_t<std::size_t>
Signed integer with pointer size.
using little_endian_t = std::integral_constant<int, static_cast<signed int>(endian::little)>
using native_endian_t = std::integral_constant<int, static_cast<signed int>(endian::native)>
template <typename T, typename = std::enable_if_t<std::is_pointer_v<T>>>
using owner = T
GSL-like owning raw pointer typedef.
template <typename T>
using pimpl = propagate_const<std::unique_ptr<T>>
Pointer-to-implementation pattern trait.
template <typename T>
using plain_type_t = typename plain_type<T>::type
Remove all cv qualifiers, references and pointers from a type.
template <typename T>
using remove_cvref_t = typename remove_cvref<T>::type
The type referred by T or T itself if it is not a reference, with top-level cv-qualifiers removed.
template <typename T = void>
using result = expected<T, std::string>
template <typename T>
using shared_pimpl = propagate_const<std::shared_ptr<T>>
using u16 = std::uint16_t
16-bit unsigned integer
using u32 = std::uint32_t
32-bit unsigned integer
using u64 = std::uint64_t
64-bit unsigned integer
using u8 = std::uint8_t
8-bit unsigned integer
using uint = unsigned int
Alias for unsigned int
using ulonglong = unsigned long long
Alias for unsigned long long
using uptr = std::uintptr_t
Unsigned integer with pointer size.
using usize = std::size_t
Unsigned integer with pointer size.
using version_range = detail::range
using version_range_option = detail::satisfies_option

Functions

template <typename T>
auto abs(T const& v) →  T constexpr
Returns the absolute value of a number.
template <typename T>
auto approx_eq(T a, T b, T epsilon = std::numeric_limits<T>::epsilon()) →  bool constexpr
Returns true if numbers are approximately equal within given epsilon.
template <class To, class From>
bit_cast(From const& src) noexcept
Casts value from one type to another by bit copy.
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
auto bit_ceil(T x) →  T constexpr noexcept
Returns the next power of two of the value.
void broken_invariant(std::string_view const message = "Broken invariant", source_location const& location = source_location::current())
Invokes the global contract violation handler (see violation_handler) with a broken invariant violation.
void broken_postcondition(std::string_view const message = "Broken postcondition", source_location const& location = source_location::current())
Invokes the global contract violation handler (see violation_handler) with a broken postcondition violation.
void broken_precondition(std::string_view const message = "Broken precondition", source_location const& location = source_location::current())
Invokes the global contract violation handler (see violation_handler) with a broken precondition violation.
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto byteswap(T x) →  T constexpr noexcept
Reverses the byte order of the value.
template <typename T>
auto byteswap_unchecked(T u) →  T noexcept
Reverses the byte order of the value without checking for unique object representations.
auto compare(version const& lhs, version const& rhs, comparators_option option = comparators_option::include_prerelease) →  int constexpr noexcept
void default_contract_violation_handler(contract_violation const& violation)
Default contract violation handler.
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto div_euclid(T a, T b) →  T
Calculates Euclidean division, the matching method for rem_euclid().
template <typename C>
auto ends_with(std::basic_string<C> const& input, std::basic_string_view<C> sv) →  bool noexcept
template <typename C>
auto ends_with(std::basic_string<C> const& input, C c) →  bool noexcept
template <typename C>
auto ends_with(std::basic_string<C> const& input, C const* chp) →  bool noexcept
template <typename C>
auto ends_with(std::basic_string_view<C> const& input, std::basic_string_view<C> sv) →  bool noexcept
template <typename C>
auto ends_with(std::basic_string_view<C> const& input, C c) →  bool noexcept
template <typename C>
auto ends_with(std::basic_string_view<C> const& input, C const* chp) →  bool noexcept
auto equal_to(version const& lhs, version const& rhs, comparators_option option = comparators_option::include_prerelease) →  bool constexpr noexcept
template <typename... Args>
auto error(std::string_view format, Args && ... args) →  unexpected<std::decay_t<std::string>>
Generates an unexpected error object with a formatted error message.
template <typename Callback>
auto finally(Callback&& callback) →  detail::scope_guard<Callback> noexcept(…)
template <std::size_t N>
fixed_string(const char8_t(&)[N]) →  fixed_string< N - 1 >
template <std::size_t N>
fixed_string(fixed_string<N>) →  fixed_string< N >
template <std::size_t N>
fixed_string(char const(&)[N]) →  fixed_string< N - 1 >
template <std::size_t N>
fixed_string(wchar_t const(&)[N]) →  fixed_string< N - 1 >
template <std::size_t N>
fixed_string(char16_t const(&)[N]) →  fixed_string< N - 1 >
template <std::size_t N>
fixed_string(char32_t const(&)[N]) →  fixed_string< N - 1 >
fixed_string() →  fixed_string< 0 >
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
auto floor(T val) →  T constexpr
Rounds val down to the nearest integer.
auto fmod(f32 const x, f32 const y) →  f32 constexpr
Returns the remainder of the division of x by y.
template <typename F>
auto from_c_str(char const* owned_str, int const size = -1, F&& dealloc_function = [](char const*ptr) { std::free(const_cast<char*>(ptr));}) →  std::string
auto from_chars(char const* first, char const* last, version& v) →  from_chars_result constexpr noexcept
auto from_string(std::string_view str) →  version constexpr
auto from_string_noexcept(std::string_view str) →  optional<version> constexpr noexcept
auto greater(version const& lhs, version const& rhs, comparators_option option = comparators_option::include_prerelease) →  bool constexpr noexcept
auto greater_equal(version const& lhs, version const& rhs, comparators_option option = comparators_option::include_prerelease) →  bool constexpr noexcept
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
auto has_single_bit(T x) →  bool constexpr noexcept
Checks if the value is an integral power of two.
auto hex_to_char(char c) →  unsigned char constexpr
void invariant(bool const expression, std::string_view const message = "Invariant violated", source_location const& location = source_location::current())
Checks if a given invariant expression is true and throws a contract violation if it is not.
auto is_digit(char c) →  bool constexpr noexcept
auto is_dot(char c) →  bool constexpr noexcept
auto is_hex(char c) →  bool constexpr noexcept
auto is_hyphen(char c) →  bool constexpr noexcept
auto is_letter(char c) →  bool constexpr noexcept
auto is_logical_or(char c) →  bool constexpr noexcept
template <typename T>
auto is_null(T a, T epsilon = std::numeric_limits<T>::epsilon()) →  bool constexpr
Returns true if number is approximately zero within given epsilon.
auto is_operator(char c) →  bool constexpr noexcept
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
auto is_pow2(T x) →  bool constexpr noexcept
Checks if the value is an integral power of two.
auto is_space(char c) →  bool constexpr noexcept
template <typename F>
auto lazy(F&& f) →  auto
Constructs a lazy object from a given function object.
auto less(version const& lhs, version const& rhs, comparators_option option = comparators_option::include_prerelease) →  bool constexpr noexcept
auto less_equal(version const& lhs, version const& rhs, comparators_option option = comparators_option::include_prerelease) →  bool constexpr noexcept
auto logger() →  spdlog::logger&
auto logger(std::string_view const name) →  spdlog::logger&
template <typename T>
auto make_observer(T* ptr) →  observer_ptr<T> constexpr noexcept
template <class T = detail::i_am_secret, class U, class Ret = detail::conditional_t<std::is_same<T, detail::i_am_secret>::value, detail::decay_t<U>, T>>
auto make_optional(U&& v) →  optional<Ret> constexpr
template <class T, class... Args>
auto make_optional(Args && ... args) →  optional<T> constexpr
template <class T, class U, class... Args>
auto make_optional(std::initializer_list<U> il, Args && ... args) →  optional<T> constexpr
template <typename Callback>
auto make_scope_guard(Callback&& callback) →  detail::scope_guard<Callback> noexcept(…)
template <typename T>
auto max(T&& v) →  T constexpr
Returns the maximum of a single value.
template <typename T, typename... Args>
auto max(T const& v1, T const& v2, Args const&... args) →  T constexpr
Returns the maximum value among the provided arguments.
template <typename T>
auto min(T&& v) →  T constexpr
Returns the minimum of a single value.
template <typename T, typename... Args>
auto min(T const& v1, T const& v2, Args const&... args) →  T constexpr
Returns the minimum value among the provided arguments.
auto not_equal_to(version const& lhs, version const& rhs, comparators_option option = comparators_option::include_prerelease) →  bool constexpr noexcept
void not_implemented(source_location const& location = source_location::current())
Invokes the global contract violation handler (see violation_handler) with a broken invariant violation.
template <typename T>
auto ok(T&& t) →  expected<std::decay_t<T>, std::string>
Wrap a value in an expected.
auto ok() →  result
template <class T, class U>
auto operator!=(optional<T> const& lhs, optional<U> const& rhs) →  bool constexpr
template <class T>
auto operator!=(optional<T> const& lhs, nullopt_t) →  bool constexpr noexcept
template <class T>
auto operator!=(nullopt_t, optional<T> const& rhs) →  bool constexpr noexcept
template <class T, class U>
auto operator!=(optional<T> const& lhs, U const& rhs) →  bool constexpr
template <class T, class U>
auto operator!=(U const& lhs, optional<T> const& rhs) →  bool constexpr
auto operator!=(source_location const& lhs, source_location const& rhs) →  bool noexcept
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
auto operator!=(T lower, u128 const& other) →  bool constexpr noexcept
auto operator!=(version const& lhs, version const& rhs) →  bool constexpr noexcept
template <typename T, typename U>
auto operator!=(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) →  bool constexpr noexcept
auto operator""_i16(ulonglong const value) →  i16 constexpr
Literal operator for i16.
auto operator""_i32(ulonglong const value) →  i32 constexpr
Literal operator for i32.
auto operator""_i64(ulonglong const value) →  i64 constexpr
Literal operator for i64.
auto operator""_i8(ulonglong const value) →  i8 constexpr
Literal operator for i8.
auto operator""_ptrdiff(ulonglong value) →  std::ptrdiff_t constexpr
Literal operator for std::ptrdiff_t.
auto operator""_pvoid(ulonglong const value) →  void*
Literal operator for void*.
auto operator""_u16(ulonglong const value) →  u16 constexpr
Literal operator for u16.
auto operator""_u32(ulonglong const value) →  u32 constexpr
Literal operator for u32.
auto operator""_u64(ulonglong const value) →  u64 constexpr
Literal operator for u64.
auto operator""_u8(ulonglong const value) →  u8 constexpr
Literal operator for u8.
auto operator""_uuid(char const* str, std::size_t const size) →  uuid constexpr
Literal operator for the uuid.
auto operator""_version(char const* str, std::size_t length) →  version constexpr
Version literal operator.
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
auto operator%(T lower, u128 const& value) →  u128 constexpr noexcept
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
auto operator&(T lower, u128 const& value) →  u128 constexpr noexcept
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
auto operator*(T lower, u128 const& value) →  u128 constexpr noexcept
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
auto operator+(T lower, u128 const& value) →  u128 constexpr noexcept
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
auto operator-(T lower, u128 const& value) →  u128 constexpr noexcept
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
auto operator/(T lower, u128 const& value) →  u128 constexpr noexcept
template <class T, class U>
auto operator<(optional<T> const& lhs, optional<U> const& rhs) →  bool constexpr
template <class T>
auto operator<(optional<T> const&, nullopt_t) →  bool constexpr noexcept
template <class T>
auto operator<(nullopt_t, optional<T> const& rhs) →  bool constexpr noexcept
template <class T, class U>
auto operator<(optional<T> const& lhs, U const& rhs) →  bool constexpr
template <class T, class U>
auto operator<(U const& lhs, optional<T> const& rhs) →  bool constexpr
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
auto operator<(T lower, u128 const& other) →  bool constexpr noexcept
auto operator<(version const& lhs, version const& rhs) →  bool constexpr noexcept
template <typename T, typename U>
auto operator<(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) →  bool constexpr noexcept
template <class E, class T>
auto operator<<(std::basic_ostream<E, T>& os, source_location const& loc) →  std::basic_ostream<E, T>&
Stream operator for source_location.
template <typename Char, typename Traits>
auto operator<<(std::basic_ostream<Char, Traits>& os, version const& v) →  std::basic_ostream<Char, Traits>&
template <class T, class U>
auto operator<=(optional<T> const& lhs, optional<U> const& rhs) →  bool constexpr
template <class T>
auto operator<=(optional<T> const& lhs, nullopt_t) →  bool constexpr noexcept
template <class T>
auto operator<=(nullopt_t, optional<T> const&) →  bool constexpr noexcept
template <class T, class U>
auto operator<=(optional<T> const& lhs, U const& rhs) →  bool constexpr
template <class T, class U>
auto operator<=(U const& lhs, optional<T> const& rhs) →  bool constexpr
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
auto operator<=(T lower, u128 const& other) →  bool constexpr noexcept
auto operator<=(version const& lhs, version const& rhs) →  bool constexpr noexcept
template <typename T, typename U>
auto operator<=(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) →  bool constexpr noexcept
auto operator<=>(version const& lhs, version const& rhs) →  std::strong_ordering constexpr
template <class T, class U>
auto operator==(optional<T> const& lhs, optional<U> const& rhs) →  bool constexpr
Compares two optional objects.
template <class T>
auto operator==(optional<T> const& lhs, nullopt_t) →  bool constexpr noexcept
Compares an optional to a nullopt
template <class T>
auto operator==(nullopt_t, optional<T> const& rhs) →  bool constexpr noexcept
template <class T, class U>
auto operator==(optional<T> const& lhs, U const& rhs) →  bool constexpr
Compares the optional with a value.
template <class T, class U>
auto operator==(U const& lhs, optional<T> const& rhs) →  bool constexpr
auto operator==(source_location const& lhs, source_location const& rhs) →  bool noexcept
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
auto operator==(T lower, u128 const& other) →  bool constexpr noexcept
auto operator==(version const& lhs, version const& rhs) →  bool constexpr noexcept
template <typename T, typename U>
auto operator==(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) →  bool constexpr noexcept
template <class T, class U>
auto operator>(optional<T> const& lhs, optional<U> const& rhs) →  bool constexpr
template <class T>
auto operator>(optional<T> const& lhs, nullopt_t) →  bool constexpr noexcept
template <class T>
auto operator>(nullopt_t, optional<T> const&) →  bool constexpr noexcept
template <class T, class U>
auto operator>(optional<T> const& lhs, U const& rhs) →  bool constexpr
template <class T, class U>
auto operator>(U const& lhs, optional<T> const& rhs) →  bool constexpr
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
auto operator>(T lower, u128 const& other) →  bool constexpr noexcept
auto operator>(version const& lhs, version const& rhs) →  bool constexpr noexcept
template <typename T, typename U>
auto operator>(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) →  bool constexpr noexcept
template <class T, class U>
auto operator>=(optional<T> const& lhs, optional<U> const& rhs) →  bool constexpr
template <class T>
auto operator>=(optional<T> const&, nullopt_t) →  bool constexpr noexcept
template <class T>
auto operator>=(nullopt_t, optional<T> const& rhs) →  bool constexpr noexcept
template <class T, class U>
auto operator>=(optional<T> const& lhs, U const& rhs) →  bool constexpr
template <class T, class U>
auto operator>=(U const& lhs, optional<T> const& rhs) →  bool constexpr
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
auto operator>=(T lower, u128 const& other) →  bool constexpr noexcept
auto operator>=(version const& lhs, version const& rhs) →  bool constexpr noexcept
template <typename T, typename U>
auto operator>=(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) →  bool constexpr noexcept
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
auto operator^(T lower, u128 const& value) →  u128 constexpr noexcept
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
auto operator|(T lower, u128 const& value) →  u128 constexpr noexcept
template <class T>
optional(T) →  optional< T >
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
auto popcount(T x) →  int constexpr noexcept
Returns the number of 1 bits in the value.
void postcondition(bool const expression, std::string_view const message = "Postcondition violated", source_location const& location = source_location::current())
Checks if a given postcondition expression is true and throws a contract violation if it is not.
void precondition(bool const expression, std::string_view const message = "Precondition violated", source_location const& location = source_location::current())
Checks if a given precondition expression is true and throws a contract violation if it is not.
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto rem_euclid(T a, T b) →  T
Calculates the least nonnegative remainder of self (mod rhs).
auto set_violation_handler(contract_violation_handler handler) →  contract_violation_handler
Sets the global contract violation handler and returns the old one.
template <typename T>
auto some(T&& t) →  optional<std::decay_t<T>>
Wrap a value in an optional.
auto split(std::string const& input) →  std::vector<std::string>
auto split(std::string_view input) →  std::vector<std::string>
auto split_by(std::string const& input, char delimiter) →  std::vector<std::string>
auto split_by(std::string_view input, char delimiter) →  std::vector<std::string>
template <typename C>
auto starts_with(std::basic_string<C> const& input, std::basic_string_view<C> sv) →  bool noexcept
template <typename C>
auto starts_with(std::basic_string<C> const& input, C c) →  bool noexcept
template <typename C>
auto starts_with(std::basic_string<C> const& input, C const* chp) →  bool noexcept
template <typename C>
auto starts_with(std::basic_string_view<C> const& input, std::basic_string_view<C> sv) →  bool noexcept
template <typename C>
auto starts_with(std::basic_string_view<C> const& input, C c) →  bool noexcept
template <typename C>
auto starts_with(std::basic_string_view<C> const& input, C const* chp) →  bool noexcept
template <class T, detail::enable_if_t<std::is_move_constructible<T>::value>* = nullptr, detail::enable_if_t<detail::is_swappable<T>::value>* = nullptr>
void swap(optional<T>& lhs, optional<T>& rhs) noexcept(…)
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto to_big_endian(T x) →  T constexpr noexcept
Reverses the byte order of the value if the native endianness is little.
auto to_chars(char* first, char* last, version const& v) →  to_chars_result constexpr noexcept
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto to_degrees(T radians) →  T constexpr noexcept
Converts radians to degrees.
auto to_digit(char c) →  std::uint16_t constexpr noexcept
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto to_little_endian(T x) →  T constexpr noexcept
Reverses the byte order of the value if the native endianness is big.
auto to_lower(std::string_view input) →  std::string
auto to_lower(char c) →  char constexpr noexcept
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
auto to_radians(T degrees) →  T constexpr noexcept
Converts degrees to radians.
auto to_string(version const& v) →  std::string
template <typename T, typename = std::enable_if_t<std::is_enum_v<T>>>
auto to_underlying(T t) →  auto constexpr noexcept
Converts an enumeration value to its underlying type.
void unreachable()
Informs the compiler that the current location is unreachable.
auto valid(std::string_view str) →  bool constexpr noexcept
auto violation_handler() →  contract_violation_handler&
Returns the current global contract violation handler.

Variables

static nullopt_t nullopt constexpr
Represents an empty optional.
template <typename... Args>
const_overload_t<Args...> const_overload constexpr
template <typename T, typename... U>
bool is_any_of_v constexpr
template <typename... Args>
non_const_overload_t<Args...> non_const_overload constexpr
auto none constexpr
Wrap an empty value in an optional.
template <typename... Args>
overload_t<Args...> overload constexpr

Enum documentation

enum class rll::angle_unit: char

Measurement unit of the angle.

enum class rll::contract_type: signed char

Type of contract.

Enumerators
precondition

Precondition.

postcondition

Postcondition.

invariant

Invariant.

enum class rll::endian: signed int
#include <rll/bit.h>

Endianness.

This is the backport of std::endian.

Enumerators
little

Little endian.

big

Big endian.

native

Native endian. Either little or big.

enum class rll::prerelease: std::uint8_t

enum class rll::saving_policy: u8

Determines the policy used for autosaving configuration files.

Enumerators
autosave

Saves configuration files automatically on closing.

explicit_

Saves configuration files only explicitly.

enum class rll::velocity_unit: char

Measurement unit.

Typedef documentation

using rll::big_endian_t = std::integral_constant<int, static_cast<signed int>(endian::big)>
#include <rll/bit.h>

using rll::contract_violation_handler = std::function<void(contract_violation const &)>

Contract violation handler type.

using rll::f128 = long double

Float with 128-bit precision.

using rll::f32 = float

Float with 32-bit precision.

using rll::f64 = double

Float with 64-bit precision.

using rll::i16 = std::int16_t

16-bit signed integer

using rll::i32 = std::int32_t

32-bit signed integer

using rll::i64 = std::int64_t

64-bit signed integer

using rll::i8 = std::int8_t

8-bit signed integer

using rll::isize = std::make_signed_t<std::size_t>

Signed integer with pointer size.

using rll::little_endian_t = std::integral_constant<int, static_cast<signed int>(endian::little)>
#include <rll/bit.h>

using rll::native_endian_t = std::integral_constant<int, static_cast<signed int>(endian::native)>
#include <rll/bit.h>

template <typename T, typename = std::enable_if_t<std::is_pointer_v<T>>>
using rll::owner = T

GSL-like owning raw pointer typedef.

Template parameters
T Pointer type.

rll::owner<T> is designed as a safety mechanism for code that must deal directly with raw pointers that own memory.

Ideally such code should be restricted to the implementation of low-level abstractions. rll::owner<T> can also be used as a stepping point in converting legacy code to use more modern RAII constructs, such as smart pointers.

template <typename T>
using rll::pimpl = propagate_const<std::unique_ptr<T>>

Pointer-to-implementation pattern trait.

Template parameters
T Type to implement.

Allows to use Pimpl pattern in custom types and classes.

Example declaration:

class TestPimpl : rll::pin
{
  public:
     TestPimpl() = default;
     [[nodiscard]] auto add(int a, int b) const -> int;

  private:
    struct impl;
    rll::pimpl<struct impl> impl_;
};

struct TestPimpl::impl
{
    int add(int a, int b) const { return a + b; }
};

int TestPimpl::add(int a, int b) const {
  return this->impl_->add(a, b);
}

template <typename T>
using rll::plain_type_t = typename plain_type<T>::type

Remove all cv qualifiers, references and pointers from a type.

template <typename T>
using rll::remove_cvref_t = typename remove_cvref<T>::type

The type referred by T or T itself if it is not a reference, with top-level cv-qualifiers removed.

template <typename T = void>
using rll::result = expected<T, std::string>

template <typename T>
using rll::shared_pimpl = propagate_const<std::shared_ptr<T>>

using rll::u16 = std::uint16_t

16-bit unsigned integer

using rll::u32 = std::uint32_t

32-bit unsigned integer

using rll::u64 = std::uint64_t

64-bit unsigned integer

using rll::u8 = std::uint8_t

8-bit unsigned integer

using rll::uint = unsigned int

Alias for unsigned int

using rll::ulonglong = unsigned long long

Alias for unsigned long long

using rll::uptr = std::uintptr_t

Unsigned integer with pointer size.

using rll::usize = std::size_t

Unsigned integer with pointer size.

using rll::version_range = detail::range

using rll::version_range_option = detail::satisfies_option

Function documentation

#include <rll/math.h>
template <typename T>
T rll::abs(T const& v) constexpr

Returns the absolute value of a number.

Template parameters
T Type of the value.
Parameters
in Value to take the absolute value of.
Returns The absolute value of v.

This function simply negates the input if it is negative, and returns the input unchanged if it is non-negative. It is a constexpr version of std::abs.

#include <rll/math.h>
template <typename T>
bool rll::approx_eq(T a, T b, T epsilon = std::numeric_limits<T>::epsilon()) constexpr

Returns true if numbers are approximately equal within given epsilon.

Template parameters
T Number type
Parameters
a First number
b Second number
epsilon Epsilon factor for comparison. Default is std::numeric_limits<T>::epsilon().
Returns True if numbers are approximately equal within given epsilon.

Compares floating point values using formula |a - b| <= epsilon * epsilon_factor.

#include <rll/bit.h>
template <class To, class From>
rll::bit_cast(From const& src) noexcept

Casts value from one type to another by bit copy.

Template parameters
To Destination type. Must be a trivially copyable type and have the same size as the source type.
From Source type. Must be a trivially copyable type and have the same size as the destination type.
Parameters
src Source value.
Returns Destination value.

This is the backport of std::bit_cast.

Obtain a value of type To by reinterpreting the object representation of From. Every bit in the value representation of the returned To object is equal to the corresponding bit in the object representation of from.

The values of padding bits in the returned To object are unspecified.

If there is no value of type To corresponding to the value representation produced, the behavior is undefined. If there are multiple such values, which value is produced is unspecified.

#include <rll/bit.h>
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>
T rll::bit_ceil(T x) constexpr noexcept

Returns the next power of two of the value.

Template parameters
T Type of the value. Must be an unsigned integral type.
Parameters
x Value.
Returns The next power of two of the value.

void rll::broken_invariant(std::string_view const message = "Broken invariant", source_location const& location = source_location::current())

Invokes the global contract violation handler (see violation_handler) with a broken invariant violation.

Parameters
message Violation message. Defaults to "Broken invariant".
location Violation location in source code. Defaults to current location.

If the expression is false, the contract violation is thrown with the given message and location.

void rll::broken_postcondition(std::string_view const message = "Broken postcondition", source_location const& location = source_location::current())

Invokes the global contract violation handler (see violation_handler) with a broken postcondition violation.

Parameters
message Violation message. Defaults to "Broken postcondition".
location Violation location in source code. Defaults to current location.

void rll::broken_precondition(std::string_view const message = "Broken precondition", source_location const& location = source_location::current())

Invokes the global contract violation handler (see violation_handler) with a broken precondition violation.

Parameters
message Violation message. Defaults to "Broken precondition".
location Violation location in source code. Defaults to current location.

#include <rll/bit.h>
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
T rll::byteswap(T x) constexpr noexcept

Reverses the byte order of the value.

Template parameters
T Type of the value. Must be a numeric type.
Parameters
x Value.
Returns Reversed value.

This is the backport of std::byteswap.

#include <rll/bit.h>
template <typename T>
T rll::byteswap_unchecked(T u) noexcept

Reverses the byte order of the value without checking for unique object representations.

Template parameters
T Type of the value. Must be a numeric type.
Returns Reversed value.

void rll::default_contract_violation_handler(contract_violation const& violation)

Default contract violation handler.

Parameters
violation Contract violation data.

Default implementation of the contract violation handler.

Prints the violation to the standard error stream and terminates the program. If it is possible, colors the violation message in red.

Example output:

Contract violation (invariant):
   Hello, world!
   in function 'int __cdecl main(int,char **)'
   in file 'D:/dev/my/floppy-dev/bin/main.cc'
   at line 7:18

Process finished with exit code 3

#include <rll/math.h>
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
T rll::div_euclid(T a, T b)

Calculates Euclidean division, the matching method for rem_euclid().

Parameters
a Dividend
b Divisor

template <typename C>
bool rll::ends_with(std::basic_string<C> const& input, std::basic_string_view<C> sv) noexcept

template <typename C>
bool rll::ends_with(std::basic_string<C> const& input, C c) noexcept

template <typename C>
bool rll::ends_with(std::basic_string<C> const& input, C const* chp) noexcept

template <typename C>
bool rll::ends_with(std::basic_string_view<C> const& input, std::basic_string_view<C> sv) noexcept

template <typename C>
bool rll::ends_with(std::basic_string_view<C> const& input, C c) noexcept

template <typename C>
bool rll::ends_with(std::basic_string_view<C> const& input, C const* chp) noexcept

template <typename... Args>
unexpected<std::decay_t<std::string>> rll::error(std::string_view format, Args && ... args)

Generates an unexpected error object with a formatted error message.

Parameters
format The format string used to construct the error message.
args Additional arguments to format the error message.
Returns An unexpected object containing the formatted error message.

This function formats an error message using the provided format string and arguments, and returns it wrapped in an unexpected object.

template <typename Callback>
detail::scope_guard<Callback> rll::finally(Callback&& callback) noexcept(…)

template <std::size_t N>
rll::fixed_string(const char8_t(&)[N]) →  fixed_string< N - 1 >

template <std::size_t N>
rll::fixed_string(fixed_string<N>) →  fixed_string< N >

template <std::size_t N>
rll::fixed_string(char const(&)[N]) →  fixed_string< N - 1 >

template <std::size_t N>
rll::fixed_string(wchar_t const(&)[N]) →  fixed_string< N - 1 >

template <std::size_t N>
rll::fixed_string(char16_t const(&)[N]) →  fixed_string< N - 1 >

template <std::size_t N>
rll::fixed_string(char32_t const(&)[N]) →  fixed_string< N - 1 >

rll::fixed_string() →  fixed_string< 0 >

#include <rll/math.h>
template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
T rll::floor(T val) constexpr

Rounds val down to the nearest integer.

Template parameters
T Number type. Must be a floating point type.
Parameters
val Number to round.

This is a constexpr version of std::floor.

f32 rll::fmod(f32 const x, f32 const y) constexpr
#include <rll/math.h>

Returns the remainder of the division of x by y.

Parameters
in First value.
in Second value.
Returns The remainder of the division of x by y.

This function is a constexpr version of std::fmod.

template <typename F>
std::string rll::from_c_str(char const* owned_str, int const size = -1, F&& dealloc_function = [](char const*ptr) { std::free(const_cast<char*>(ptr));})

from_chars_result rll::from_chars(char const* first, char const* last, version& v) constexpr noexcept

#include <rll/bit.h>
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
bool rll::has_single_bit(T x) constexpr noexcept

Checks if the value is an integral power of two.

Template parameters
T Type of the value. Must be an integral type.
Parameters
x Value to check.
Returns True if the value is an integral power of two, false otherwise.

unsigned char rll::hex_to_char(char c) constexpr

void rll::invariant(bool const expression, std::string_view const message = "Invariant violated", source_location const& location = source_location::current())

Checks if a given invariant expression is true and throws a contract violation if it is not.

Parameters
expression Invariant expression.
message Violation message. Defaults to "Invariant violated".
location Violation location in source code. Defaults to current location.

If the expression is false, the contract violation is thrown with the given message and location.

bool rll::is_digit(char c) constexpr noexcept

bool rll::is_dot(char c) constexpr noexcept

bool rll::is_hex(char c) constexpr noexcept

bool rll::is_hyphen(char c) constexpr noexcept

bool rll::is_letter(char c) constexpr noexcept

bool rll::is_logical_or(char c) constexpr noexcept

#include <rll/math.h>
template <typename T>
bool rll::is_null(T a, T epsilon = std::numeric_limits<T>::epsilon()) constexpr

Returns true if number is approximately zero within given epsilon.

Template parameters
T Number type
Parameters
a Number
epsilon Epsilon factor for comparison. Default is std::numeric_limits<T>::epsilon().
Returns True if number is zero within given epsilon.

Compares floating point values using formula |a| <= epsilon * epsilon_factor

bool rll::is_operator(char c) constexpr noexcept

#include <rll/bit.h>
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
bool rll::is_pow2(T x) constexpr noexcept

Checks if the value is an integral power of two.

Template parameters
T Type of the value. Must be an integral type.
Parameters
x Value to check.
Returns True if the value is an integral power of two, false otherwise.

This is an alias for has_single_bit function.

bool rll::is_space(char c) constexpr noexcept

template <typename F>
auto rll::lazy(F&& f)

Constructs a lazy object from a given function object.

Parameters
in Function object to be evaluated when the value is requested the first time. The function object is moved into the lazy object.

spdlog::logger& rll::logger()
#include <rll/log.h>

spdlog::logger& rll::logger(std::string_view const name)
#include <rll/log.h>

template <typename T>
observer_ptr<T> rll::make_observer(T* ptr) constexpr noexcept

template <class T = detail::i_am_secret, class U, class Ret = detail::conditional_t<std::is_same<T, detail::i_am_secret>::value, detail::decay_t<U>, T>>
optional<Ret> rll::make_optional(U&& v) constexpr

template <class T, class... Args>
optional<T> rll::make_optional(Args && ... args) constexpr

template <class T, class U, class... Args>
optional<T> rll::make_optional(std::initializer_list<U> il, Args && ... args) constexpr

template <typename Callback>
detail::scope_guard<Callback> rll::make_scope_guard(Callback&& callback) noexcept(…)

#include <rll/math.h>
template <typename T>
T rll::max(T&& v) constexpr

Returns the maximum of a single value.

Template parameters
T Type of the value.
Parameters
in Value to return.
Returns The maximum of a single value.

This overload simply returns the given value.

#include <rll/math.h>
template <typename T, typename... Args>
T rll::max(T const& v1, T const& v2, Args const&... args) constexpr

Returns the maximum value among the provided arguments.

Template parameters
T Type of the values to compare.
Args Variadic template arguments allowing multiple values of type T.
Parameters
v1 in First value to compare.
v2 in Second value to compare.
args in Additional values to compare.
Returns The maximum value among the provided arguments.

This function compares multiple values and returns the largest one. It uses a recursive approach to handle an arbitrary number of arguments.

#include <rll/math.h>
template <typename T>
T rll::min(T&& v) constexpr

Returns the minimum of a single value.

Template parameters
T Type of the value.
Parameters
in Value to return.
Returns The minimum of a single value.

This overload simply returns the given value.

#include <rll/math.h>
template <typename T, typename... Args>
T rll::min(T const& v1, T const& v2, Args const&... args) constexpr

Returns the minimum value among the provided arguments.

Template parameters
T Type of the values to compare.
Args Variadic template arguments allowing multiple values of type T.
Parameters
v1 in First value to compare.
v2 in Second value to compare.
args in Additional values to compare.
Returns The minimum value among the provided arguments.

This function compares multiple values and returns the smallest one. It uses a recursive approach to handle an arbitrary number of arguments.

void rll::not_implemented(source_location const& location = source_location::current())

Invokes the global contract violation handler (see violation_handler) with a broken invariant violation.

Parameters
location Violation location in source code. Defaults to current location.

Useful for marking a function as unimplemented.

template <typename T>
expected<std::decay_t<T>, std::string> rll::ok(T&& t)

Wrap a value in an expected.

This function is a helper for creating an expected from a value. It is mostly useful when working with generic code that needs to work with both expected and optional types.

result rll::ok()

template <class T, class U>
bool rll::operator!=(optional<T> const& lhs, optional<U> const& rhs) constexpr

template <class T>
bool rll::operator!=(optional<T> const& lhs, nullopt_t) constexpr noexcept

template <class T>
bool rll::operator!=(nullopt_t, optional<T> const& rhs) constexpr noexcept

template <class T, class U>
bool rll::operator!=(optional<T> const& lhs, U const& rhs) constexpr

template <class T, class U>
bool rll::operator!=(U const& lhs, optional<T> const& rhs) constexpr

bool rll::operator!=(source_location const& lhs, source_location const& rhs) noexcept

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
bool rll::operator!=(T lower, u128 const& other) constexpr noexcept

Template parameters
T Integral type.
Parameters
lower in The integer value to compare.
other in The u128 value to compare.
Returns true if the integer value is not equal to the u128 value, false otherwise.

Checks if an integer value is not equal to a u128 value.

bool rll::operator!=(version const& lhs, version const& rhs) constexpr noexcept

template <typename T, typename U>
bool rll::operator!=(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) constexpr noexcept

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
u128 rll::operator%(T lower, u128 const& value) constexpr noexcept

Template parameters
T Integer type.
Parameters
lower in The integer value to be divided.
value in The u128 value that divides the integer.
Returns u128 the remainder of the division.

Calculates the remainder of division of an integer by a u128 value.

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
u128 rll::operator&(T lower, u128 const& value) constexpr noexcept

Template parameters
T Integer type.
Parameters
lower in The integer value.
value in The u128 value.
Returns u128 the result of the bitwise AND operation.

Performs bitwise AND operation between an integer and a u128 value.

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
u128 rll::operator*(T lower, u128 const& value) constexpr noexcept

Template parameters
T Integer type.
Parameters
lower in The integer value to be multiplied.
value in The u128 value to be multiplied.
Returns u128 the result of the multiplication.

Performs multiplication between an integer and a u128 value.

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
u128 rll::operator+(T lower, u128 const& value) constexpr noexcept

Template parameters
T Integer type.
Parameters
lower in The integer value to be added.
value in The u128 value to be added.
Returns u128 the result of the addition.

Performs addition between an integer and a u128 value.

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
u128 rll::operator-(T lower, u128 const& value) constexpr noexcept

Template parameters
T Integer type.
Parameters
lower in The integer value from which the u128 value is subtracted.
value in The u128 value to be subtracted.
Returns u128 the result of the subtraction.

Performs subtraction of a u128 value from an integer.

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
u128 rll::operator/(T lower, u128 const& value) constexpr noexcept

Template parameters
T Integer type.
Parameters
lower in The integer value to be divided.
value in The u128 value that divides the integer.
Returns u128 the result of the division.

Performs division of an integer by a u128 value.

template <class T, class U>
bool rll::operator<(optional<T> const& lhs, optional<U> const& rhs) constexpr

template <class T>
bool rll::operator<(optional<T> const&, nullopt_t) constexpr noexcept

template <class T>
bool rll::operator<(nullopt_t, optional<T> const& rhs) constexpr noexcept

template <class T, class U>
bool rll::operator<(optional<T> const& lhs, U const& rhs) constexpr

template <class T, class U>
bool rll::operator<(U const& lhs, optional<T> const& rhs) constexpr

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
bool rll::operator<(T lower, u128 const& other) constexpr noexcept

Template parameters
T An integral type parameter that is checked at compile-time to ensure it is an integer type.
Parameters
lower in The integer value of type T to be compared.
other in The u128 value to compare against.
Returns true if lower is less than other, false otherwise.

Compares if an integer value is less than a u128 value.

This function template overloads the less than operator (<) to compare an integer of type T with a u128 value. It checks if the integer value is lexicographically less than the u128 value.

bool rll::operator<(version const& lhs, version const& rhs) constexpr noexcept

template <typename T, typename U>
bool rll::operator<(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) constexpr noexcept

template <class E, class T>
std::basic_ostream<E, T>& rll::operator<<(std::basic_ostream<E, T>& os, source_location const& loc)

Stream operator for source_location.

template <typename Char, typename Traits>
std::basic_ostream<Char, Traits>& rll::operator<<(std::basic_ostream<Char, Traits>& os, version const& v)

template <class T, class U>
bool rll::operator<=(optional<T> const& lhs, optional<U> const& rhs) constexpr

template <class T>
bool rll::operator<=(optional<T> const& lhs, nullopt_t) constexpr noexcept

template <class T>
bool rll::operator<=(nullopt_t, optional<T> const&) constexpr noexcept

template <class T, class U>
bool rll::operator<=(optional<T> const& lhs, U const& rhs) constexpr

template <class T, class U>
bool rll::operator<=(U const& lhs, optional<T> const& rhs) constexpr

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
bool rll::operator<=(T lower, u128 const& other) constexpr noexcept

Template parameters
T An integral type parameter that is checked at compile-time to ensure it is an integer type.
Parameters
lower in The integer value of type T to be compared.
other in The u128 value to compare against.
Returns true if lower is less than or equal to other, false otherwise.

Compares if an integer value is less than or equal to a u128 value.

This function template overloads the less than or equal to operator (<=) to compare an integer of type T with a u128 value. It checks if the integer value is lexicographically less than or equal to the u128 value.

bool rll::operator<=(version const& lhs, version const& rhs) constexpr noexcept

template <typename T, typename U>
bool rll::operator<=(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) constexpr noexcept

std::strong_ordering rll::operator<=>(version const& lhs, version const& rhs) constexpr

template <class T, class U>
bool rll::operator==(optional<T> const& lhs, optional<U> const& rhs) constexpr

Compares two optional objects.

template <class T>
bool rll::operator==(optional<T> const& lhs, nullopt_t) constexpr noexcept

Compares an optional to a nullopt

template <class T>
bool rll::operator==(nullopt_t, optional<T> const& rhs) constexpr noexcept

template <class T, class U>
bool rll::operator==(optional<T> const& lhs, U const& rhs) constexpr

Compares the optional with a value.

template <class T, class U>
bool rll::operator==(U const& lhs, optional<T> const& rhs) constexpr

bool rll::operator==(source_location const& lhs, source_location const& rhs) noexcept

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
bool rll::operator==(T lower, u128 const& other) constexpr noexcept

Template parameters
T Integral type.
Parameters
lower in The integer value to compare.
other in The u128 value to compare.
Returns true if the integer value is equal to the u128 value, false otherwise.

Checks if an integer value is equal to a u128 value.

bool rll::operator==(version const& lhs, version const& rhs) constexpr noexcept

template <typename T, typename U>
bool rll::operator==(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) constexpr noexcept

template <class T, class U>
bool rll::operator>(optional<T> const& lhs, optional<U> const& rhs) constexpr

template <class T>
bool rll::operator>(optional<T> const& lhs, nullopt_t) constexpr noexcept

template <class T>
bool rll::operator>(nullopt_t, optional<T> const&) constexpr noexcept

template <class T, class U>
bool rll::operator>(optional<T> const& lhs, U const& rhs) constexpr

template <class T, class U>
bool rll::operator>(U const& lhs, optional<T> const& rhs) constexpr

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
bool rll::operator>(T lower, u128 const& other) constexpr noexcept

Template parameters
T An integral type parameter that is checked at compile-time to ensure it is an integer type.
Parameters
lower in The integer value of type T to be compared.
other in The u128 value to compare against.
Returns true if lower is greater than other, false otherwise.

Compares if an integer value is greater than a u128 value.

This function template overloads the greater than operator (>) to compare an integer of type T with a u128 value. It checks if the integer value is lexicographically greater than the u128 value.

bool rll::operator>(version const& lhs, version const& rhs) constexpr noexcept

template <typename T, typename U>
bool rll::operator>(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) constexpr noexcept

template <class T, class U>
bool rll::operator>=(optional<T> const& lhs, optional<U> const& rhs) constexpr

template <class T>
bool rll::operator>=(optional<T> const&, nullopt_t) constexpr noexcept

template <class T>
bool rll::operator>=(nullopt_t, optional<T> const& rhs) constexpr noexcept

template <class T, class U>
bool rll::operator>=(optional<T> const& lhs, U const& rhs) constexpr

template <class T, class U>
bool rll::operator>=(U const& lhs, optional<T> const& rhs) constexpr

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
bool rll::operator>=(T lower, u128 const& other) constexpr noexcept

Template parameters
T An integral type parameter that is checked at compile-time to ensure it is an integer type.
Parameters
lower in The integer value of type T to be compared.
other in The u128 value to compare against.
Returns true if lower is greater than or equal to other, false otherwise.

Compares if an integer value is greater than or equal to a u128 value.

This function template overloads the greater than or equal to operator (>=) to compare an integer of type T with a u128 value. It checks if the integer value is lexicographically greater than or equal to the u128 value.

bool rll::operator>=(version const& lhs, version const& rhs) constexpr noexcept

template <typename T, typename U>
bool rll::operator>=(observer_ptr<T> const& lhs, observer_ptr<U> const& rhs) constexpr noexcept

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
u128 rll::operator^(T lower, u128 const& value) constexpr noexcept

Template parameters
T Integer type.
Parameters
lower in The integer value.
value in The u128 value.
Returns u128 the result of the bitwise XOR operation.

Performs bitwise XOR operation between an integer and a u128 value.

#include <rll/u128.h>
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
u128 rll::operator|(T lower, u128 const& value) constexpr noexcept

Template parameters
T Integer type.
Parameters
lower in The integer value.
value in The u128 value.
Returns u128 the result of the bitwise OR operation.

Performs bitwise OR operation between an integer and a u128 value.

template <class T>
rll::optional(T) →  optional< T >

#include <rll/bit.h>
template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
int rll::popcount(T x) constexpr noexcept

Returns the number of 1 bits in the value.

Template parameters
T Type of the value. Must be an unsigned integral type.
Parameters
x Value to count the number of 1 bits in.
Returns The number of 1 bits in the value.

void rll::postcondition(bool const expression, std::string_view const message = "Postcondition violated", source_location const& location = source_location::current())

Checks if a given postcondition expression is true and throws a contract violation if it is not.

Parameters
expression Postcondition expression.
message Violation message. Defaults to "Postcondition violated".
location Violation location in source code. Defaults to current location.

If the expression is false, the contract violation is thrown with the given message and location.

void rll::precondition(bool const expression, std::string_view const message = "Precondition violated", source_location const& location = source_location::current())

Checks if a given precondition expression is true and throws a contract violation if it is not.

Parameters
expression Precondition expression.
message Violation message. Defaults to "Precondition violated".
location Violation location in source code. Defaults to current location.

If the expression is false, the contract violation is thrown with the given message and location.

#include <rll/math.h>
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
T rll::rem_euclid(T a, T b)

Calculates the least nonnegative remainder of self (mod rhs).

Parameters
a Dividend
b Divisor

contract_violation_handler rll::set_violation_handler(contract_violation_handler handler)

Sets the global contract violation handler and returns the old one.

Parameters
handler Contract violation handler.
Returns Old global contract violation handler.

template <typename T>
optional<std::decay_t<T>> rll::some(T&& t)

Wrap a value in an optional.

This function is a helper for creating an optional from a value. It is mostly useful when working with generic code that needs to work with both expected and optional types.

std::vector<std::string> rll::split_by(std::string const& input, char delimiter)

std::vector<std::string> rll::split_by(std::string_view input, char delimiter)

template <typename C>
bool rll::starts_with(std::basic_string<C> const& input, std::basic_string_view<C> sv) noexcept

template <typename C>
bool rll::starts_with(std::basic_string<C> const& input, C c) noexcept

template <typename C>
bool rll::starts_with(std::basic_string<C> const& input, C const* chp) noexcept

template <typename C>
bool rll::starts_with(std::basic_string_view<C> const& input, std::basic_string_view<C> sv) noexcept

template <typename C>
bool rll::starts_with(std::basic_string_view<C> const& input, C c) noexcept

template <typename C>
bool rll::starts_with(std::basic_string_view<C> const& input, C const* chp) noexcept

template <class T, detail::enable_if_t<std::is_move_constructible<T>::value>* = nullptr, detail::enable_if_t<detail::is_swappable<T>::value>* = nullptr>
void rll::swap(optional<T>& lhs, optional<T>& rhs) noexcept(…)

#include <rll/bit.h>
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
T rll::to_big_endian(T x) constexpr noexcept

Reverses the byte order of the value if the native endianness is little.

Template parameters
T Type of the value. Must be a numeric type.
Parameters
x Value.
Returns Reversed value.

If the native endianness is big, the value is returned unchanged.

to_chars_result rll::to_chars(char* first, char* last, version const& v) constexpr noexcept

#include <rll/math.h>
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
T rll::to_degrees(T radians) constexpr noexcept

Converts radians to degrees.

Template parameters
T Underlying type. Must be an integral or floating point type.
Parameters
radians Radian value.
Returns Degree value.

std::uint16_t rll::to_digit(char c) constexpr noexcept

#include <rll/bit.h>
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
T rll::to_little_endian(T x) constexpr noexcept

Reverses the byte order of the value if the native endianness is big.

Template parameters
T Type of the value. Must be a numeric type.
Parameters
x Value.
Returns Reversed value.

If the native endianness is little, the value is returned unchanged.

char rll::to_lower(char c) constexpr noexcept

#include <rll/math.h>
template <typename T, typename = std::enable_if_t<is_num_v<T>>>
T rll::to_radians(T degrees) constexpr noexcept

Converts degrees to radians.

Template parameters
T Underlying type. Must be an integral or floating point type.
Parameters
degrees Degree value.
Returns Radian value.

template <typename T, typename = std::enable_if_t<std::is_enum_v<T>>>
auto rll::to_underlying(T t) constexpr noexcept

Converts an enumeration value to its underlying type.

Template parameters
T The enumeration type. Must be an enumeration type.
Parameters
t The enumeration value to convert.
Returns The underlying value of the enumeration.

This is a convenience function for converting an enumeration value to its underlying type. It is a generic version of the C++23 std::to_underlying function.

void rll::unreachable()

Informs the compiler that the current location is unreachable.

If the compiler can prove that the current location is unreachable, it is free to optimize the program as if the current location did not exist. This is a very powerful optimization hint.

This function is very useful when you write code that should never be executed (for example, in a switch-case statement where you have already handled all possible values), as it allows the compiler to optimize away the unreachable code.

Example:

enum class Color { Red, Green, Blue };

auto to_string(Color c) -> std::string {
  switch (c) {
    case Color::Red: return "red";
    case Color::Green: return "green";
    case Color::Blue: return "blue";
    default: rll::unreachable();
  }
}

bool rll::valid(std::string_view str) constexpr noexcept

contract_violation_handler& rll::violation_handler()

Returns the current global contract violation handler.

Returns Mutable reference to the global contract violation handler.

Variable documentation

static nullopt_t rll::nullopt constexpr

Represents an empty optional.

template <typename... Args>
const_overload_t<Args...> rll::const_overload constexpr

template <typename T, typename... U>
bool rll::is_any_of_v constexpr

template <typename... Args>
non_const_overload_t<Args...> rll::non_const_overload constexpr

auto rll::none constexpr

Wrap an empty value in an optional.

This function is a helper for creating an optional from a value. It is mostly useful when working with generic code that needs to work with both expected and optional types.

template <typename... Args>
overload_t<Args...> rll::overload constexpr