tap.cpp 999 B

12345678910111213141516171819202122232425262728
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/assert.hpp>
  5. #include <boost/hana/chain.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/tap.hpp>
  8. #include <boost/hana/tuple.hpp>
  9. #include <set>
  10. namespace hana = boost::hana;
  11. int main() {
  12. // We use a sorted container because the order in which the functions
  13. // are called is unspecified.
  14. std::set<int> before, after;
  15. auto xs = hana::make_tuple(1, 2, 3)
  16. | hana::tap<hana::tuple_tag>([&](int x) { before.insert(x); })
  17. | [](auto x) { return hana::make_tuple(x, -x); }
  18. | hana::tap<hana::tuple_tag>([&](int x) { after.insert(x); });
  19. BOOST_HANA_RUNTIME_CHECK(before == std::set<int>{1, 2, 3});
  20. BOOST_HANA_RUNTIME_CHECK(after == std::set<int>{1, -1, 2, -2, 3, -3});
  21. BOOST_HANA_RUNTIME_CHECK(xs == hana::make_tuple(1, -1, 2, -2, 3, -3));
  22. }