Boost logo

Boost :

Subject: Re: [boost] [Bind] How do I get bind to deduce the return type offor_each?
From: Thomas Jordan (thomasjordan_at_[hidden])
Date: 2010-04-19 14:48:16


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?

Peter Dimov replied:

-----------------

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);
   }
};

--------------------

Thanks, Peter, and thanks to everyone else who replied, for their helpful suggestions.

FWIW, I'm putting together a presentation for my colleagues, to show the facilities for higher-order programming in STL and Boost, and I wanted to show a couple of 'out-there' examples to illustrate their power. I'm a bit of an arriviste and my C++ is 'improving,' but I'm really impressed that you can do functional-style programming so nicely in C++.

Regards, Tom.


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