at_key.cpp 830 B

123456789101112131415161718192021222324252627
  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/integral_constant.hpp>
  7. #include <boost/hana/map.hpp>
  8. #include <boost/hana/pair.hpp>
  9. #include <boost/hana/type.hpp>
  10. #include <string>
  11. namespace hana = boost::hana;
  12. int main() {
  13. auto m = hana::make_map(
  14. hana::make_pair(hana::type<int>{}, std::string{"int"}),
  15. hana::make_pair(hana::int_<3>{}, std::string{"3"})
  16. );
  17. BOOST_HANA_RUNTIME_CHECK(hana::at_key(m, hana::type<int>{}) == "int");
  18. // usage as operator[]
  19. BOOST_HANA_RUNTIME_CHECK(m[hana::type<int>{}] == "int");
  20. BOOST_HANA_RUNTIME_CHECK(m[hana::int_<3>{}] == "3");
  21. }