combine.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <boost/hof/construct.hpp>
  10. #include <boost/hof/capture.hpp>
  11. #include <utility>
  12. #include <tuple>
  13. template<class T, class U>
  14. struct mini_pair
  15. {
  16. T first;
  17. U second;
  18. template<class X, class Y>
  19. constexpr mini_pair(X&& x, Y&& y)
  20. : first(boost::hof::forward<X>(x)), second(boost::hof::forward<Y>(y))
  21. {}
  22. };
  23. template<class T1, class U1, class T2, class U2>
  24. constexpr bool operator==(const mini_pair<T1, U1>& x, const mini_pair<T2, U2>& y)
  25. {
  26. return x.first == y.first && x.second == y.second;
  27. }
  28. template<class T, class U>
  29. constexpr mini_pair<T, U> make_mini_pair(T x, U y)
  30. {
  31. return mini_pair<T, U>(x, y);
  32. }
  33. BOOST_HOF_TEST_CASE()
  34. {
  35. BOOST_HOF_TEST_CHECK(
  36. boost::hof::combine(
  37. boost::hof::construct<std::tuple>(),
  38. boost::hof::capture_basic(1)(boost::hof::construct<std::pair>()),
  39. boost::hof::capture_basic(2)(boost::hof::construct<std::pair>())
  40. )(2, 4)
  41. == std::make_tuple(std::make_pair(1, 2), std::make_pair(2, 4)));
  42. }
  43. BOOST_HOF_TEST_CASE()
  44. {
  45. BOOST_HOF_TEST_CHECK(
  46. boost::hof::combine(
  47. boost::hof::construct<mini_pair>(),
  48. boost::hof::capture_basic(1)(boost::hof::construct<mini_pair>()),
  49. boost::hof::capture_basic(2)(boost::hof::construct<mini_pair>())
  50. )(2, 4)
  51. == make_mini_pair(make_mini_pair(1, 2), make_mini_pair(2, 4)));
  52. BOOST_HOF_STATIC_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. }