#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, 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::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_string_of(IntType val) { return sprout::int_to_string(val); } // // to_string // // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_string(int val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_string(unsigned val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_string(long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_string(unsigned long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_string(long long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_string(unsigned long long val) { // return sprout::to_string_of(val); // } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_string(IntType val) { return sprout::to_string_of(val); } // // to_wstring // // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_wstring(int val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_wstring(unsigned val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_wstring(long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_wstring(unsigned long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_wstring(long long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_wstring(unsigned long long val) { // return sprout::to_string_of(val); // } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_wstring(IntType val) { return sprout::to_string_of(val); } // // to_u16string // // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u16string(int val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u16string(unsigned val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u16string(long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u16string(unsigned long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u16string(long long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u16string(unsigned long long val) { // return sprout::to_string_of(val); // } template::value>::type = sprout::enabler> inline SPROUT_CONSTEXPR sprout::basic_string::value> to_u16string(IntType val) { return sprout::to_string_of(val); } // // to_u32string // // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u32string(int val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u32string(unsigned val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u32string(long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u32string(unsigned long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u32string(long long val) { // return sprout::to_string_of(val); // } // inline SPROUT_CONSTEXPR sprout::basic_string::value> // to_u32string(unsigned long long val) { // return sprout::to_string_of(val); // } 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