fuse.cpp 727 B

1234567891011121314151617181920212223242526
  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/fuse.hpp>
  6. #include <boost/hana/tuple.hpp>
  7. namespace hana = boost::hana;
  8. auto tie = [](auto& ...vars) {
  9. return hana::fuse([&vars...](auto ...values) {
  10. // Using an initializer list to sequence the assignments.
  11. int dummy[] = {0, ((void)(vars = values), 0)...};
  12. (void)dummy;
  13. });
  14. };
  15. int main() {
  16. int a = 0;
  17. char b = '\0';
  18. double c = 0;
  19. tie(a, b, c)(hana::make_tuple(1, '2', 3.3));
  20. BOOST_HANA_RUNTIME_CHECK(a == 1 && b == '2' && c == 3.3);
  21. }