1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

add SPROUT_ASSERT

This commit is contained in:
bolero-MURAKAMI 2013-03-18 19:12:21 +09:00
parent a5e14e71e1
commit 07f052fb6e
32 changed files with 386 additions and 284 deletions

View file

@ -5,22 +5,23 @@
#include <stdexcept>
#include <sprout/config.hpp>
#include <sprout/ctype/ascii.hpp>
#include <sprout/assert.hpp>
namespace sprout {
namespace detail {
template<typename Elem, typename IntType>
inline SPROUT_CONSTEXPR Elem
int_to_char(IntType val, int base) {
return val >= 0 && val < 10 ? static_cast<Elem>('0') + val
: val >= 10 && val < static_cast<IntType>(base) ? static_cast<Elem>('a') + (val - 10)
: throw std::invalid_argument("value out of bounds")
return SPROUT_ASSERT(2 <= base && base <= 36), SPROUT_ASSERT(IntType(0) <= val && val < static_cast<IntType>(base)),
val < 10 ? static_cast<Elem>('0') + val
: static_cast<Elem>('a') + (val - 10)
;
}
template<typename Elem, typename IntType>
inline SPROUT_CONSTEXPR Elem
int_to_char(IntType val) {
return val >= 0 && val < 10 ? static_cast<Elem>('0') + val
: throw std::invalid_argument("value out of bounds")
return SPROUT_ASSERT(IntType(0) <= val && val < IntType(10)),
static_cast<Elem>('0') + val
;
}