2

Up until now, i was copying a src fusion sequence into a dst fusion sequence.

struct Dst { ... } dst;
boost::fusion::copy( src, dst );

However, dst, which is a struct adapted as a fusion sequence has a new member, placed last.

src's size has not changed though.

How do I fix that?

manlio
  • 18,345
  • 14
  • 76
  • 126
MMM
  • 910
  • 1
  • 9
  • 25

1 Answers1

0

You just keep the same code.

The first fields will be copied as ever, and the trailing, new, field is left untouched:

See it Live On Coliru

#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/struct.hpp>
#include <boost/fusion/algorithm/auxiliary/copy.hpp>
#include <boost/fusion/include/io.hpp>
#include <iostream>

namespace fus = boost::fusion;

struct X {
    int i;
    double d;
    std::string s;
    std::string extra;
};

BOOST_FUSION_ADAPT_STRUCT(X, (int,i)(double,d)(std::string,s)(std::string,extra))

int main()
{
    fus::vector<int, double, std::string> src(42, 3.14, "hello");

    X dst { -1, -1, "filler", "filler" };

    fus::copy(src, dst);

    std::cout << fus::as_vector(dst);
}

Prints

(42 3.14 hello filler)
sehe
  • 374,641
  • 47
  • 450
  • 633
  • there is this code in copy.hpp: BOOST_STATIC_ASSERT( result_of::size::value == result_of::size::value); How is it that it is compiling for you? – MMM Oct 31 '14 at 23:26
  • It was changed between [v1.54](http://www.boost.org/doc/libs/1_54_0/boost/fusion/algorithm/auxiliary/copy.hpp) and [v.1.55](http://www.boost.org/doc/libs/1_55_0/boost/fusion/algorithm/auxiliary/copy.hpp) – sehe Oct 31 '14 at 23:34
  • @MMM I'm sure you can buy a newer version :) – sehe Oct 31 '14 at 23:37
  • is there a way to use a view to copy the minimum of the 2 sequences? – MMM Oct 31 '14 at 23:38
  • Yes. To do it generically, that'll be a bit of TMP, but of course you can. I'd consider just writing the copy operation as in 1.55 though (for the simple reason that it's not compiletime functionality anyways) – sehe Oct 31 '14 at 23:39
  • ok i just edited the copy.hpp directly into boost. I'll upgrade in a month or so anyways – MMM Oct 31 '14 at 23:45