issue8.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "test.hpp"
  8. #include <vector>
  9. #include <boost/hof/pipable.hpp>
  10. #include <boost/hof/placeholders.hpp>
  11. #include <algorithm>
  12. struct filter_fn
  13. {
  14. template<class Input, class P>
  15. Input operator()(Input input, P pred) const
  16. {
  17. Input output(input.size());
  18. output.erase(
  19. ::std::copy_if(
  20. ::std::begin(input),
  21. ::std::end(input),
  22. ::std::begin(output),
  23. pred
  24. ),
  25. ::std::end(output)
  26. );
  27. return output;
  28. }
  29. };
  30. static constexpr boost::hof::pipable_adaptor<filter_fn> filter = {};
  31. BOOST_HOF_TEST_CASE()
  32. {
  33. std::vector<int> data;
  34. for(int i=0;i<6;i++)
  35. {
  36. data.push_back(i);
  37. }
  38. std::vector<int> r1 = data | filter(boost::hof::_1 > 1);
  39. BOOST_HOF_TEST_CHECK(r1.size() == 4);
  40. std::vector<int> r2 = filter(data, boost::hof::_1 > 1);
  41. BOOST_HOF_TEST_CHECK(r2.size() == 4);
  42. }