find_if.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/concept/struct.hpp>
  6. #include <boost/hana/equal.hpp>
  7. #include <boost/hana/find_if.hpp>
  8. #include <boost/hana/integral_constant.hpp>
  9. #include <boost/hana/optional.hpp>
  10. #include "minimal_struct.hpp"
  11. #include <laws/base.hpp>
  12. namespace hana = boost::hana;
  13. using hana::test::ct_eq;
  14. template <int i = 0>
  15. struct undefined { };
  16. int main() {
  17. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  18. hana::find_if(obj(), undefined<>{}),
  19. hana::nothing
  20. ));
  21. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  22. hana::find_if(obj(ct_eq<0>{}), hana::equal.to(hana::int_c<0>)),
  23. hana::just(ct_eq<0>{})
  24. ));
  25. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  26. hana::find_if(obj(undefined<1>{}), hana::equal.to(hana::int_c<1>)),
  27. hana::nothing
  28. ));
  29. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  30. hana::find_if(obj(ct_eq<0>{}, ct_eq<1>{}), hana::equal.to(hana::int_c<0>)),
  31. hana::just(ct_eq<0>{})
  32. ));
  33. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  34. hana::find_if(obj(ct_eq<0>{}, ct_eq<1>{}), hana::equal.to(hana::int_c<1>)),
  35. hana::just(ct_eq<1>{})
  36. ));
  37. BOOST_HANA_CONSTANT_CHECK(hana::equal(
  38. hana::find_if(obj(undefined<0>{}, undefined<1>{}), hana::equal.to(hana::int_c<2>)),
  39. hana::nothing
  40. ));
  41. }