find_if.cpp 1.6 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/at_key.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/find_if.hpp>
  8. #include <boost/hana/optional.hpp>
  9. #include <boost/hana/set.hpp>
  10. #include <laws/base.hpp>
  11. namespace hana = boost::hana;
  12. using hana::test::ct_eq;
  13. int main() {
  14. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  15. hana::find_if(hana::make_set(), hana::equal.to(ct_eq<1>{})),
  16. hana::nothing
  17. ));
  18. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  19. hana::find_if(hana::make_set(ct_eq<1>{}), hana::equal.to(ct_eq<1>{})),
  20. hana::just(ct_eq<1>{})
  21. ));
  22. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  23. hana::find_if(hana::make_set(ct_eq<1>{}), hana::equal.to(ct_eq<2>{})),
  24. hana::nothing
  25. ));
  26. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  27. hana::find_if(hana::make_set(ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(ct_eq<1>{})),
  28. hana::just(ct_eq<1>{})
  29. ));
  30. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  31. hana::find_if(hana::make_set(ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(ct_eq<2>{})),
  32. hana::just(ct_eq<2>{})
  33. ));
  34. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  35. hana::find_if(hana::make_set(ct_eq<1>{}, ct_eq<2>{}), hana::equal.to(ct_eq<3>{})),
  36. hana::nothing
  37. ));
  38. // find with operators
  39. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  40. hana::make_set(ct_eq<1>{})[ct_eq<1>{}],
  41. ct_eq<1>{}
  42. ));
  43. }