|
Boost : |
From: Kowalke Oliver (QD IT PA AS) (Oliver.Kowalke_at_[hidden])
Date: 2008-04-14 08:38:26
the code works at least with gcc 4.2.3
Oliver
> #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[])
> {
> try
> {
> boost::promise< int > p;
> boost::future_wrapper< int,
> boost::mpl::vector< X > > wrapper(
> boost::bind(
> add,
> 11,
> 13),
> p);
> boost::future< int > f( p);
>
> boost::thread t(
> boost::bind(
> & 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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk