Boost logo

Boost :

From: Kowalke Oliver (QD IT PA AS) (Oliver.Kowalke_at_[hidden])
Date: 2008-04-14 03:26:07


Sorry - didn't read your docu carefully. As you say in the docs 'However, arbitrary user-defined exception types cannot be supported.'.

What about to specify an mpl::vector with arbitrary user-defined exception types?
I'm using your future library siunce last year with this little modification (at least for me it works).
Oliver

template<
     typename R,
     typename V = mpl::vector<>
>
  class future_wrapper
  {
    public:
      future_wrapper(const boost::function<R (void)> &fn, const promise<R> &ft ) : fn_(fn), ft_(ft) {}; // stores fn and ft
      void operator()() throw() { // executes fn() and places the outcome into ft

            typedef typename boost::mpl::fold<
                V,
                detail::exec_function,
                detail::catch_exception< boost::mpl::_1, boost::mpl::_2 >
>::type exec_type;

           detail::catch_ellipsis< exec_type >::exec( fn_, ft_);
      }
    private:
      boost::function<R (void)> fn_;
      promise<R> ft_;
  };

struct exec_function
        {
                template< typename R >
                static void exec(
                        boost::function< R ( void) > const& fn,
                        boost::promise< R > & ft)
                { ft.set( fn() ); }

                static void exec(
                        boost::function< void ( void) > const& fn,
                        boost::promise< void > & ft)
                {
                        fn();
                        ft.set();
                }
        };

        template<
                typename P,
                typename E
>
        struct catch_exception
        {
                template< typename R >
                static void exec(
                        boost::function< R ( void) > const& fn,
                        boost::promise< R > & ft)
                {
                        try
                        { P::exec( fn, ft); }
                        catch ( E const& e)
                        { ft.set_exception( e); }
                }

                static void exec(
                        boost::function< void ( void) > const& fn,
                        boost::promise< void > & ft)
                {
                        try
                        { P::exec( fn, ft); }
                        catch ( E const& e)
                        { ft.set_exception( e); }
                }
        };

        template< typename P >
        struct catch_ellipsis
        {
                template< typename R >
                static void exec(
                        boost::function< R ( void) > const& fn,
                        boost::promise< R > & ft)
                {
                        try
                        { P::exec( fn, ft); }
                        catch (...)
            { ft.set_exception(boost::detail::current_exception() ); }
                }

                static void exec(
                        boost::function< void ( void) > const& fn,
                        boost::promise< void > & ft)
                {
                        try
                        { P::exec( fn, ft); }
                        catch (...)
            { ft.set_exception(boost::detail::current_exception() ); }
                }
        };

> Hello,
> is it correct that user defined exceptions thrown by the
> defered function object will be rethrown as as
> std::runtime_error (if it was derived from std::exception) or
> std::bad_exception?
> If yes - what about specifying an mpl::vector with user
> defined exception types (passing to future_wrapper etc.)?
> regards, oliver
>
> > I wanted to formally request a review of my Futures library.
> > Latest Version: http://braddock.com/~braddock/future/
> >
> > The library has matured greatly over the past year. It has been
> > heavily used as a key component in a mid-sized commercial
> application
> > on both Linux and Windows. Extensive unit tests and (just
> > now) documentation have been written - in fact there are more than
> > twice as many lines of test code and documentation than are in the
> > library proper.
> >
> > The library incorporates many ideas from this list, from other
> > prospective submissions, other languages, and from academic papers.
> >
> > The library does not currently use jamfiles or boostdoc (I tried I
> > really did). It is a header-only library. The documentation is
> > currently straight HTML, and should be very easy to translate to
> > boostdoc if the submission looks good.
> >
> > NOTE - to avoid confusion, note that there is an older 2005
> > boost.future candidate in the vault by Thorsten Schuett that is not
> > related to mine (although it was studied early on).
> >
> > Thanks,
> > Braddock Gaskill
> > braddock_at_[hidden]
> >
> > _______________________________________________
> > Unsubscribe & other changes:
> > http://lists.boost.org/mailman/listinfo.cgi/boost
> >
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


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