$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] [Statechart] Passing reference tocreate_processor()
From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2009-04-23 09:19:46
Steve & Igor,
I must admit I don't currently see why this happens, I'll probably have to 
produce a minimal repro and ask bind experts for help.
For now, you might want to try the attached work-around (note the additional 
conversion operator in class Object). This compiles for me on VC9.0 and 
seems to work as expected. Yes, this is an ugly hack but it has the 
advantage that it can be reverted relatively quickly once I've figured out 
how to fix this bug. Alternatively, you could change Test so that it accepts 
an Object * (or any smart ptr) rather than an Object &, but that would of 
course require changes in several places in the code, not just one as in my 
suggestion.
For now I'll have to stop here, I'll pursue this further next weekend.
HTH,
Andreas
#include <boost/statechart/asynchronous_state_machine.hpp>
#include <boost/statechart/fifo_scheduler.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/noncopyable.hpp>
#include <boost/ref.hpp>
class Object : public boost::noncopyable
{
    public:
        Object() {}
        operator boost::reference_wrapper<Object>() // <-- HERE
        {
            return boost::ref(*this);
        }
};
struct Initial;
struct Test : boost::statechart::asynchronous_state_machine<Test, Initial>
{
    public:
        Test(my_context ctx, Object &) : my_base(ctx) {}
};
struct Initial : boost::statechart::simple_state<Initial, Test> {};
int main()
{
    Object value;
    boost::statechart::fifo_scheduler<> scheduler;
    const boost::statechart::fifo_scheduler<>::processor_handle processor1 =
        scheduler.create_processor<Test>(boost::ref(value));
    scheduler.initiate_processor(processor1);
    scheduler.operator ()();
    return 0;
}