/* @copyright Louis Dionne 2015 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 using namespace boost::hana; int main() { { //! [sequence] BOOST_HANA_CONSTEXPR_CHECK( sequence(make(just(1), just('2'), just(3.3))) == just(make(1, '2', 3.3)) ); BOOST_HANA_CONSTANT_CHECK( sequence(make(just(1), nothing, just(3.3))) == nothing ); // This is a generalized Cartesian product. BOOST_HANA_CONSTEXPR_CHECK( sequence(make(make(1, 2, 3), make(4), make(5, 6))) == make( make(1, 4, 5), make(1, 4, 6), make(2, 4, 5), make(2, 4, 6), make(3, 4, 5), make(3, 4, 6) ) ); //! [sequence] }{ //! [traverse] BOOST_HANA_CONSTEXPR_LAMBDA auto half = [](auto x) { return if_(x % int_<2> == int_<0>, just(x / int_<2>), nothing ); }; BOOST_HANA_CONSTANT_CHECK( traverse(make(int_<2>, int_<4>, int_<6>), half) == just(make(int_<1>, int_<2>, int_<3>)) ); BOOST_HANA_CONSTANT_CHECK( traverse(make(int_<2>, int_<3>, int_<6>), half) == nothing ); BOOST_HANA_CONSTEXPR_LAMBDA auto twice = [](auto x) { return make(x, x); }; BOOST_HANA_CONSTEXPR_CHECK( traverse(just('x'), twice) == make(just('x'), just('x')) ); BOOST_HANA_CONSTANT_CHECK( traverse(nothing, twice) == make(nothing) ); //! [traverse] } }