Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2004-02-08 15:27:59


On Sun, Feb 08, 2004 at 09:04:11PM +0100, Fredrik Blomqvist wrote:
> What I want to add to the discussion is that I believe we need _two_
> versions of return_type (or whatever we choose to call it).
> Even though I like the power and syntax of the result_of<F(a,b)>, I'd say
> it's not unreasonable to be in a situation where the argument types (if any)
> simply aren't know. In such cases a plain return_type<F> that would atleast
> make an "educated guess" would be better than nothing.

Here you go:

   template <class F> struct educated_guess_return_type
      { typedef int result_type; };

It is right every time the actual return type is "int"! :)

Seriously, can you show a case how "educated guess" is better than
nothing? My instincts tell me that it's better to fail to compile than
to guess the wrong type and start having random implicit conversions
start kicking in.

In the (rare?) case where the return type of F doesn't depend on its
arguments, then it either (a) it should probably just declare an
F::result_type (in which case I think result_of<F> may work), or (b)
just doing result_of<F(int,int)> (where 'int' is arbitrary) seems likely
to 'get the right answer' anyway.

-- 
-Brian McNamara (lorgon_at_[hidden])

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