| 1 | /*============================================================================= |
| 2 | Copyright (c) 2017 Paul Fultz II |
| 3 | combine.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/combine.hpp> |
| 8 | #include "test.hpp" |
| 9 | |
| 10 | #include <boost/hof/construct.hpp> |
| 11 | #include <boost/hof/capture.hpp> |
| 12 | #include <utility> |
| 13 | #include <tuple> |
| 14 | |
| 15 | template<class T, class U> |
| 16 | struct mini_pair |
| 17 | { |
| 18 | T first; |
| 19 | U second; |
| 20 | |
| 21 | template<class X, class Y> |
| 22 | constexpr mini_pair(X&& x, Y&& y) |
| 23 | : first(boost::hof::forward<X>(x)), second(boost::hof::forward<Y>(y)) |
| 24 | {} |
| 25 | }; |
| 26 | |
| 27 | template<class T1, class U1, class T2, class U2> |
| 28 | constexpr bool operator==(const mini_pair<T1, U1>& x, const mini_pair<T2, U2>& y) |
| 29 | { |
| 30 | return x.first == y.first && x.second == y.second; |
| 31 | } |
| 32 | |
| 33 | template<class T, class U> |
| 34 | constexpr mini_pair<T, U> make_mini_pair(T x, U y) |
| 35 | { |
| 36 | return mini_pair<T, U>(x, y); |
| 37 | } |
| 38 | |
| 39 | BOOST_HOF_TEST_CASE() |
| 40 | { |
| 41 | BOOST_HOF_TEST_CHECK( |
| 42 | boost::hof::combine( |
| 43 | boost::hof::construct<std::tuple>(), |
| 44 | boost::hof::capture_basic(1)(boost::hof::construct<std::pair>()), |
| 45 | boost::hof::capture_basic(2)(boost::hof::construct<std::pair>()) |
| 46 | )(2, 4) |
| 47 | == std::make_tuple(std::make_pair(1, 2), std::make_pair(2, 4))); |
| 48 | } |
| 49 | |
| 50 | BOOST_HOF_TEST_CASE() |
| 51 | { |
| 52 | BOOST_HOF_TEST_CHECK( |
| 53 | boost::hof::combine( |
| 54 | boost::hof::construct<mini_pair>(), |
| 55 | boost::hof::capture_basic(1)(boost::hof::construct<mini_pair>()), |
| 56 | boost::hof::capture_basic(2)(boost::hof::construct<mini_pair>()) |
| 57 | )(2, 4) |
| 58 | == make_mini_pair(make_mini_pair(1, 2), make_mini_pair(2, 4))); |
| 59 | |
| 60 | BOOST_HOF_STATIC_TEST_CHECK( |
| 61 | boost::hof::combine( |
| 62 | boost::hof::construct<mini_pair>(), |
| 63 | boost::hof::capture_basic(1)(boost::hof::construct<mini_pair>()), |
| 64 | boost::hof::capture_basic(2)(boost::hof::construct<mini_pair>()) |
| 65 | )(2, 4) |
| 66 | == make_mini_pair(make_mini_pair(1, 2), make_mini_pair(2, 4))); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |