Implement erase_if function and related tests

This commit is contained in:
m-peko
2020-11-25 12:00:31 +01:00
committed by Krystian Stasiowski
parent 59c4c556bb
commit 3a1efd2078
3 changed files with 73 additions and 0 deletions

View File

@ -5614,6 +5614,31 @@ operator+(
std::size_t(0), +lhs);
}
//------------------------------------------------------------------------------
//
// erase_if
//
//------------------------------------------------------------------------------
template<
std::size_t N, typename CharT,
typename Traits, typename UnaryPredicate>
BOOST_STATIC_STRING_CPP14_CONSTEXPR
typename
basic_static_string<N, CharT, Traits>::size_type
erase_if(
basic_static_string<N, CharT, Traits>& str,
UnaryPredicate pred)
{
auto first = str.begin();
for (auto it = first; it != str.end(); ++it)
if (!pred(*it))
*first++ = std::move(*it);
const auto count = str.end() - first;
str.erase(first, str.end());
return count;
}
//------------------------------------------------------------------------------
//
// swap