Cheenu Srinivasan | 1 Feb 2004 14:45
Picon
Favicon

return type of boost::bind

I wish to store the return value of boost::bind in an intermediate object
to invoke it at a later time.  I only ever see examples which combine
the call to boost:bind with the immediate invocation on the returned
object such as:

    #include <boost/bind.hpp>
    using namespace boost;
    #include <iostream>
    using namespace std;

    double f(int i, double d) {
      cout << "int = " << i << endl;
      return d;
    }

    main() {
      int i = 99;
      cout << bind(f, _1, 1.234)(i) << endl;
    }

Instead I'd like to postpone the call to the returned object.  What's the 
type of obj?

  main() {
    int i = 99;
    WHAT_IS_MY_TYPE obj = bind(f, _1, 1.234);
    ...
    cout << obj(i) << endl;
}

(Continue reading)

Duane Murphy | 1 Feb 2004 19:15
Picon
Gravatar

Re: return type of boost::bind

The return type of boost::bind is fairly indeterminate. In order to call
a bound function at a later time, look at boost::function. It does a nice
job of holding on to a function that uses boost::bind.

--- At Sun, 1 Feb 2004 08:45:43 -0500, Cheenu Srinivasan wrote:

>I wish to store the return value of boost::bind in an intermediate object
>to invoke it at a later time.  I only ever see examples which combine
>the call to boost:bind with the immediate invocation on the returned
>object such as:
>
>    #include <boost/bind.hpp>
>    using namespace boost;
>    #include <iostream>
>    using namespace std;
>
>    double f(int i, double d) {
>      cout << "int = " << i << endl;
>      return d;
>    }
>
>    main() {
>      int i = 99;
>      cout << bind(f, _1, 1.234)(i) << endl;
>    }
>
>Instead I'd like to postpone the call to the returned object.  What's the 
>type of obj?
>
>  main() {
(Continue reading)

Cheenu Srinivasan | 1 Feb 2004 20:09
Picon
Favicon

Re: return type of boost::bind

Duane Murphy wrote:
> The return type of boost::bind is fairly indeterminate. In order to call
> a bound function at a later time, look at boost::function. It does a nice
> job of holding on to a function that uses boost::bind.

I looked at "Using bind with Boost.Function" in the boost::function docs.
Mimicing that, for my example, I tried:

  boost::function<double (int)> bound_func = boost::bind(f, _1, 1.234);
  int i = 99;
  cout << bound_func(i) << endl;

but it throws a bad_function_call exception when bound_func(i) is invoked.
How do I use boost::function for this situation?

Thanks.
Cheenu

I wrote:
> >I wish to store the return value of boost::bind in an intermediate object
> >to invoke it at a later time.  I only ever see examples which combine
> >the call to boost:bind with the immediate invocation on the returned
> >object such as:
> >
> >    #include <boost/bind.hpp>
> >    using namespace boost;
> >    #include <iostream>
> >    using namespace std;
> >
> >    double f(int i, double d) {
(Continue reading)

Peter Dimov | 1 Feb 2004 21:29

Re: return type of boost::bind

Cheenu Srinivasan wrote:
> Instead I'd like to postpone the call to the returned object.  What's
> the type of obj?
> 
>   main() {
>     int i = 99;
>     WHAT_IS_MY_TYPE obj = bind(f, _1, 1.234);
>     ...
>     cout << obj(i) << endl;
> }

You can use a separate function template:

template<class F> void test(F f)
{
    int i = 99;
    std::cout << f(i) << std::endl;
}

int main()
{
    test( boost::bind(f, _1, 1.234) );
}
Peter Dimov | 1 Feb 2004 21:31

Re: return type of boost::bind

Cheenu Srinivasan wrote:
> Duane Murphy wrote:
>> The return type of boost::bind is fairly indeterminate. In order to
>> call a bound function at a later time, look at boost::function. It
>> does a nice job of holding on to a function that uses boost::bind.
> 
> I looked at "Using bind with Boost.Function" in the boost::function
> docs. Mimicing that, for my example, I tried:
> 
>   boost::function<double (int)> bound_func = boost::bind(f, _1, 1.234);
>   int i = 99;
>   cout << bound_func(i) << endl;
> 
> but it throws a bad_function_call exception when bound_func(i) is
> invoked. How do I use boost::function for this situation?

Works for me; it's probably a compiler bug. Which compiler are you using?

Try

boost::function<double (int)> bound_func( boost::bind(f, _1, 1.234) );

instead.
Cheenu Srinivasan | 1 Feb 2004 22:42
Picon
Favicon

Re: return type of boost::bind

Peter Dimov wrote:
> Cheenu Srinivasan wrote:
> > Duane Murphy wrote:
> >> The return type of boost::bind is fairly indeterminate. In order to
> >> call a bound function at a later time, look at boost::function. It
> >> does a nice job of holding on to a function that uses boost::bind.
> > 
> > I looked at "Using bind with Boost.Function" in the boost::function
> > docs. Mimicing that, for my example, I tried:
> > 
> >   boost::function<double (int)> bound_func = boost::bind(f, _1, 1.234);
> >   int i = 99;
> >   cout << bound_func(i) << endl;
> > 
> > but it throws a bad_function_call exception when bound_func(i) is
> > invoked. How do I use boost::function for this situation?
> 
> Works for me; it's probably a compiler bug. Which compiler are you using?
> 
> Try
> 
> boost::function<double (int)> bound_func( boost::bind(f, _1, 1.234) );
> 
> instead.

With MSVC 7.1. the exception is thrown with both 'bound_func = bind(...)'
and 'bound_func(bind(...))'.  But I tried it with g++/solaris and it works.
So it does look like a bug with the MS compiler.  Thanks.
Peter Dimov | 1 Feb 2004 23:06

Re: return type of boost::bind

Cheenu Srinivasan wrote:
>
> With MSVC 7.1. the exception is thrown with both 'bound_func =
> bind(...)' and 'bound_func(bind(...))'.  But I tried it with
> g++/solaris and it works. So it does look like a bug with the MS
> compiler.  Thanks.

It works for me in MSVC 7.1, but I'm using the CVS version of Boost. It may
be a bug in 1.30.2 (if that's what you are using). You may download 1.31
release candidate 2 from

    http://www.esva.net/~beman/boost_1_31_0_rc2.zip

to verify that the problem does not occur with the immininent 1.31 release.
Ben Chan | 2 Feb 2004 04:04
Picon
Favicon

Compliation speed of Boost.Signal in C++ Builder 5

Dear All,
I'm new to boost and trying to use boost.signal in my BCB 5.0 
project,everything works fine except my project compilation speed was 
horribly slow down.Once I included the <signal.hpp>,the compiler have to 
compile extra thousands line of code even my project is empty.I did put the 
signal.hpp file in my pre-compiled header and include the static lib, but 
seems it can't help much.
Any suggestion to improve the compliation speed in BCB?VC7.0 seems compile 
pretty fast.
Thx
Ben

_________________________________________________________________
Linguaphone :  Learning English? Get Japanese lessons for FREE 
http://go.msnserver.com/HK/30476.asp
Vikrant Rathore | 2 Feb 2004 05:54

cannot compile boost with dev-cpp 4.9.8.0

HI,

Anyone has compiled boost library successfully using dev-cpp the new 
version. I try compiling it and it gives many errors. 

I follow the following qway to compile:

C:\projects\boost>

C:\projects\boost>set path=c:\dev-cpp\bin

C:\projects\boost>set MINGW_ROOT_DIRECTORY=c:\dev-cpp

C:\projects\boost>set MINGW_BIN_DIRECTORY=c:\dev-cpp\bin

C:\projects\boost>set MINGW_INCLUDE_DIRECTORY=c:\dev-cpp\include

C:\projects\boost>set MINGW_STDLIB_DIRECTORY=c:\dev-cpp\lib

C:\projects\boost>bjam -sTOOLS=mingw

I tried many different option including usig MSYS with no luck.

Thanks
with best regards,
Vikrant
Vikrant Rathore | 2 Feb 2004 12:47

boost compile problem using dev-cpp 4.9.8.5

Hi Everyone,

Please help!!!!

I am trying to compile boost library with dev-cpp. It does not compile and 
gives many errors. I can use the filesystem library as it does not require pre 
compilation. But I want to use regex and test suite library. Boost.Python 
error is fine. But other library also do not compile.

I have followed the documentation and set the enviroment variables to

C:\projects\boost>

C:\projects\boost>set path=c:\dev-cpp\bin

C:\projects\boost>set MINGW_ROOT_DIRECTORY=c:\dev-cpp

C:\projects\boost>set MINGW_BIN_DIRECTORY=c:\dev-cpp\bin

C:\projects\boost>set MINGW_INCLUDE_DIRECTORY=c:\dev-cpp\include

C:\projects\boost>set MINGW_STDLIB_DIRECTORY=c:\dev-cpp\lib

I receive more than 3000 lines in error some of them are attached:

---------------------------------------------------------------------
skipping Boost.Python library build due to missing or incorrect configuration

couldn't find Python.h in "c:/tools/python/include"

(Continue reading)


Gmane