Boost logo

Boost Users :

From: simonwlb (conic_at_[hidden])
Date: 2002-04-16 20:33:50


--- In Boost-Users_at_y..., Douglas Gregor <gregod_at_c...> wrote:
> On Monday 15 April 2002 06:56 am, you wrote:
> > Has anyone managed to use boost::function<> with Sun WorkShop 6
> > update 2? For me, it causes the compiler to core dump.
> >
> > Simon Bailey
>
> I don't believe anyone has gotten this to work, unfortunately. I
have access
> to this compiler now, so I might be able to port boost::function
to it.
>
> Doug

Glad you're on it Doug - it's a very useful class on its own and
essential for boost::threads. If any one's interested, I've whipped
up a rough version of boost::function (which only handles
functors). It's enough to get boost::threads working.

Simon

class function_holder_base // detail
{
public:
        virtual ~function_holder_base() {}
        virtual void operator()() = 0;
        virtual function_holder_base* copy() const = 0;
};

#endif // !defined(WU_FUNCTION_HOLDER_BASE_H_)

template<typename F>
class function_holder : public function_holder_base // detail
{
public:
        function_holder(const F& f) : m_f(f) {}
        ~function_holder() {}
        void operator()() { m_f(); }
        function_holder_base* copy() const { return new
function_holder(*this); }

private:
        F m_f;
};

class function
{
public:
        template<typename F> function(const F& fb) : m_fb(new
function_holder<F>(fb)) {}
        function(const function& r) : m_fb( (r.m_fb)->copy() ) {}
        function() : m_fb(0) {}
        function& operator=(const function& r)
        {
                std::auto_ptr<function_holder_base> fb( (r.m_fb)-
>copy() );
                if(fb.get())
                {
                        delete m_fb;
                        m_fb = fb.release();
                }
                return *this;
        }
        ~function() { delete m_fb; }
        void operator()() { m_fb->operator()(); }
        operator bool() const { return m_fb != 0; }
        void clear() { delete m_fb; m_fb = 0; }

private:
        function_holder_base* m_fb;
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net