/* @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 #include #include #include using namespace boost::hana; int main() { { //! [concat] using namespace boost::hana::literals; static_assert(concat(make_tuple(1, '2'), make_tuple(3.3, 4_c)) == make_tuple(1, '2', 3.3, 4_c), ""); //! [concat] }{ //! [empty] BOOST_HANA_CONSTANT_CHECK(empty() == make_tuple()); BOOST_HANA_CONSTANT_CHECK(empty() == nothing); //! [empty] }{ //! [prepend] static_assert(prepend(make_tuple(), 1) == make_tuple(1), ""); static_assert(prepend(make_tuple('2', 3.3), 1) == make_tuple(1, '2', 3.3), ""); //! [prepend] }{ //! [append] static_assert(append(make_tuple(), 1) == make_tuple(1), ""); static_assert(append(make_tuple(1, '2'), 3.3) == make_tuple(1, '2', 3.3), ""); static_assert(append(append(append(make_tuple(), 1), '2'), 3.3) == make_tuple(1, '2', 3.3), ""); //! [append] }{ //! [filter] static_assert(filter(make_tuple(1, 2.0, 3, 4.0), trait) == make_tuple(1, 3), ""); static_assert(filter(just(3), trait) == just(3), ""); BOOST_HANA_CONSTANT_CHECK(filter(just(3.0), trait) == nothing); //! [filter] }{ //! [cycle] static_assert(cycle(make_tuple('x', 'y'), size_t<2>) == make_tuple('x', 'y', 'x', 'y'), ""); //! [cycle] }{ //! [remove_if] static_assert(remove_if(make_tuple(1, 2.0, 3, 4.0), trait) == make_tuple(2.0, 4.0), ""); static_assert(remove_if(just(3.0), trait) == just(3.0), ""); BOOST_HANA_CONSTANT_CHECK(remove_if(just(3), trait) == nothing); //! [remove_if] }{ using boost::hana::remove; // Make sure we don't clash with ::remove from //! [remove] BOOST_HANA_CONSTANT_CHECK(remove(tuple_t, type) == tuple_t); BOOST_HANA_CONSTANT_CHECK(remove(just(type), type) == just(type)); BOOST_HANA_CONSTANT_CHECK(remove(just(type), type) == nothing); //! [remove] }{ //! [repeat] static_assert(repeat('x', size_t<2>) == make_tuple('x', 'x'), ""); // Of course, there can't be more than one element in an Optional. static_assert(repeat('x', size_t<2>) == just('x'), ""); //! [repeat] }{ //! [prefix] using namespace std::literals; BOOST_HANA_RUNTIME_CHECK( prefix(make_tuple("dog"s, "car"s, "house"s), "my"s) == make_tuple("my", "dog", "my", "car", "my", "house") ); //! [prefix] }{ //! [suffix] static_assert( suffix(make_tuple(1, 2, 3, 4), 0) == make_tuple(1, 0, 2, 0, 3, 0, 4, 0) , ""); //! [suffix] } }