at.const.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/tuple.hpp>
  6. #include <string>
  7. namespace hana = boost::hana;
  8. struct Empty { };
  9. int main() {
  10. {
  11. using T = hana::tuple<int>;
  12. const T t(3);
  13. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 3);
  14. }
  15. {
  16. using T = hana::tuple<std::string, int>;
  17. const T t("high", 5);
  18. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == "high");
  19. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t) == 5);
  20. }
  21. {
  22. using T = hana::tuple<double, int>;
  23. constexpr T t(2.718, 5);
  24. static_assert(hana::at_c<0>(t) == 2.718, "");
  25. static_assert(hana::at_c<1>(t) == 5, "");
  26. }
  27. {
  28. using T = hana::tuple<Empty>;
  29. constexpr T t{Empty()};
  30. constexpr Empty e = hana::at_c<0>(t); (void)e;
  31. }
  32. {
  33. using T = hana::tuple<double&, std::string, int>;
  34. double d = 1.5;
  35. const T t(d, "high", 5);
  36. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 1.5);
  37. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t) == "high");
  38. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t) == 5);
  39. hana::at_c<0>(t) = 2.5;
  40. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(t) == 2.5);
  41. BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(t) == "high");
  42. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(t) == 5);
  43. BOOST_HANA_RUNTIME_CHECK(d == 2.5);
  44. }
  45. }