1 /*============================================================================= 2 Copyright (c) 2017 Paul Fultz II 3 issue8.cpp 4 Distributed under the Boost Software License, Version 1.0. (See accompanying 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 ==============================================================================*/ 7 8 #include "test.hpp" 9 #include <vector> 10 #include <boost/hof/pipable.hpp> 11 #include <boost/hof/placeholders.hpp> 12 #include <algorithm> 13 14 15 struct filter_fn 16 { 17 template<class Input, class P> operator ()filter_fn18 Input operator()(Input input, P pred) const 19 { 20 Input output(input.size()); 21 output.erase( 22 ::std::copy_if( 23 ::std::begin(input), 24 ::std::end(input), 25 ::std::begin(output), 26 pred 27 ), 28 ::std::end(output) 29 ); 30 return output; 31 } 32 }; 33 34 static constexpr boost::hof::pipable_adaptor<filter_fn> filter = {}; 35 BOOST_HOF_TEST_CASE()36BOOST_HOF_TEST_CASE() 37 { 38 std::vector<int> data; 39 for(int i=0;i<6;i++) 40 { 41 data.push_back(i); 42 } 43 std::vector<int> r1 = data | filter(boost::hof::_1 > 1); 44 BOOST_HOF_TEST_CHECK(r1.size() == 4); 45 46 std::vector<int> r2 = filter(data, boost::hof::_1 > 1); 47 BOOST_HOF_TEST_CHECK(r2.size() == 4); 48 } 49