/* @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) */ ////////////////////////////////////////////////////////////////////////////// // Important: Keep this file in sync with the Overview in the README ////////////////////////////////////////////////////////////////////////////// #include #include #include #include using namespace boost::hana; struct President { std::string name; }; struct Car { std::string name; }; struct City { std::string name; }; int main() { // Heterogeneous sequences for value-level metaprogramming. auto stuff = tuple(President{"Obama"}, Car{"Toyota"}, City{"Quebec"}); auto names = transform(stuff, [](auto thing) { return thing.name; }); BOOST_HANA_RUNTIME_CHECK(reverse(names) == tuple("Quebec", "Toyota", "Obama")); // No compile-time information is lost: // `stuff` wasn't constexpr but its length is! static_assert(length(stuff) == 3u, ""); // Type-level metaprogramming works too. auto types = transform(stuff, [](auto thing) { return type; }); BOOST_HANA_CONSTANT_CHECK( types == tuple(type, type, type) ); }