From 8a4fca3aec9cf076635d216f902465f78a7dad19 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 21 Mar 2016 15:32:43 +0900 Subject: [PATCH] fix copy_backward implementation --- sprout/algorithm/cxx14/copy_backward.hpp | 2 +- sprout/string/char_traits.hpp | 4 ++-- sprout/string/shift_concat.hpp | 8 ++++---- sprout/string/string.hpp | 6 ++++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sprout/algorithm/cxx14/copy_backward.hpp b/sprout/algorithm/cxx14/copy_backward.hpp index ed1652e6..a821fe3d 100644 --- a/sprout/algorithm/cxx14/copy_backward.hpp +++ b/sprout/algorithm/cxx14/copy_backward.hpp @@ -23,7 +23,7 @@ namespace sprout { inline SPROUT_CXX14_CONSTEXPR BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, BidirectionalIterator2 result) { while (first != last) { - *--result = *--first; + *--result = *--last; } return result; } diff --git a/sprout/string/char_traits.hpp b/sprout/string/char_traits.hpp index 14d751bc..5e3cbe76 100644 --- a/sprout/string/char_traits.hpp +++ b/sprout/string/char_traits.hpp @@ -113,7 +113,7 @@ namespace sprout { ); } static SPROUT_CXX14_CONSTEXPR char_type* move(char_type* s1, char_type const* s2, std::size_t n) { - sprout::copy_backward(s2, s2 + n, s1); + sprout::copy_backward(s2, s2 + n, s1 + n); return s1; } static SPROUT_CXX14_CONSTEXPR char_type* copy(char_type* s1, char_type const* s2, std::size_t n) { @@ -199,7 +199,7 @@ namespace sprout { } template static SPROUT_CXX14_CONSTEXPR OutputIterator move(OutputIterator s1, ConstInputIterator s2, std::size_t n) { - sprout::copy_backward(s2, s2 + n, s1); + sprout::copy_backward(s2, s2 + n, s1 + n); return s1; } template diff --git a/sprout/string/shift_concat.hpp b/sprout/string/shift_concat.hpp index 10a9c691..bcef6ae6 100644 --- a/sprout/string/shift_concat.hpp +++ b/sprout/string/shift_concat.hpp @@ -162,13 +162,14 @@ namespace sprout { )... ); } + } // namespace detail // // operator>> // template inline SPROUT_CONSTEXPR sprout::basic_string operator>>(sprout::basic_string const& lhs, T const& rhs) { - return sprout::detail::string_rshift( + return sprout::detail::string_lshift( lhs, lhs.size(), rhs, sprout::make_index_tuple::make() @@ -178,7 +179,7 @@ namespace sprout { inline SPROUT_CONSTEXPR sprout::basic_string operator>>(sprout::basic_string const& lhs, T const (& rhs)[M]) { typedef sprout::char_traits_helper traits_type; - return sprout::detail::string_rshift( + return sprout::detail::string_lshift( lhs, lhs.size(), rhs, traits_type::length(rhs, M - 1), sprout::make_index_tuple::make() @@ -187,13 +188,12 @@ namespace sprout { template inline SPROUT_CONSTEXPR sprout::basic_string operator>>(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { - return sprout::detail::string_rshift( + return sprout::detail::string_lshift( lhs, lhs.size(), rhs, rhs.size(), sprout::make_index_tuple::make() ); } - } // namespace detail } // namespace sprout #endif // #ifndef SPROUT_STRING_SHIFT_CONCAT_HPP diff --git a/sprout/string/string.hpp b/sprout/string/string.hpp index 95b04299..5e06e77f 100644 --- a/sprout/string/string.hpp +++ b/sprout/string/string.hpp @@ -982,7 +982,8 @@ namespace sprout { } template SPROUT_CXX14_CONSTEXPR basic_string& operator<<=(T const (& rhs)[M]) { - std::size_t rsize = traits_type::length(rhs, M - 1); + typedef sprout::char_traits_helper helper_type; + std::size_t rsize = helper_type::length(rhs, M - 1); lengthcheck(size() + rsize); traits_type::copy(end(), rhs, rsize); put_terminator(impl_.len + rsize); @@ -1004,7 +1005,8 @@ namespace sprout { } template SPROUT_CXX14_CONSTEXPR basic_string& operator>>=(T const (& rhs)[M]) { - std::size_t rsize = traits_type::length(rhs, M - 1); + typedef sprout::char_traits_helper helper_type; + std::size_t rsize = helper_type::length(rhs, M - 1); lengthcheck(size() + rsize); traits_type::move(begin() + rsize, begin(), size()); traits_type::copy(begin(), rhs, rsize);