view: add trim_if

This commit is contained in:
Danny Robson 2021-11-20 05:58:35 +10:00
parent 71d350b29c
commit eb89ddcd53

View File

@ -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 /// 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 /// the word-view. if there is insufficient data for the extraction an