Boost logo

Boost :

Subject: [boost] [Function] Interest in boost::functions that take and return references to self-type?
From: Tony Astolfi (tastolfi_at_[hidden])
Date: 2009-11-16 10:17:47

Would there be interest in adding a feature to boost::function that allows a
function to accept as input and return values of the same type as itself?

I think this would be useful for implementing state machines.

Something like:

typedef boost::function< boost::function_self_type (event const&) >

state_transition_fcn initial_state (event const& e);
state_transition_fcn second_state (event const& e);

state_transition_fcn initial_state (event const& e)
    if (/* some predicate on e*/) {
        // go to new state
        return &second_state;
    } else {
        // stay in old state
        return &initial_state;

state_transition_fcn current_state = &initial_state;
while (more_events) {
    current_state = current_state( next_event );

-Tony Astolfi

ps. Please point me in the right direction if such a thing already exists!

Boost list run by bdawes at, gregod at, cpdaniel at, john at