#ifndef SPROUT_STRING_STRING_TO_INT_HPP #define SPROUT_STRING_STRING_TO_INT_HPP #include #include #include #include #include #include #include namespace sprout { namespace detail { template< typename IntType, typename Elem, std::size_t N, typename Traits > inline IntType string_to_int_dynamic(sprout::basic_string const& str, std::size_t* idx, int base = 10) { Elem* endptr = nullptr; IntType result = sprout::detail::str_to_int(str.c_str(), &endptr, base); *idx = endptr - str.c_str(); return result; } } // // string_to_int // template< typename IntType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType string_to_int(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return !idx ? sprout::detail::str_to_int(str.begin(), base) : sprout::detail::string_to_int_dynamic(str, idx, base) ; } template< typename IntType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType string_to_int(sprout::basic_string const& str, int base = 10) { return sprout::detail::str_to_int(str.begin(), base); } // // stoi // template inline SPROUT_CONSTEXPR int stoi(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR int stoi(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } // // stol // template inline SPROUT_CONSTEXPR long stol(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR long stol(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } // // stoul // template inline SPROUT_CONSTEXPR unsigned long stoul(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR unsigned long stoul(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } // // stoll // template inline SPROUT_CONSTEXPR long long stoll(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR long long stoll(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } // // stoull // template inline SPROUT_CONSTEXPR unsigned long long stoull(sprout::basic_string const& str, std::size_t* idx, int base = 10) { return sprout::string_to_int(str, idx, base); } template inline SPROUT_CONSTEXPR unsigned long long stoull(sprout::basic_string const& str, int base = 10) { return sprout::string_to_int(str, base); } // // from_string // template< typename IntType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType from_string(sprout::basic_string const& str, std::size_t* idx) { return sprout::string_to_int(str, idx); } template< typename IntType, typename Elem, std::size_t N, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR IntType from_string(sprout::basic_string const& str) { return sprout::string_to_int(str); } } // namespace sprout #endif // #ifndef SPROUT_STRING_STRING_TO_INT_HPP