19 #ifndef PSTORE_SUPPORT_UNSIGNED_CAST_HPP 20 #define PSTORE_SUPPORT_UNSIGNED_CAST_HPP 26 template <
typename SrcT,
typename DestT = std::make_
unsigned_t<
typename std::remove_cv_t<SrcT>>,
27 typename =
typename std::enable_if<std::is_
integral<SrcT>::value &&
28 std::is_
unsigned<DestT>::value>::type>
29 constexpr DestT unsigned_cast (SrcT
const value) noexcept {
31 std::numeric_limits<DestT>::max () >=
32 std::numeric_limits<std::make_unsigned_t<
typename std::remove_cv_t<SrcT>>>::max (),
33 "DestT cannot hold all of the values of SrcT");
34 PSTORE_ASSERT (value >= SrcT{0});
35 return static_cast<DestT
> (value);
38 template <
typename SrcT,
typename DestT = std::make_
unsigned_t<
typename std::remove_cv_t<SrcT>>,
39 typename =
typename std::enable_if<std::is_
integral<SrcT>::value &&
40 std::is_
unsigned<DestT>::value>::type>
41 constexpr DestT checked_unsigned_cast (SrcT
const value) {
42 if (value < SrcT{0}) {
43 raise (std::errc::invalid_argument,
"bad cast to unsigned");
45 return unsigned_cast<SrcT, DestT> (value);
50 #endif // PSTORE_SUPPORT_UNSIGNED_CAST_HPP Definition: nonpod2.cpp:40
Provides an pstore-specific error codes and a suitable error category for them.