Example #1
0
 static constexpr int_type check_valid_(OtherType val) {
     //If Max or Min doesn't fit into OtherType, then clearly val cannot exceed that boundary
     //(and the check code would be incorrect, so we can and *must* not do it).
     //static const bool other_is_floating_point = !std::numeric_limits<OtherType>::is_exact;
     return
     constexpr_require_and_return(
         (!std::numeric_limits<OtherType>::is_exact /*other_is_floating_point*/
          ? (val <= OtherType(Max) && Int(val) <= Max)
                  : (Int(OtherType(Max)) == Max && (Max >= Int(0)) == (OtherType(Max) >= OtherType(0)))
                  ? (val <= OtherType(Max))
                     : (Max >= Int(0))),
                  "bounds_checked_int overflow",
                  constexpr_require_and_return(
                      (!std::numeric_limits<OtherType>::is_exact /*other_is_floating_point*/
                       ? (val >= OtherType(Min) && Int(val) >= Min)
                       : (Int(OtherType(Min)) == Min && (Min >= Int(0)) == (OtherType(Min) >= OtherType(0)))
                       ? (val >= OtherType(Min))
                       : (Min < Int(0))),
                       "bounds_checked_int underflow",
                       static_cast<int_type>(val)));
 }
Example #2
0
 constexpr char operator[](size_t i)const {
   return constexpr_require_and_return(i < info::data_len, "bounds overflow", buf_[i]);
 }