Boost logo

Boost :

Subject: Re: [boost] [Bind] How do I get bind to deduce the return type offor_each?
From: Peter Dimov (pdimov_at_[hidden])
Date: 2010-04-16 15:48:20


Thomas Jordan wrote:
> Thanks a lot for the suggestion, I did take a look at Lambda library, and
> I saw that it used some extra type information in its STL
> algorithm wrappers (the 'sig') to help it figure out the return types.
> However, I am against using the Lambda library
> for other reasons, I only want to use the bind library. I'd appreciate
> some specific advice on how to get the type deduction
> with the Boost.bind library. Or is this just not possible with
> Boost.bind?

It's not. Boost.Bind only supports function objects with a specific, fixed
type. There is no mechanism to tell it that the return type of

struct myForEach
{
   template <typename II, typename F>
   F operator()(II begin, II end, F function) const
   {
      return std::for_each(begin, end, function);
   }
};

is the same as its third argument. In this specific case I'd just use

struct myForEach
{
   typedef void result_type;
   template <typename II, typename F>
   void operator()(II begin, II end, F function) const
   {
      std::for_each(begin, end, function);
   }
};
 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk