diff --git a/sprout/string/concat.hpp b/sprout/string/concat.hpp index c88cf17e..3b19d15f 100644 --- a/sprout/string/concat.hpp +++ b/sprout/string/concat.hpp @@ -4,64 +4,163 @@ #include #include #include +#include +#include #include -#include -#include -#include -#include +//#include +//#include +//#include +//#include namespace sprout { + namespace detail { + template + inline SPROUT_CONSTEXPR sprout::basic_string + string_concat( + sprout::basic_string const& lhs, + std::size_t lsize, + T const& rhs, + sprout::index_tuple + ) + { + return sprout::basic_string{ + { + (Indexes < lsize ? lhs[Indexes] + : Indexes < lsize + 1 ? rhs + : T() + )... + }, + lsize + 1 + }; + } + template + inline SPROUT_CONSTEXPR sprout::basic_string + string_concat( + T const& lhs, + sprout::basic_string const& rhs, + std::size_t rsize, + sprout::index_tuple + ) + { + return sprout::basic_string{ + { + (Indexes < 1 ? lhs + : Indexes < 1 + rsize ? rhs[Indexes - 1] + : T() + )... + }, + 1 + rsize + }; + } + template + inline SPROUT_CONSTEXPR sprout::basic_string + string_concat( + sprout::basic_string const& lhs, + std::size_t lsize, + T const (& rhs)[M], + std::size_t rsize, + sprout::index_tuple + ) + { + return sprout::basic_string{ + { + (Indexes < lsize ? lhs[Indexes] + : Indexes < lsize + rsize ? rhs[Indexes - lsize] + : T() + )... + }, + lsize + rsize + }; + } + template + inline SPROUT_CONSTEXPR sprout::basic_string + string_concat( + T const (& lhs)[M], + std::size_t lsize, + sprout::basic_string const& rhs, + std::size_t rsize, + sprout::index_tuple + ) + { + return sprout::basic_string{ + { + (Indexes < lsize ? lhs[Indexes] + : Indexes < lsize + rsize ? rhs[Indexes - lsize] + : T() + )... + }, + lsize + rsize + }; + } + template + inline SPROUT_CONSTEXPR sprout::basic_string + string_concat( + sprout::basic_string const& lhs, + std::size_t lsize, + sprout::basic_string const& rhs, + std::size_t rsize, + sprout::index_tuple + ) + { + return sprout::basic_string{ + { + (Indexes < lsize ? lhs[Indexes] + : Indexes < lsize + rsize ? rhs[Indexes - lsize] + : T() + )... + }, + lsize + rsize + }; + } + } // namespace detail + // // operator+ // template - inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::push_back, T>::type operator+( - sprout::basic_string const& lhs, - T const& rhs - ) - { - return sprout::fixed::push_back(lhs, rhs); + inline SPROUT_CONSTEXPR sprout::basic_string + operator+(sprout::basic_string const& lhs, T const& rhs) { + return sprout::detail::string_concat( + lhs, lhs.size(), + rhs, + sprout::index_range<0, N + 1>::make() + ); } template - inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::push_front, T>::type operator+( - T const& lhs, - sprout::basic_string const& rhs - ) - { - return sprout::fixed::push_front(rhs, lhs); + inline SPROUT_CONSTEXPR sprout::basic_string + operator+(T const& lhs, sprout::basic_string const& rhs) { + return sprout::detail::string_concat( + lhs, + rhs, rhs.size(), + sprout::index_range<0, 1 + N>::make() + ); } - template - inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::append_back< - sprout::basic_string, - sprout::basic_string - >::type operator+( - sprout::basic_string const& lhs, - T const (& rhs)[N2] - ) - { - return sprout::fixed::append_back(lhs, sprout::to_string(rhs)); + template + inline SPROUT_CONSTEXPR sprout::basic_string + operator+(sprout::basic_string const& lhs, T const (& rhs)[M]) { + return sprout::detail::string_concat( + lhs, lhs.size(), + rhs, sprout::char_traits::length(rhs), + sprout::index_range<0, N + (M - 1)>::make() + ); } - template - inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::append_front< - sprout::basic_string, - sprout::basic_string - >::type operator+( - T const (& lhs)[N2], - sprout::basic_string const& rhs - ) - { - return sprout::fixed::append_front(rhs, sprout::to_string(lhs)); + template + inline SPROUT_CONSTEXPR sprout::basic_string + operator+(T const (& lhs)[M], sprout::basic_string const& rhs) { + return sprout::detail::string_concat( + lhs, sprout::char_traits::length(lhs), + rhs, rhs.size(), + sprout::index_range<0, (M - 1) + N>::make() + ); } - template - inline SPROUT_CONSTEXPR typename sprout::fixed::result_of::append_back< - sprout::basic_string, - sprout::basic_string - >::type operator+( - sprout::basic_string const& lhs, - sprout::basic_string const& rhs - ) - { - return sprout::fixed::append_back(lhs, rhs); + template + inline SPROUT_CONSTEXPR sprout::basic_string + operator+(sprout::basic_string const& lhs, sprout::basic_string const& rhs) { + return sprout::detail::string_concat( + lhs, lhs.size(), + rhs, rhs.size(), + sprout::index_range<0, N1 + N2>::make() + ); } } // namespace sprout