$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: [boost] [function] support for overloaded function
From: Oliver Kowalke (k-oli_at_[hidden])
Date: 2008-10-30 04:35:36
Hello,
how can I support the return type of bind as well as function as function argument in following code.
regards,
Oliver
#include <iostream>
#include <cstdlib>
#include <stdexcept>
#include <boost/bind.hpp>
#include <boost/function.hpp>
struct X {};
struct Y
{
       template< typename R >
       void f( boost::function< R() > const& fn)
       {}
       template< typename R >
       void f( boost::function< R( X &) > const& fn)
       {}
};
struct Z
{
       int u( int i)
       { return i; }
       int v( X & x, int i)
       { return i; }
};
int main( int argc, char *argv[])
{
        try
       {
              Y y;
              X x;
              Z z;
              // does not compile
              y.f(
                     boost::bind(
                            & Z::u,
                            z,
                            1) );
              boost::function< int() > fn1(
                     boost::bind(
                            & Z::u,
                            z,
                            1) );
              y.f( fn1);
              // does not compile
              y.f(
                     boost::bind(
                            & Z::v,
                            z,
                            _1,
                            1) );
              boost::function< int( X &) > fn2(
                     boost::bind(
                            & Z::v,
                            z,
                            _1,
                            1) );
              y.f( fn2);
              return EXIT_SUCCESS;
       }
       catch ( std::exception const& e)
       { std::cerr << e.what() << std::endl; }
       catch ( ... )
       { std::cerr << "unhandled" << std::endl; }
       return EXIT_FAILURE;
}
-- Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten Browser-Versionen downloaden: http://www.gmx.net/de/go/browser