/*============================================================================= Copyright (c) 2011-2013 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_SHRINK_HPP #define SPROUT_STRING_SHRINK_HPP #include #include #include #include #include #include #include HDR_ALGORITHM_MIN_MAX_SSCRISK_CEL_OR_SPROUT namespace sprout { // // shrink_string // template > class shrink_string { public: typedef sprout::basic_string string_type; private: typedef sprout::value_holder holder_type; private: template static SPROUT_CONSTEXPR sprout::basic_string implicit_conversion_impl( string_type const& str, std::size_t len, sprout::index_tuple ) { typedef sprout::detail::string_construct_access access_type; return access_type::raw_construct(len, (Indexes < N ? str[Indexes] : T())...); } private: holder_type holder_; public: shrink_string(shrink_string const&) = default; shrink_string(shrink_string&&) = default; SPROUT_CONSTEXPR shrink_string(string_type const& s) : holder_(s) {} SPROUT_CONSTEXPR operator string_type const&() const { return holder_.get(); } template SPROUT_CONSTEXPR operator sprout::basic_string() const { return implicit_conversion_impl( holder_.get(), NS_SSCRISK_CEL_OR_SPROUT::min(N2, holder_.get().size()), sprout::make_index_tuple<(N < N2 ? N : N2)>::make() ); } }; // // shrink // template inline SPROUT_CONSTEXPR sprout::shrink_string shrink(sprout::basic_string const& s) { return sprout::shrink_string(s); } template inline SPROUT_CONSTEXPR sprout::basic_string shrink(sprout::basic_string const& s) { return sprout::shrink(s); } template inline SPROUT_CONSTEXPR sprout::shrink_string shrink(T const(& arr)[N]) { return sprout::shrink(sprout::to_string(arr)); } template inline SPROUT_CONSTEXPR sprout::basic_string shrink(T const(& arr)[N]) { return sprout::shrink(sprout::to_string(arr)); } } // namespace sprout #endif // #ifndef SPROUT_STRING_SHRINK_HPP