#ifndef SPROUT_STRING_INT_TO_STRING_HPP #define SPROUT_STRING_INT_TO_STRING_HPP #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, typename... Args, typename sprout::enabler_if<(sizeof...(Args) == sprout::printed_integer_digits::value - 1)>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> int_to_string_impl_1(IntType val, bool negative, Args... args) { return negative ? sprout::make_string_as(static_cast('-'), args...) : sprout::make_string_as(args...) ; } template< typename Elem, int Base, typename IntType, typename... Args, typename sprout::enabler_if<(sizeof...(Args) < sprout::printed_integer_digits::value - 1)>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> int_to_string_impl_1(IntType val, bool negative, Args... args) { return val == 0 ? (negative ? sprout::make_string_as(static_cast('-'), args...) : sprout::make_string_as(args...) ) : sprout::detail::int_to_string_impl_1( val / Base, negative, sprout::detail::int_to_char(negative ? -(val % Base) : val % Base, Base), args... ) ; } template inline SPROUT_CONSTEXPR sprout::basic_string::value> int_to_string_impl(IntType val) { return val == 0 ? sprout::make_string_as(static_cast('0')) : sprout::detail::int_to_string_impl_1(val, val < 0) ; } template< typename Elem, int Base, typename UIntType, typename... Args, typename sprout::enabler_if<(sizeof...(Args) == sprout::printed_integer_digits::value)>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> uint_to_string_impl_1(UIntType val, Args... args) { return sprout::make_string_as(args...); } template< typename Elem, int Base, typename UIntType, typename... Args, typename sprout::enabler_if<(sizeof...(Args) < sprout::printed_integer_digits::value)>::type = sprout::enabler > inline SPROUT_CONSTEXPR sprout::basic_string::value> uint_to_string_impl_1(UIntType val, Args... args) { return val == 0 ? sprout::make_string_as(args...) : sprout::detail::uint_to_string_impl_1( val / Base, sprout::detail::int_to_char(val % Base, Base), args... ) ; } template inline SPROUT_CONSTEXPR sprout::basic_string::value> uint_to_string_impl(UIntType val) { return val == 0 ? sprout::make_string_as(static_cast('0')) : sprout::detail::uint_to_string_impl_1(val) ; } 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_impl(val); } 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::uint_to_string_impl(val); } } // 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); } // // 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