#ifndef SPROUT_UTILITY_STRING_REF_STRING_TO_FLOAT_HPP #define SPROUT_UTILITY_STRING_REF_STRING_TO_FLOAT_HPP #include #include #include #include #include #include namespace sprout { namespace detail { template< typename FloatType, typename Elem, typename Traits > inline FloatType string_to_float_dynamic(sprout::basic_string_ref const& str, std::size_t* idx) { Elem* endptr = nullptr; FloatType result = sprout::detail::str_to_float(str.c_str(), &endptr); *idx = endptr - str.c_str(); return result; } } // // string_to_float // template< typename FloatType, typename Elem, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType string_to_float(sprout::basic_string_ref const& str, std::size_t* idx) { return !idx ? sprout::detail::str_to_float(str.begin()) : sprout::detail::string_to_float_dynamic(str, idx) ; } template< typename FloatType, typename Elem, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType string_to_float(sprout::basic_string_ref const& str) { return sprout::detail::str_to_float(str.begin()); } // // stof // template inline SPROUT_CONSTEXPR float stof(sprout::basic_string_ref const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template inline SPROUT_CONSTEXPR float stof(sprout::basic_string_ref const& str) { return sprout::string_to_float(str); } // // stod // template inline SPROUT_CONSTEXPR double stod(sprout::basic_string_ref const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template inline SPROUT_CONSTEXPR double stod(sprout::basic_string_ref const& str) { return sprout::string_to_float(str); } // // stold // template inline SPROUT_CONSTEXPR long double stold(sprout::basic_string_ref const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template inline SPROUT_CONSTEXPR long double stold(sprout::basic_string_ref const& str) { return sprout::string_to_float(str); } // // from_string // template< typename FloatType, typename Elem, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType from_string(sprout::basic_string_ref const& str, std::size_t* idx) { return sprout::string_to_float(str, idx); } template< typename FloatType, typename Elem, typename Traits, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType from_string(sprout::basic_string_ref const& str) { return sprout::string_to_float(str); } } // namespace sprout #endif // #ifndef SPROUT_UTILITY_STRING_REF_STRING_TO_FLOAT_HPP