2
0
mirror of https://github.com/boostorg/hana.git synced 2026-01-25 18:22:17 +00:00
Files
hana/example/tutorial/sem.cpp
Louis Dionne ca37fdfa4c [Doc] Add a section on performance in the tutorial
Also:
- Introduce the .js charts we have in the reference
- Remove the ugly "Generated by Doxygen" footer
- Refactor the benchmarks
2015-04-25 16:31:56 -04:00

62 lines
1.2 KiB
C++

/*
@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 <boost/hana.hpp>
#include <sstream>
#include <string>
using namespace boost::hana;
int main() {
{
//! [copy_initialize]
std::string hello{"Hello"};
std::string world{"world"};
// copies hello and world
_tuple<std::string, std::string> xs{hello, world};
//! [copy_initialize]
}{
//! [move_initialize]
std::string hello{"Hello"};
std::string world{"world"};
// moves hello and world
_tuple<std::string, std::string> xs{std::move(hello), std::move(world)};
//! [move_initialize]
}
//! [reverse_transform]
auto to_str = [](auto const& x) {
std::stringstream ss;
ss << x;
return ss.str();
};
auto xs = make_tuple(1, 2.2, 'a', "bcde");
BOOST_HANA_RUNTIME_CHECK(
reverse(transform(xs, to_str)) == make_tuple("bcde", "a", "2.2", "1")
);
//! [reverse_transform]
//! [reverse_transform_copy]
reverse(
transform(xs, to_str) // <-- copy into reverse(...) here?
);
//! [reverse_transform_copy]
//! [reverse_transform_move]
reverse(
transform(xs, to_str) // <-- nah, move from the temporary!
);
//! [reverse_transform_move]
}