On Tue, Jul 22, 2008 at 10:38 AM, Joel de Guzman <joel@boost-consulting.com> wrote:
Istvan Buki wrote:

   Why do you have to use metl::result_of?  Wouldn't it be simpler to
   have a
   result typedef inside the filter? ('typedef filter_t::result
   filter_result_t')


Again, this  started as a fusion learning experiment and I decided to use the same convention as fusion to construct the result types.
I admit it is not clear to me what reason decided the fusion developers to use the result_of namespace instead of a typedef inside the algorithm classes.

Various reasons:
1) A typedef is not good enough[x]. It has to be a template because
  the result-type is potentially dependent on the argument types.
  IOTW, the actual result type can change depending on what you
  pass.

2) The result_of namespace contains all the metafunction counterparts
  of all the functions. They mimic, as much as possible, what you have
  in MPL. So, if you want to do pure type computations, you can
  use the result_of namespace.

[x]: Take a simple function:

      template <typename T>
      T square (T val) { return val * val; }

- What is the result type of square? Can it be a typedef?
- How can you write a C++ utility that will give you this type?
 E.g. I want to call this function with an argument of int,
 but I want to know the result type beforehand so I can put
 the result in a vector.

It's obvious what the result is with our example above. But say
I have another function with a more complicated result type.
How do you automate this task for the user?


Thanks for explaining. It makes perfect sense now.