1/*=============================================================================
2 Copyright (c) 2017 Paul Fultz II
3 filter.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 <boost/hof/if.hpp>
8#include "test.hpp"
9
10#include <boost/hof/proj.hpp>
11#include <boost/hof/lift.hpp>
12#include <boost/hof/construct.hpp>
13#include <boost/hof/first_of.hpp>
14#include <boost/hof/unpack.hpp>
15
16#include <tuple>
17
18BOOST_HOF_LIFT_CLASS(make_tuple_f, std::make_tuple);
19
20struct integer_predicate
21{
22 constexpr integer_predicate()
23 {}
24 template<class T>
25 constexpr auto operator()(T x) const BOOST_HOF_RETURNS
26 (
27 boost::hof::first_of(
28 boost::hof::if_(std::is_integral<T>())(boost::hof::pack_basic),
29 boost::hof::always(boost::hof::pack_basic())
30 )(boost::hof::move(x))
31 )
32};
33
34struct filter_integers
35{
36 template<class Seq>
37 constexpr auto operator()(Seq s) const BOOST_HOF_RETURNS
38 (
39 boost::hof::unpack(
40 boost::hof::proj(integer_predicate(), boost::hof::unpack(make_tuple_f()))
41 )(std::move(s))
42 )
43};
44
45
46BOOST_HOF_TEST_CASE()
47{
48 BOOST_HOF_TEST_CHECK(filter_integers()(boost::hof::pack_basic(1, 2, 2.0, 3)) == std::make_tuple(1, 2, 3));
49#if BOOST_HOF_HAS_CONSTEXPR_TUPLE
50 BOOST_HOF_STATIC_TEST_CHECK(filter_integers()(boost::hof::pack_basic(1, 2, 2.0, 3)) == std::make_tuple(1, 2, 3));
51#endif
52}
53
54
55

source code of boost/libs/hof/test/filter.cpp