Boost logo

Boost :

From: Kowalke Oliver (QD IT PA AS) (Oliver.Kowalke_at_[hidden])
Date: 2008-04-14 08:32:59

Hello Vincente,

> This is very elegant on the context of the future library.

thank you :))

> It will be nice if the exec_function, the catch_exception and
> the catch_ellipsis do not depend directly on the promise<R>.

If desired I would suggest that exception_ptr will handle arbitrary user-defined
exception types. The function detail::_exp_current_exception (I'm refering to exception_ptr_impl.hpp from Braddogs future library) mußt be a template which gets the arbitrary user-defined exception types as tempalte arguments. I append a first shot of the code (modified versions of future and exception_ptr):

#include <iostream>
#include <cstdlib>
#include <stdexcept>

#include <boost/bind.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/thread.hpp>

#include <future.hpp>

struct X
        std::string msg;

        X( std::string const& msg_)
        : msg( msg_)

int add( int a, int b)
{ throw X("abc"); return a + b; }

void execute( boost::function< void() > fn)
{ fn(); }

int main( int argc, char *argv[])
                boost::promise< int > p;
                boost::future_wrapper< int, boost::mpl::vector< X > > wrapper(
                boost::future< int > f( p);

                boost::thread t(
                                & execute,
                                wrapper) );

                std::cout << "add = " << f.get() << std::endl;

                return EXIT_SUCCESS;
        catch ( X const& x)
        { std::cerr << x.msg << std::endl; }
        catch ( std::exception const& e)
        { std::cerr << e.what() << std::endl; }
        catch ( ... )
        { std::cerr << "unhandled exception" << std::endl; }
        return EXIT_FAILURE;

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