foldable.cpp 753 B

12345678910111213141516171819202122232425
  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/ext/std/integer_sequence.hpp>
  6. #include <boost/hana/unpack.hpp>
  7. #include <tuple>
  8. #include <utility>
  9. namespace hana = boost::hana;
  10. auto add = [](auto a, auto b, auto c) { return a + b + c; };
  11. int main() {
  12. std::tuple<int, long, double> tuple{1, 2l, 3.3};
  13. auto sum = hana::unpack(std::integer_sequence<int, 0, 1, 2>{}, [&](auto ...i) {
  14. // the `i`s are `std::integral_constant<int, ...>`s
  15. return add(std::get<decltype(i)::value>(tuple)...);
  16. });
  17. BOOST_HANA_RUNTIME_CHECK(sum == 6.3);
  18. }