werkzeugkiste::config::detail namespace

Internal implementation namespace.

Contents

Functions

template<typename T, typename S, typename E>
auto sign_aware_integral_cast(const S value, std::false_type, std::true_type, bool may_throw) -> std::optional<T>
Helper to cast from a SIGNED to an UNSIGNED integral value.
template<typename T, typename S, typename E>
auto sign_aware_integral_cast(const S value, std::false_type, std::false_type, bool may_throw) -> std::optional<T>
Helper to cast from an UNSIGNED to a SIGNED integral value.
template<typename T, typename S, typename E>
auto integral_cast(const S value, std::false_type, bool may_throw) -> std::optional<T>
Helper/dispatcher to cast between integral types of DIFFERENT SIGNS.
template<typename T, typename S, typename E>
auto integral_cast(const S value, std::true_type, bool may_throw) -> std::optional<T>
Helper to cast between integral types of the SAME SIGN.
template<typename T, typename S, typename E>
auto int_to_int(const S value, bool may_throw) -> std::optional<T> constexpr
Dispatcher to cast between integral types.
template<typename T, typename S, typename E>
auto float_to_float(S value, bool may_throw) -> std::optional<T>
Helper to cast between floating point types.
template<typename T>
auto pow2(int exp) -> T constexpr
A constexpr-compatible computation of $2^exp$.
template<typename T, typename S>
auto float_to_int_range() -> std::pair<S, S> constexpr
Returns the value range for the floating point to integer cast.
template<typename T, typename S, typename E>
auto float_to_int_unchecked(S value, bool may_throw) -> std::optional<T>
Helper that converts a floating point to integral and back in order to check if the conversion is lossless. Performs no additional sanity checks.
template<typename T, typename S, typename E>
auto float_to_int(S value, bool may_throw) -> std::optional<T>
Helper to cast from floating point to integral types.
template<typename T, typename S, typename E>
auto int_to_float_unchecked(S value, bool may_throw) -> std::optional<T>
Internal helper to convert an integer to floating point and back in order to check if the cast is lossless. Performs no additional sanity checks.
template<typename T, typename S, typename E>
auto int_to_float(S value, bool may_throw) -> std::optional<T>
Helper to cast from integral to floating point types.
template<typename T, typename S, typename E = std::domain_error>
auto numcast(const S value, const bool may_throw) -> std::optional<T> constexpr
Dispatcher to cast a number from source type S to target type T.

Function documentation

template<typename T, typename S>
std::pair<S, S> werkzeugkiste::config::detail::float_to_int_range() constexpr

Returns the value range for the floating point to integer cast.

Returns

Returns the <min,max> pair, such that:

  • min is the lowest floating point value which will not underflow when converted to T (integral).
  • max is the lowest floating point value which will overflow when converted to T (integral).

template<typename T, typename S, typename E = std::domain_error>
std::optional<T> werkzeugkiste::config::detail::numcast(const S value, const bool may_throw) constexpr

Dispatcher to cast a number from source type S to target type T.

Template parameters
T Target type.
S Source type.
E Exception type to be thrown if may_throw is true.
Parameters
value The value to be cast.
may_throw If true, an exception E will be thrown for invalid casts, i.e. for values which are not exactly representable by the target type. If false, no exception will be thrown and the validity of the cast can be checked via the optional return value.