| 1 | // Copyright Louis Dionne 2013-2022 |
|---|---|
| 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 | |
| 5 | #include <boost/hana/assert.hpp> |
| 6 | #include <boost/hana/functional/overload.hpp> |
| 7 | |
| 8 | #include <iostream> |
| 9 | #include <string> |
| 10 | namespace hana = boost::hana; |
| 11 | |
| 12 | |
| 13 | auto on_string = [](std::string const& s) { |
| 14 | std::cout << "matched std::string: "<< s << std::endl; |
| 15 | return s; |
| 16 | }; |
| 17 | |
| 18 | auto on_int = [](int i) { |
| 19 | std::cout << "matched int: "<< i << std::endl; |
| 20 | return i; |
| 21 | }; |
| 22 | |
| 23 | auto f = hana::overload(on_int, on_string); |
| 24 | |
| 25 | int main() { |
| 26 | // prints "matched int: 1" |
| 27 | BOOST_HANA_RUNTIME_CHECK(f(1) == 1); |
| 28 | |
| 29 | // prints "matched std::string: abcdef" |
| 30 | BOOST_HANA_RUNTIME_CHECK(f("abcdef") == std::string{ "abcdef"}); |
| 31 | } |
| 32 |
