Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Signal Network and Boost.Fusion

The components in the Signal Network library are implemented using Boost.Fusion. To use the Signal Network library, you might benefit from the following if you're not familiar with fusion.

Fused vs. unfused

A simple C++ function object might look something like this:

struct f
{
    int operator()(int arg1, int &arg2, const std::string &arg3)
    {
        ...
    }
}

The thing to note here is that there are three arguments (of types int, int &, and const std::string & respectively), and that when the function object is invoked, they are passed separately:

int x;
std::string s;
f()(1, x, s);

In the terminology of Boost.Fusion, this function object is unfused. This is in contrast to a fused fuction object, which might look like this:

struct fused_f
{
    int operator()(fusion::vector<int, int &, const std::string &> &args)
    {
        ...
    }
}

Basically, the difference is that the three arguments from the unfused version are now sent in a single fusion container. The benefit is that no matter how many "unfused" arguments there are, there is always a single "fused" argument. Hence, writing templates that deal with a variable number of arguments becomes a lot simpler.

Signal Network provides both fused and unfused components

While writing the generic components provided in the Signal Network library benefits from using Boost.Fusion, your particular use case might not. For this reason, every component provided by the Signal Network library:

The type of sent signal is provided as a template argument to the class, and the default value can be set by defining SIGNAL_NETWORK_DEFAULT_OUT to either unfused or fused before including a sinal network component.

For example,

signals::storage<int (int, int &, const std::string &>), signals::unfused> unfused_storage;
signals::storage<int (int, int &, const std::string &>), signals::fused> fused_storage;

In the above case, unfused_storage is similar to f above, and can be used as a slot for signals which carry regular, unfused arguments. On the other hand, fused_storage acts as a function object similar to fused_f above. Hence, it can be used as a slot for signals which carry a fusion container as an argument.

Copyright © 2007 Stjepan Rajko

PrevUpHomeNext