Boost logo

Boost :

From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2007-03-14 17:37:23


 
Frank Mori Hess wrote:

> > The usage of operator overloading has one advantage over a similar
> > solution using functions, though. When combining futures
> you ultimately
> > want to flatten the composed return types: i.e. for a f1 || f2 || f3
> > (with different return types T1, T2 and T3) you want to get a
> > variant<T1, T2, T3> as the composite return type and not a
> > variant<variant<T1, T2>, T3> (as you would get using simple
> functions
> > taking two parameters).
> >
> > This naturally involves some meta template magic to construct the
> > required return types. Using functions you'll have to do
> this by hand,
> > using operators you can reuse existing meta-template frameworks like
> > proto allowing to implement this with minimal effort.
>
> Why couldn't you just overload the function to take varying
> numbers of
> arguments? I'll just use the name "compose_variant" for illustration:
>
> variant<T1, T2> compose_variant(T1 t1, T2 t2);
> variant<T1, T2, T3> compose_variant(T1 t1, T2 t2, T3 t3);
> // ...

Ease of implementation. No need to implement a varying number of overloads
for one function or a single complex function having all but one default
arguments. But that's a matter of style and taste...

Regards Hartmut


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