Boost logo

Boost Users :

From: Joel de Guzman (joel_at_[hidden])
Date: 2008-07-22 04:38:44


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?

Cheers,

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net