/*============================================================================= Copyright (c) 2011-2014 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_STRING_INT_TO_STRING_HPP #define SPROUT_STRING_INT_TO_STRING_HPP #include #include #include #include #include #include #include #include #include #include namespace sprout { // // printed_integer_digits // template struct printed_integer_digits : public sprout::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) { typedef sprout::detail::string_construct_access::value> access_type; return val < 0 ? access_type::raw_construct( static_cast(digits + 1), static_cast('-'), (Indexes < digits ? sprout::detail::int_to_char(sprout::detail::int_digit_at(val, digits - 1 - Indexes)) : Elem() )... ) : access_type::raw_construct( static_cast(digits), (Indexes < digits ? sprout::detail::int_to_char(sprout::detail::int_digit_at(val, digits - 1 - Indexes)) : Elem() )... ) ; } 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) { typedef sprout::detail::string_construct_access::value> access_type; return access_type::raw_construct( static_cast(digits), (Indexes < digits ? sprout::detail::int_to_char(sprout::detail::int_digit_at(val, digits - 1 - Indexes)) : Elem() )... ); } } // 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::make_index_tuple::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