I'm taking my first steps with Boost.Hana, so please bear with me. I have
#include <boost/hana.hpp>
namespace hana = boost::hana;
using namespace hana::literals;
#include <string>
struct A
{
int integer;
std::string string;
};
int main()
{
auto tuple = hana::make_tuple(42, "42");
A a;
hana::for_each(hana::zip(hana::members(a), tuple), [](auto& element) { element[0_c] = element[1_c]; });
}
This is my attempt at assigning each tuple element to its respective (sequential) member of A. This does not work (see live example for complete error). It boils down to
main.cpp:19:54: note: candidate function [with $0 = boost::hana::tuple<int, int>] not viable: expects an l-value for 1st argument
hana::for_each(hana::zip(hana::members(a), input), [](auto& element) { element[0_c] = element[1_c]; });
^
I read in the documentation that Hana algorithms have by-value semantics, but then how would one go about doing this kind of thing? Is constructing an A
from the hana::tuple
the only thing possible?