at.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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/detail/variadic/at.hpp>
  5. #include <boost/hana/assert.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <laws/base.hpp>
  8. namespace hana = boost::hana;
  9. namespace vd = hana::detail::variadic;
  10. using hana::test::ct_eq;
  11. struct non_pod { virtual ~non_pod() { } };
  12. template <int i> struct y { };
  13. int main() {
  14. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  15. vd::at<0>(ct_eq<0>{}),
  16. ct_eq<0>{}
  17. ));
  18. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  19. vd::at<0>(ct_eq<0>{}, ct_eq<1>{}),
  20. ct_eq<0>{}
  21. ));
  22. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  23. vd::at<1>(y<0>{}, ct_eq<1>{}),
  24. ct_eq<1>{}
  25. ));
  26. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  27. vd::at<0>(ct_eq<0>{}, y<1>{}, y<2>{}),
  28. ct_eq<0>{}
  29. ));
  30. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  31. vd::at<1>(y<0>{}, ct_eq<1>{}, y<2>{}),
  32. ct_eq<1>{}
  33. ));
  34. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  35. vd::at<2>(y<0>{}, y<1>{}, ct_eq<2>{}),
  36. ct_eq<2>{}
  37. ));
  38. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  39. vd::at<0>(ct_eq<0>{}, y<1>{}, y<2>{}, y<3>{}),
  40. ct_eq<0>{}
  41. ));
  42. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  43. vd::at<1>(y<0>{}, ct_eq<1>{}, y<2>{}, y<3>{}),
  44. ct_eq<1>{}
  45. ));
  46. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  47. vd::at<2>(y<0>{}, y<1>{}, ct_eq<2>{}, y<3>{}),
  48. ct_eq<2>{}
  49. ));
  50. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  51. vd::at<3>(y<0>{}, y<1>{}, y<2>{}, ct_eq<3>{}),
  52. ct_eq<3>{}
  53. ));
  54. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  55. vd::at<0>(ct_eq<0>{}, y<1>{}, y<2>{}, y<3>{}, y<4>{}),
  56. ct_eq<0>{}
  57. ));
  58. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  59. vd::at<1>(y<0>{}, ct_eq<1>{}, y<2>{}, y<3>{}, y<4>{}),
  60. ct_eq<1>{}
  61. ));
  62. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  63. vd::at<2>(y<0>{}, y<1>{}, ct_eq<2>{}, y<3>{}, y<4>{}),
  64. ct_eq<2>{}
  65. ));
  66. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  67. vd::at<3>(y<0>{}, y<1>{}, y<2>{}, ct_eq<3>{}, y<4>{}),
  68. ct_eq<3>{}
  69. ));
  70. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  71. vd::at<4>(y<0>{}, y<1>{}, y<2>{}, y<3>{}, ct_eq<4>{}),
  72. ct_eq<4>{}
  73. ));
  74. // make sure we can use non-pods on both side of the fetched object
  75. vd::at<0>(ct_eq<0>{}, non_pod{});
  76. vd::at<1>(non_pod{}, ct_eq<1>{});
  77. // make sure it works with const objects
  78. int const i = 1;
  79. vd::at<0>(i);
  80. }