|
Boost : |
Subject: [boost] [bind] [patch] support for result_of
From: Stefan Strasser (strasser_at_[hidden])
Date: 2010-08-15 09:23:30
Hi,
would a full implementation of this patch:
https://svn.boost.org/trac/boost/raw-attachment/ticket/4542/bind.patch
be accepted to Boost.Bind?
it provides support for bind()ing generic function objects and for
boost::result_of<F(...)> where F is a result of bind().
for example:
struct F{
template<typename T>
T operator()(T const &t, int) const{ return t; }
template<typename Args>
struct result;
};
the result type depends on the argument type, so instead of
"result_type", "result" is defined according to boost::result_of:
template<typename T>
struct F::result<F(T const &,int)>{ typedef T type; }
this function object can not be used with bind(), because bind()
requires F::result_type to be defined.
with the patch, you can bind() the function object, and determine the
result of the bound function object using result_of:
int main(){
g(bind(F(),_1,5));
}
template<typename F>
void g(F const &f){
double doubleres=f(1.234); //F(1.234,5) -> double
boost::result_of<F(int const &)>::type intres=f(1); // F(1,5) -> int
}
C++ TR1 includes result_of and bind(). it doesn't seem to say anything
about result_of<bind()-result> though.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk