|
Boost Users : |
Subject: [Boost-users] [Boost.Range] combine, native range-for, and destructuring
From: John M. Dlugosz (ngnr63q02_at_[hidden])
Date: 2018-04-14 10:34:30
I want to go through two vectors at the same time, and the way to do this is to "zip" the
items from each into a tuple. boost::combine is a function for that.
for (auto&[def,residue] : boost::combine(playdef, residues)) {
gives me an error
1>e:\scratch\c++code\scratchproject2\fizzbuzz\fizzbuzz.cpp(66): error C2440:
'initializing': cannot convert from
'boost::tuples::cons<std::pair<int,std::string_view> &,boost::tuples::cons<int
&,boost::fusion::detail::build_tuple_cons<boost::fusion::single_view_iterator<Sequence,boost::mpl::int_<1>>,Last,true>::type>>'
to
'boost::tuples::cons<std::pair<int,std::string_view> &,boost::tuples::cons<int
&,boost::fusion::detail::build_tuple_cons<boost::fusion::single_view_iterator<Sequence,boost::mpl::int_<1>>,Last,true>::type>>
&'
The only difference is in the final `&` character.
Trying to explore the behavior in pieces, I try:
for (auto row : boost::combine(playdef, residues)) {
auto&[def, residue] = row; // line 1
row.get<1>() = 17; // line 2
residue= 42; // line 3
Now line2 does work, and I note that assignment goes through and updates the original
`residues` vector.
The destructuring on line 1 does compile now, being on a separate line.
But line 3 gives me an error about not being able to assign to a crazy complicated type.
What's going on? Is Boost.Range zipped ranges simply not compatible with the native
language features?
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net