searchable.cpp 1.1 KB

123456789101112131415161718192021222324252627282930
  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/at_key.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/find.hpp>
  8. #include <boost/hana/integral_constant.hpp>
  9. #include <boost/hana/map.hpp>
  10. #include <boost/hana/optional.hpp>
  11. #include <boost/hana/pair.hpp>
  12. #include <boost/hana/type.hpp>
  13. namespace hana = boost::hana;
  14. constexpr auto m = hana::make_map(
  15. hana::make_pair(hana::type_c<int>, 'i'),
  16. hana::make_pair(hana::type_c<float>, 'f')
  17. );
  18. static_assert(hana::find(m, hana::type_c<int>) == hana::just('i'), "");
  19. static_assert(hana::find(m, hana::type_c<float>) == hana::just('f'), "");
  20. BOOST_HANA_CONSTANT_CHECK(hana::find(m, hana::type_c<void>) == hana::nothing);
  21. BOOST_HANA_CONSTANT_CHECK(hana::find(m, hana::int_c<3>) == hana::nothing);
  22. // operator[] is equivalent to at_key
  23. static_assert(m[hana::type_c<int>] == 'i', "");
  24. static_assert(m[hana::type_c<float>] == 'f', "");
  25. int main() { }