/* @copyright Louis Dionne 2014 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 #include #include #include #include #include #include #include #include #include #include #include #include using namespace boost::hana; int main() { { //! [all] using namespace literals; BOOST_HANA_CONSTEXPR_LAMBDA auto odd = [](auto x) { return x % 2_c != 0_c; }; BOOST_HANA_CONSTEXPR_CHECK(all(tuple(1, 3), odd)); BOOST_HANA_CONSTANT_CHECK(!all(tuple(3_c, 4_c), odd)); BOOST_HANA_CONSTANT_CHECK( !all(tuple(type, type), trait) ); BOOST_HANA_CONSTANT_CHECK( all(tuple(type, type), trait) ); //! [all] } { //! [all_of] BOOST_HANA_CONSTEXPR_CHECK(all_of(tuple(true_, true, true_))); BOOST_HANA_CONSTANT_CHECK(!all_of(tuple(true, false_, true_))); //! [all_of] } { //! [any] using namespace literals; BOOST_HANA_CONSTEXPR_LAMBDA auto odd = [](auto x) { return x % 2_c != 0_c; }; BOOST_HANA_CONSTEXPR_CHECK(any(tuple(1, 2), odd)); BOOST_HANA_CONSTANT_CHECK(!any(tuple(2_c, 4_c), odd)); BOOST_HANA_CONSTANT_CHECK( any(tuple(type, type), trait) ); BOOST_HANA_CONSTANT_CHECK( !any(tuple(type, type), trait) ); //! [any] } { //! [any_of] BOOST_HANA_CONSTANT_CHECK(any_of(tuple(false, false_, true_))); BOOST_HANA_CONSTEXPR_CHECK(any_of(tuple(false, false_, true))); BOOST_HANA_CONSTEXPR_CHECK(!any_of(tuple(false, false_, false_))); //! [any_of] } { //! [elem] BOOST_HANA_CONSTANT_CHECK(elem(tuple(2, int_<2>, int_<3>, 'x'), int_<3>)); BOOST_HANA_CONSTANT_CHECK(elem(set(1, '2', type, "foobar"), type)); //! [elem] } { //! [find] BOOST_HANA_CONSTEXPR_CHECK(find(tuple(1.0, 2, '3'), trait_) == just(2)); BOOST_HANA_CONSTANT_CHECK(find(tuple(1.0, 2, '3'), trait_) == nothing); constexpr auto types = tuple_t; BOOST_HANA_CONSTANT_CHECK(find(types, _ == type) == just(type)); BOOST_HANA_CONSTANT_CHECK(find(types, _ == type) == nothing); //! [find] } { //! [in] BOOST_HANA_CONSTEXPR_LAMBDA auto xs = tuple( int_<1>, type, int_<2>, type, int_<3>, type, type ); BOOST_HANA_CONSTANT_CHECK( filter(xs, in ^ tuple(int_<3>, type, type)) == tuple(type, int_<3>, type) ); //! [in] } { //! [lookup] BOOST_HANA_CONSTANT_CHECK(lookup(tuple(int_<1>, type, '3'), type) == just(type)); BOOST_HANA_CONSTANT_CHECK(lookup(tuple(int_<1>, type, '3'), type) == nothing); BOOST_HANA_CONSTEXPR_LAMBDA auto m = map( pair(1, 'x'), pair(type, 3.3), pair(type, type) ); BOOST_HANA_CONSTEXPR_CHECK(lookup(m, type) == just(3.3)); //! [lookup] } { //! [none] using namespace literals; BOOST_HANA_CONSTEXPR_LAMBDA auto odd = [](auto x) { return x % 2_c != 0_c; }; BOOST_HANA_CONSTANT_CHECK(none(tuple(2_c, 4_c), odd)); BOOST_HANA_CONSTEXPR_CHECK(!none(tuple(1, 2), odd)); BOOST_HANA_CONSTANT_CHECK( !none(tuple(type, type), trait) ); BOOST_HANA_CONSTANT_CHECK( none(tuple(type, type), trait) ); //! [none] } { //! [none_of] BOOST_HANA_CONSTEXPR_CHECK(none_of(tuple(false, false_, false_))); BOOST_HANA_CONSTEXPR_CHECK(!none_of(tuple(false, false_, true))); BOOST_HANA_CONSTANT_CHECK(!none_of(tuple(false, false_, true_))); //! [none_of] } { //! [subset] BOOST_HANA_CONSTEXPR_CHECK(subset(tuple(1, '2', 3.3), tuple(3.3, 1, '2', nullptr))); //! [subset] } }