// ... is included for iostream and fusion in snipped ... naming location fusion = boost: : Fusion; Class base {secure: int x; Public: Base (): x (0) {} zero Chugh () {x ++; Cout & lt; & Lt; "I am a base .. now x" " & Lt; X & LT; & Lt; Endl; }}; Class alpha: public base {public: zero cheat () {x + = 2; Cout & lt; & Lt; "Hi, I'm an alpha, x is now" Chug (); }}; Int main () {typedef fusion :: vector & lt; Base *, Alpha *, Bravo *, Base * & gt; material; Material Goods (New Base, New Alpha, New Bravo, New Base); Fusion :: for_each (content, chat ()); // replaces each element in the stuff as expected / output: I am a base. Now X is 1 Hi, I am an alpha, now x is 2 Hello, I am a Bravo; X is now 3 I'm a base X Now 1 * / cout & lt; & Lt; Endl; // If I do not put 'const' in front of 'content' ... typedef fusion :: result_of :: push_back & lt; Constant Stuff, Alpha * & gt; :: Type NewStuff; // ... then it complains because it wants to be the stuff: NewStuff newStuff = fusion :: push_back (stuff, new alpha); // ... but since the stuff is now const, now I can not change its elements :( Fusion :: Fresh_Ech (new stuff, Chugh ()); 0;};
How do I get for_each (new stuff, chug) to work?
(Note: I only encourage: Fusion believes that whenever I call push_back, New vector should be made. (Note: I only believe in promotions with very short documents:
: Fusion is to make a new vector every time I call push_back.)
You are not creating a new vector. push_back
If you want to create a new vector on the lazy evaluation extended sequence, for example typedef
newstuff
like
typedef fusion :: vector
Your program works then.
BTW, Fusion is a very work I think that it would be more F as if you store actual objects instead of pointers and use transform
then chug
logic from class to < Code> struct chug which will not be suitable for every type of operator then any new vector will be created, you can work with ideas with sluggish evaluation.
Comments
Post a Comment