123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- // Copyright Louis Dionne 2013-2017
- // Distributed under the Boost Software License, Version 1.0.
- // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
- #include "minimal.hpp"
- #include <boost/hana/and.hpp>
- #include <boost/hana/equal.hpp>
- #include <boost/hana/eval_if.hpp>
- #include <boost/hana/if.hpp>
- #include <boost/hana/not.hpp>
- #include <boost/hana/not_equal.hpp>
- #include <boost/hana/or.hpp>
- #include <boost/hana/tuple.hpp>
- #include <boost/hana/while.hpp>
- #include <laws/base.hpp>
- #include <laws/logical.hpp>
- namespace hana = boost::hana;
- struct invalid { };
- int main() {
- constexpr auto bools = hana::make_tuple(
- minimal_constant<bool, false>{},
- minimal_constant<bool, true>{}
- );
- hana::test::TestLogical<minimal_constant_tag<bool>>{bools};
- constexpr auto true_ = minimal_constant<bool, true>{};
- constexpr auto false_ = minimal_constant<bool, false>{};
- // not_
- {
- BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::not_(true_), false_));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::not_(false_), true_));
- }
- // and_
- {
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(true_),
- true_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(false_),
- false_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(true_, true_),
- true_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(true_, false_),
- false_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(false_, invalid{}),
- false_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(true_, true_, true_),
- true_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(true_, true_, false_),
- false_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(true_, false_, invalid{}),
- false_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::and_(false_, invalid{}, invalid{}),
- false_
- ));
- }
- // or_
- {
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(true_),
- true_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(false_),
- false_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(false_, false_),
- false_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(false_, true_),
- true_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(true_, invalid{}),
- true_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(false_, false_, false_),
- false_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(false_, false_, true_),
- true_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(false_, true_, invalid{}),
- true_
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::or_(true_, invalid{}, invalid{}),
- true_
- ));
- }
- // if_
- {
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::if_(true_, hana::test::ct_eq<3>{}, hana::test::ct_eq<4>{}),
- hana::test::ct_eq<3>{}
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::if_(false_, hana::test::ct_eq<3>{}, hana::test::ct_eq<4>{}),
- hana::test::ct_eq<4>{}
- ));
- }
- // eval_if
- {
- auto t = [](auto) { return hana::test::ct_eq<2>{}; };
- auto e = [](auto) { return hana::test::ct_eq<3>{}; };
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::eval_if(true_, t, invalid{}),
- hana::test::ct_eq<2>{}
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::eval_if(false_, invalid{}, e),
- hana::test::ct_eq<3>{}
- ));
- }
- // while_
- {
- hana::test::_injection<0> f{};
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::while_(hana::not_equal.to(hana::test::ct_eq<0>{}), hana::test::ct_eq<0>{}, invalid{}),
- hana::test::ct_eq<0>{}
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::while_(hana::not_equal.to(f(hana::test::ct_eq<0>{})), hana::test::ct_eq<0>{}, f),
- f(hana::test::ct_eq<0>{})
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::while_(hana::not_equal.to(f(f(hana::test::ct_eq<0>{}))), hana::test::ct_eq<0>{}, f),
- f(f(hana::test::ct_eq<0>{}))
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::while_(hana::not_equal.to(f(f(f(hana::test::ct_eq<0>{})))), hana::test::ct_eq<0>{}, f),
- f(f(f(hana::test::ct_eq<0>{})))
- ));
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::while_(hana::not_equal.to(f(f(f(f(hana::test::ct_eq<0>{}))))), hana::test::ct_eq<0>{}, f),
- f(f(f(f(hana::test::ct_eq<0>{}))))
- ));
- // Make sure it can be called with an lvalue state:
- auto state = hana::test::ct_eq<0>{};
- BOOST_HANA_CONSTANT_CHECK(hana::equal(
- hana::while_(hana::not_equal.to(f(f(f(f(hana::test::ct_eq<0>{}))))), state, f),
- f(f(f(f(hana::test::ct_eq<0>{}))))
- ));
- }
- }
|