index_if.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright Louis Dionne 2013-2017
  2. // Copyright Jason Rice 2017
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. #include <boost/hana/index_if.hpp>
  6. #include <boost/hana/integral_constant.hpp>
  7. #include <cstddef>
  8. #include <support/counter.hpp>
  9. namespace hana = boost::hana;
  10. int main() {
  11. // Tests hana::index_if on an infinite iterable
  12. constexpr Counter<> c{};
  13. auto pred = [](auto i) {
  14. return [=](auto x) {
  15. return hana::bool_c<decltype(x)::value == decltype(i)::value>;
  16. };
  17. };
  18. static_assert(hana::value(decltype(hana::index_if(c, pred(hana::size_c<0>)).value()){}) == 0, "");
  19. static_assert(hana::value(decltype(hana::index_if(c, pred(hana::size_c<1>)).value()){}) == 1, "");
  20. static_assert(hana::value(decltype(hana::index_if(c, pred(hana::size_c<2>)).value()){}) == 2, "");
  21. static_assert(hana::value(decltype(hana::index_if(c, pred(hana::size_c<3>)).value()){}) == 3, "");
  22. static_assert(hana::value(decltype(hana::index_if(c, pred(hana::size_c<4>)).value()){}) == 4, "");
  23. static_assert(hana::value(decltype(hana::index_if(c, pred(hana::size_c<5>)).value()){}) == 5, "");
  24. static_assert(hana::value(decltype(hana::index_if(c, pred(hana::size_c<6>)).value()){}) == 6, "");
  25. }