overload_linearly.cpp 677 B

12345678910111213141516171819202122
  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/functional/overload_linearly.hpp>
  6. #include <string>
  7. namespace hana = boost::hana;
  8. auto f = hana::overload_linearly(
  9. [](int i) { return i + 1; },
  10. [](std::string s) { return s + "d"; },
  11. [](double) { BOOST_HANA_RUNTIME_CHECK(false && "never called"); }
  12. );
  13. int main() {
  14. BOOST_HANA_RUNTIME_CHECK(f(1) == 2);
  15. BOOST_HANA_RUNTIME_CHECK(f("abc") == "abcd");
  16. BOOST_HANA_RUNTIME_CHECK(f(2.2) == static_cast<int>(2.2) + 1);
  17. }