view: add trim_if
This commit is contained in:
parent
71d350b29c
commit
eb89ddcd53
23
view.hpp
23
view.hpp
@ -727,6 +727,29 @@ namespace cruft {
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename BeginT, typename EndT, typename FunctionT>
|
||||
view<BeginT, EndT>
|
||||
trim_if [[nodiscard]] (
|
||||
view<BeginT, EndT> const buffer,
|
||||
FunctionT &&test
|
||||
) {
|
||||
auto const first = std::find_if_not (
|
||||
std::begin (buffer),
|
||||
std::end (buffer),
|
||||
test
|
||||
);
|
||||
|
||||
auto const last = std::find_if_not (
|
||||
std::make_reverse_iterator (buffer.end ()),
|
||||
std::make_reverse_iterator (first),
|
||||
test
|
||||
);
|
||||
|
||||
return view (first, last.base ());
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// Returns a reference to a value of the designated type at the front of
|
||||
/// the word-view. if there is insufficient data for the extraction an
|
||||
|
Loading…
Reference in New Issue
Block a user