Boost logo

Boost :

From: Herb Sutter (hsutter_at_[hidden])
Date: 2002-02-19 14:50:44


> >>---------------------------------
> If the return expression includes anything else, including more than one
> auto variables, it could involve an implicit conversion.
>
> template<typename A, typename B>
> auto operator+(A a, B b)
> {
> return a + b; // posible implicit conversion here.
> }
> <<--------------------------------------------------
> Yes!
> And we don't know what that conversion is! And we can't ask the
> compiler to tell us. Instead in LL, we had to do pages of
> type deduction code that "knows" what the conversions are. And
> if you are using a user defined class that has overloaded
> operator +() you have to tell us what the return type is. Its
> arcane, and the compiler does know it. But we can't find out.
> And we don't really care what it is, other than to pass it
> along to the calling function.
>
> You wouldn't believe what a killer issue this is until you
> try it. (Jeremy S. knows that's for sure, as does Peter D.)

I didn't quite follow that. Let's assume both auto and strict typeof:

  template<typename A, typename B>
  operator+(A a, B b)
  {
    return a + b;
  }

  typeof( operator+<X,Y>( X(), Y() ) )
  typeof( X() + Y() )

In this example, what is the type you are looking for? Can the two be
different? I'm actually still trying to get my head around operator+ invoking
operator+ on its own operands, which looks infinitely recursive, so I'm sure I
don't yet understand the problem and I want to be educated. Thanks,

Herb


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