What is the effect of pipe operator in C ++ boost :: adapters :: filter?

The boost::adaptors::filteredfilterlike function is used:

std::vector<int> input;
input += 1,2,3,4,5,6,7,8,9;

boost::copy(
        input | filtered(is_even()),
        std::ostream_iterator<int>(std::cout, ","));

What is the effect of the pipe operator in this case? This is not defined for std::vector, is it overload? If so, how to effectively search for such operators in libraires, such as boost?

+4
source share
1 answer

This is the Boost Range Adapter . In this one more documentation was recorded. > "Boost C ++ Libraries" .

There are many such ranges that can be composed to write a high-level functional effect. Examples here:

filtered

input | filtered(is_even()) :

boost::range_detail::filtered_range<is_even, std::vector<int> >

Range (input), (is_even()).

, , , . :

is_even predicate;
for (auto const& i : input)
    if (predicate(i))
        std::cout << i << ",";

range | adaptor - , .

/ |?

", ". , filtered(is_even()) boost::range_detail::filter_holder<is_even>, operator |:

template< class SinglePassRange, class Predicate >
inline filtered_range<Predicate, SinglePassRange>
operator|(SinglePassRange& r,
          const filter_holder<Predicate>& f)
{
    BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange>));
    return filtered_range<Predicate, SinglePassRange>( f.val, r );
}

. . , " rng " , ( ).

+ = 1,2,.... - user463035818 56

Boost Assign, , , ++ 11 ,

std::vector<int> input { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

std::vector<int> input;
input.insert(input.end(), { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
+3

Source: https://habr.com/ru/post/1695777/


All Articles