#ifndef SPROUT_STRING_INT_TO_STRING_HPP #define SPROUT_STRING_INT_TO_STRING_HPP #include #include #include #include #include #include #include #include #include namespace sprout { // // printed_integer_digits // template struct printed_integer_digits : public std::integral_constant< std::size_t, sprout::integer_digits::value + (std::is_signed::value ? 1 : 0) > {}; namespace detail { template< typename Elem, int Base, typename IntType, sprout::index_t... Indexes, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> int_to_string(IntType val, int digits, sprout::index_tuple) { return val < 0 ? sprout::basic_string::value>{ { static_cast('-'), (Indexes < digits ? sprout::detail::int_to_char(sprout::detail::int_digit_at(val, digits - 1 - Indexes)) : Elem() )... }, static_cast(digits + 1) } : sprout::basic_string::value>{ { (Indexes < digits ? sprout::detail::int_to_char(sprout::detail::int_digit_at(val, digits - 1 - Indexes)) : Elem() )... }, static_cast(digits) } ; } template< typename Elem, int Base, typename IntType, sprout::index_t... Indexes, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> int_to_string(IntType val, int digits, sprout::index_tuple) { return sprout::basic_string::value>{ { (Indexes < digits ? sprout::detail::int_to_char(sprout::detail::int_digit_at(val, digits - 1 - Indexes)) : Elem() )... }, static_cast(digits) }; } } // namespace detail // // int_to_string // template< typename Elem, int Base = 10, typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> int_to_string(IntType val) { return sprout::detail::int_to_string( val, sprout::detail::int_digits(val), sprout::index_range<0, sprout::integer_digits::value>::make() ); } // // to_string_of // template< typename Elem, typename IntType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> to_string_of(IntType val) { return sprout::int_to_string(val); } // // to_string // template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_string(IntType val) { return sprout::to_string_of(val); } // // to_wstring // template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_wstring(IntType val) { return sprout::to_string_of(val); } // // to_u16string // template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_u16string(IntType val) { return sprout::to_string_of(val); } // // to_u32string // template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_u32string(IntType val) { return sprout::to_string_of(val); } } // namespace sprout #endif // #ifndef SPROUT_STRING_INT_TO_STRING_HPP