From 83580a12c795486eed8914d96e1b79231992133f Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Fri, 11 May 2012 16:50:46 +0900 Subject: [PATCH] add sprout::shrink (convert from string to shorter string) --- sprout/range/adaptor/copied.hpp | 1 + sprout/range/adaptor/sinusoidal.hpp | 1 + sprout/range/adaptor/transformed.hpp | 2 + sprout/range/range_container.hpp | 2 +- sprout/string.hpp | 1 + sprout/string/shrink.hpp | 61 ++++++++++++++++++++++++++++ 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 sprout/string/shrink.hpp diff --git a/sprout/range/adaptor/copied.hpp b/sprout/range/adaptor/copied.hpp index c0a6cb2d..f38af518 100644 --- a/sprout/range/adaptor/copied.hpp +++ b/sprout/range/adaptor/copied.hpp @@ -25,6 +25,7 @@ namespace sprout { : public sprout::range::range_container< typename sprout::container_traits::iterator > + , public sprout::detail::container_nosy_static_size , public sprout::detail::container_nosy_fixed_size { public: diff --git a/sprout/range/adaptor/sinusoidal.hpp b/sprout/range/adaptor/sinusoidal.hpp index 733d36cf..99feec88 100644 --- a/sprout/range/adaptor/sinusoidal.hpp +++ b/sprout/range/adaptor/sinusoidal.hpp @@ -23,6 +23,7 @@ namespace sprout { : public sprout::range::range_container< sprout::sinusoid_iterator > + , public sprout::detail::container_nosy_static_size , public sprout::detail::container_nosy_fixed_size { public: diff --git a/sprout/range/adaptor/transformed.hpp b/sprout/range/adaptor/transformed.hpp index 4645f0cb..310a7530 100644 --- a/sprout/range/adaptor/transformed.hpp +++ b/sprout/range/adaptor/transformed.hpp @@ -28,6 +28,7 @@ namespace sprout { typename sprout::container_traits::iterator > > + , public sprout::detail::container_nosy_static_size , public sprout::detail::container_nosy_fixed_size { public: @@ -62,6 +63,7 @@ namespace sprout { typename sprout::container_traits::iterator > > + , public sprout::detail::container_nosy_static_size , public sprout::detail::container_nosy_fixed_size { public: diff --git a/sprout/range/range_container.hpp b/sprout/range/range_container.hpp index e15d594f..8de7f0d1 100644 --- a/sprout/range/range_container.hpp +++ b/sprout/range/range_container.hpp @@ -15,7 +15,7 @@ namespace sprout { // template struct range_container - : public sprout::container_traits + : public sprout::container_traits_facade { public: typedef Iterator iterator; diff --git a/sprout/string.hpp b/sprout/string.hpp index adb5236a..37c60bae 100644 --- a/sprout/string.hpp +++ b/sprout/string.hpp @@ -14,5 +14,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_STRING_HPP diff --git a/sprout/string/shrink.hpp b/sprout/string/shrink.hpp new file mode 100644 index 00000000..345c2ffc --- /dev/null +++ b/sprout/string/shrink.hpp @@ -0,0 +1,61 @@ +#ifndef SPROUT_STRING_SHRINK_HPP +#define SPROUT_STRING_SHRINK_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + // + // shrink_string + // + template > + class shrink_string { + public: + typedef sprout::basic_string string_type; + private: + typedef sprout::value_holder holder_type; + public: + typedef typename holder_type::param_type param_type; + private: + template + static SPROUT_CONSTEXPR sprout::basic_string implicit_conversion_impl( + T const(& elems)[M], + std::size_t len, + sprout::index_tuple + ) + { + return sprout::basic_string{{(Indexes < M - 1 ? elems[Indexes] : T())...}, len}; + } + private: + holder_type holder_; + public: + shrink_string(shrink_string const&) = default; + shrink_string(shrink_string&&) = default; + explicit SPROUT_CONSTEXPR shrink_string(param_type p) + : holder_(p) + {} + template + SPROUT_CONSTEXPR operator sprout::basic_string() const { + return implicit_conversion_impl( + holder_.get().elems, + holder_.get().len, + sprout::index_range<0, (N2 < N ? N2 : N)>::make() + ); + } + }; + + // + // shrink + // + template + SPROUT_CONSTEXPR sprout::shrink_string + shrink(sprout::basic_string const& s) { + return sprout::shrink_string(s); + } +} // namespace sprout + +#endif // #ifndef SPROUT_STRING_SHRINK_HPP