1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-10-05 13:00:00 +00:00

add from_string, stol, stoul, stod, and more...

This commit is contained in:
bolero-MURAKAMI 2012-04-16 13:32:47 +09:00
commit c901c3058a
9 changed files with 554 additions and 270 deletions

View file

@ -231,7 +231,9 @@ namespace sprout {
template<typename FloatType, typename CStrIterator, typename CharPtr>
inline SPROUT_CONSTEXPR FloatType str_to_float(CStrIterator str, CharPtr* endptr) {
return !endptr ? sprout::detail::str_to_float<FloatType>(str)
: std::strtod(str, endptr)
: std::is_same<typename std::remove_cv<FloatType>::type, float>::value ? std::strtof(&*str, endptr)
: std::is_same<typename std::remove_cv<FloatType>::type, double>::value ? std::strtod(&*str, endptr)
: std::strtold(&*str, endptr)
;
}
} // namespace detail

View file

@ -81,7 +81,11 @@ namespace sprout {
template<typename IntType, typename CStrIterator, typename CharPtr>
inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, CharPtr* endptr, int base) {
return !endptr ? sprout::detail::str_to_int<IntType>(str, base)
: std::strtol(str, endptr, base)
: std::is_signed<IntType>::value
? sizeof(IntType) <= sizeof(long) ? static_cast<IntType>(std::strtol(&*str, endptr, base))
: static_cast<IntType>(std::strtoll(&*str, endptr, base))
: sizeof(IntType) <= sizeof(unsigned long) ? static_cast<IntType>(std::strtoul(&*str, endptr, base))
: static_cast<IntType>(std::strtoull(&*str, endptr, base))
;
}
} // namespace detail