find_if.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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/equal.hpp>
  6. #include <boost/hana/find_if.hpp>
  7. #include <boost/hana/optional.hpp>
  8. #include <laws/base.hpp>
  9. namespace hana = boost::hana;
  10. using hana::test::ct_eq;
  11. int main() {
  12. ct_eq<2> x{};
  13. ct_eq<3> y{};
  14. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  15. hana::find_if(hana::just(x), hana::equal.to(x)),
  16. hana::just(x)
  17. ));
  18. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  19. hana::find_if(hana::just(x), hana::equal.to(y)),
  20. hana::nothing
  21. ));
  22. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  23. hana::find_if(hana::nothing, hana::equal.to(x)),
  24. hana::nothing
  25. ));
  26. // Previously, there was a bug that would make this fail.
  27. auto non_const_nothing = hana::nothing;
  28. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  29. hana::find_if(non_const_nothing, hana::equal.to(x)),
  30. hana::nothing
  31. ));
  32. }