// 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) // Make sure `assert` always triggers an assertion #ifdef NDEBUG # undef NDEBUG #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace fusion = boost::fusion; namespace mpl = boost::mpl; using namespace std::literals; int main() { { //! [runtime] auto f = [](int i) -> std::string { return std::to_string(i * i); }; std::vector ints{1, 2, 3, 4}; std::vector strings; std::transform(ints.begin(), ints.end(), std::back_inserter(strings), f); assert((strings == std::vector{"1", "4", "9", "16"})); //! [runtime] }{ //! [heterogeneous] auto to_string = [](auto t) { std::stringstream ss; ss << t; return ss.str(); }; fusion::vector seq{1, "abc", 3.4f}; fusion::vector strings = fusion::transform(seq, to_string); assert(strings == fusion::make_vector("1"s, "abc"s, "3.4"s)); //! [heterogeneous] } } //! [type-level] template struct add_const_pointer { using type = T const*; }; using types = mpl::vector; using pointers = mpl::transform>::type; static_assert(mpl::equal< pointers, mpl::vector >::value, ""); //! [type-level]