Boost logo

Boost Users :

Subject: [Boost-users] [Fusion] The very basics!
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2010-03-10 04:40:05


I don't mind admitting that I'm finding Fusion a struggle to get my head
round; there's
something about the compile time/run time duality that makes my brain hurt!

So, a really basic question...

When I write this, pretty much verbatim from the examples, despite there
being the
appearance of a loop, this is in fact a linear invocation of three calls to
print::operator(),
and since the fusion vector is entirely known at compile time, as all fusion
types must
be, regardless of how constructed, this "loop" is completely "unrolled" at
compile time.

Is this correct?

Thanks,

- Rob.

#include <typeinfo>
#include <iostream>
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/include/algorithm.hpp>

struct print
{
    template <typename T>
    void operator()(T const& x) const
    {
        std::cout << x << " ";
    }
};

int main( )
{
    using namespace boost::fusion;

    vector<int, char, std::string> stuff(1, 'x', "howdy");
    for_each(stuff, print());
    std::cout << std::endl;
}



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