Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2008-06-03 15:27:29


On Tue, Jun 3, 2008 at 5:19 PM, Daniel Walker <daniel.j.walker_at_[hidden]> wrote:
>
> The reason result_of couldn't deduce argument dependent return types
> for nullary invocations in C++98 is that according to the heuristic
> only the result_type member is checked for nullary calls, and for
> non-nullary calls if the result_type is present, result<> is never
> checked. So, you can't have both.
>

Thanks Daniel and Tobias for you explanation. Now this point it's clear to me.

Here it is another undocumented behaviour of boost::fusion.

Did you know that dereferencing a fusion iterator to a mpl sequence
causes a duplication of the pointed object?

Following the test code:

static int cnt = 0;

struct Test
{
     Test() { cnt++; }
};

using namespace boost::fusion;

int main(int, char**)
{
    typedef boost::mpl::vector<Test,Test> Mpl_vec;

    Mpl_vec mpl_vec;

    result_of::begin<Mpl_vec>::type iter = begin(mpl_vec);

    cout << cnt << endl; // prints 0

    deref(iter);

    cout << cnt << endl; // prints 1

    *iter;

    cout << cnt << endl; // prints 2

    return 0;
}

I found this while traversing a sequence with fusion::for_each because
code started to create a lot of copies of the sequence elements,
indeed the whole sequence is duplicated each time it's traversed with
fusion::for_each !!

Is this foreseen or it's a bug.

Thanks
Marco

BTW dereferencing an iterator to a fusion sequence does not show this
behaviour and does not copy anything.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk