diff --git a/libs/string/test/string.cpp b/libs/string/test/string.cpp index 708e3b59..e8152208 100644 --- a/libs/string/test/string.cpp +++ b/libs/string/test/string.cpp @@ -74,6 +74,14 @@ namespace testspr { SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(cstr, cstr + 6); TESTSPR_BOTH_ASSERT(s1 == "foobar"); } + { + SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(6, 'f'); + TESTSPR_BOTH_ASSERT(s1 == "ffffff"); + } + { + SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(6, int('f')); + TESTSPR_BOTH_ASSERT(s1 == "ffffff"); + } { SPROUT_STATIC_CONSTEXPR auto s1 = sprout::string_t<10>::type(testspr::reduct_input(str1.begin()), testspr::reduct_input(str1.begin() + 6)); TESTSPR_BOTH_ASSERT(s1 == "foobar"); diff --git a/sprout/string/string.hpp b/sprout/string/string.hpp index 48d72388..e537738d 100644 --- a/sprout/string/string.hpp +++ b/sprout/string/string.hpp @@ -21,12 +21,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -342,7 +344,20 @@ namespace sprout { sprout::detail::string_checked_construct_t(), s, 0, NS_SSCRISK_CEL_OR_SPROUT::min(n, traits_type::length(s)) ) {} - template + SPROUT_CONSTEXPR basic_string(size_type n, value_type c) + : impl_type( + sprout::make_index_tuple::make(), + sprout::detail::string_checked_construct_t(), sprout::value_iterator(c), 0, n + ) + {} + template::value>::type = sprout::enabler> + SPROUT_CONSTEXPR basic_string(InputIterator first, InputIterator last) + : impl_type( + sprout::make_index_tuple::make(), + sprout::detail::string_checked_construct_t(), sprout::value_iterator(last), 0, first + ) + {} + template::value>::type = sprout::enabler> SPROUT_CONSTEXPR basic_string(InputIterator first, InputIterator last) : impl_type( sprout::make_index_tuple::make(), @@ -708,9 +723,7 @@ namespace sprout { } SPROUT_CONSTEXPR basic_string substr(size_type pos = 0, size_type n = npos) const { - return !(size() < pos) ? n == npos - ? substr(pos, size() - pos) - : from_c_str(c_str() + pos, n) + return !(size() < pos) ? from_c_str(c_str() + pos, NS_SSCRISK_CEL_OR_SPROUT::min(n, size() - pos)) : throw std::out_of_range("basic_string<>: index out of range") ; }