Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-09-30 06:01:26


On 9/30/07, Dean Michael Berris <mikhailberis_at_[hidden]> wrote:
> Hi Everyone,
>

Hi Dean,

>
> Comments and suggestions would be most appreciated.
>

Very nice work. I have found a lot of things are very similar to my
simple_factory, especially now that has been ported to boost::fusion.

But your code is more well organized, although I find it a little bit
difficult for me, as example is not clear to me the whole part
regarding the invokers, indeed from your example code

void function(int argument) {
        // do something;
};

//...
dispatch::dispatcher<void (int), int> d;
d[0] = function;

//...
int input;
std::cin >> input;
d[0](input);

is not clear to me when and where this invokers are called given that
dispatcher::operator[] returns a function object reference. Or perhaps
I misread.

One very little point is why you use default template parameters here;

template <typename Signature,
                typename IndexType = int,
                                typename DecisionStrategy = boost::dispatch::detail::always_true<IndexType>,
                                typename RoutingStrategy =
boost::dispatch::detail::default_routing<IndexType>
>
            struct registry_impl

If it is instantiated only from here:

template <typename Signature,
            typename IndexType = int,
                        typename DecisionStrategy = boost::dispatch::detail::always_true<IndexType>,
                        typename RoutingStrategy =
boost::dispatch::detail::default_routing<IndexType>
>
                struct dispatcher : public boost::dispatch::detail::registry_impl <Signature,
            IndexType,
            DecisionStrategy,
            RoutingStrategy
>

where default parameters are already set.

>
> This still does not implement the multiple-signature feature which I'm
> still contemplating on putting in, but this is already useful by
> itself.
>

Once I have grasped more with your code would be nice to add this
part, or possibly to share your opinion on how to do it. As example
simple_factory uses a multimap to achieve this.

But the most difficult part is to allow "relaxed" type checking on
function arguments. As example

void function(int& counter) {
        counter++;
};

//...
dispatch::dispatcher<void (int&), int> d;
d[0] = function;

//...
int input = 6;
d[0](input);

std::cout << input << "\n"; // should be 7 now.

This is difficult with multiple-signature feature. I have implemented
this in simple_factory, but was not straightforward and I doubts my
approach is the best possible one, so I would really like to share
your implemantation ideas on this.

Thanks
Marco


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