// Copyright Louis Dionne 2013-2016 // 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 namespace hana = boost::hana; using namespace hana::literals; using namespace std::literals; int main() { { //! [make] auto xs = hana::make(1, 2.2, 'a', "bcde"s); //! [make] }{ //! [make] constexpr auto r = hana::make(hana::int_c<3>, hana::int_c<10>); static_assert(r == hana::make_range(hana::int_c<3>, hana::int_c<10>), ""); //! [make] }{ //! [tuple_constructor] hana::tuple xs{1, 2.2, 'a', "bcde"s}; //! [tuple_constructor] (void)xs; }{ //! [types] auto xs = hana::make_tuple(1, '2', "345"); auto ints = hana::make_range(hana::int_c<0>, hana::int_c<100>); // what can we say about the types of `xs` and `ints`? //! [types] (void)xs; (void)ints; }{ //! [types_maximally_specified] hana::tuple xs = hana::make_tuple(1, '2', "345"); auto ints = hana::make_range(hana::int_c<0>, hana::int_c<100>); // can't specify the type of ints, however //! [types_maximally_specified] (void)xs; (void)ints; }{ //! [lifetime] std::string hello = "Hello"; std::vector world = {'W', 'o', 'r', 'l', 'd'}; // hello is copied, world is moved-in auto xs = hana::make_tuple(hello, std::move(world)); // s is a reference to the copy of hello inside xs. // It becomes a dangling reference as soon as xs is destroyed. std::string& s = xs[0_c]; //! [lifetime] (void)s; }{ //! [reference_tuple] std::string hello = "Hello"; std::vector world = {'W', 'o', 'r', 'l', 'd'}; hana::tuple&> xs{hello, world}; // s is a reference to `hello` std::string& s = xs[0_c]; BOOST_HANA_RUNTIME_CHECK(&s == &hello); //! [reference_tuple] }{ //! [reference_wrapper] std::string hello = "Hello"; std::vector world = {'W', 'o', 'r', 'l', 'd'}; auto xs = hana::make_tuple(std::ref(hello), std::ref(world)); std::string& hello_ref = xs[0_c]; std::vector& world_ref = xs[1_c]; BOOST_HANA_RUNTIME_CHECK(&hello_ref == &hello); BOOST_HANA_RUNTIME_CHECK(&world_ref == &world); //! [reference_wrapper] } } namespace overloading { //! [overloading] template void f(std::vector xs) { // ... } template ()>> void f(R r) { // ... } //! [overloading] }