44 typename std::enable_if_t<std::is_integral<T>::value, T>
48 bool overflow = __builtin_add_overflow(x, y, &result);
54 return std::numeric_limits<T>::min();
56 return std::numeric_limits<T>::max();
67template <
typename To,
typename From>
69 typename std::enable_if_t<
sizeof(To) ==
sizeof(From) &&
70 std::is_trivially_copyable<To>::value &&
71 std::is_trivially_copyable<From>::value,
74 static_assert(std::is_trivially_constructible<To>::value,
75 "This implementation additionally requires "
76 "destination type to be trivially constructible");
79 std::memcpy(&dst, &src,
sizeof(To));
88#if __cplusplus < 202002L
95#if __cplusplus <= 202302L
auto add_sat(T x, T y) noexcept -> typename std::enable_if_t< std::is_integral< T >::value, T >
Computes the saturating addition x + y for integral types.
auto bit_cast(const From &src) noexcept -> typename std::enable_if_t< sizeof(To)==sizeof(From) &&std::is_trivially_copyable< To >::value &&std::is_trivially_copyable< From >::value, To >
Obtain a value of type To by reinterpreting the object representation of From.