Boost logo

Boost :

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


I'm sorry - the exception_ptr_impl.hpp needs a modification (case where no user defined types are passed). Now it's corrected.
Oliver

/***************************************************************************
 * Copyright (C) 2008 by Oliver Kowalke *
 * kowalke_at_drslx002 *
 * *
 * This program is free software; you can redistribute it and/or modify *
 * it under the terms of the GNU General Public License as published by *
 * the Free Software Foundation; either version 2 of the License, or *
 * (at your option) any later version. *
 * *
 * This program is distributed in the hope that it will be useful, *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
 * GNU General Public License for more details. *
 * *
 * You should have received a copy of the GNU General Public License *
 * along with this program; if not, write to the *
 * Free Software Foundation, Inc., *
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
 ***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#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("X error"); 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::future_wrapper< int > 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