Indiana Unversity logo[ConceptGCC]

ConceptGCC :

Re: Addable

From: Doug Gregor (dgregor_at_[hidden])
Date: 2007-03-09 15:18:51


On Mar 8, 2007, at 4:39 PM, Martin Sebor wrote:

> Doug Gregor wrote:
>> On Mar 8, 2007, at 2:50 PM, Martin Sebor wrote:
>>> Okay, thanks.
>>>
>>> I don't think it's part of the proposal but I think it might
>>> be useful to make it possible to use the same syntax in
>>> non-template code as within templates. Maybe via a using
>>> declaration or directive:
>>>
>>> int main () {
>>> foo a, b;
>>> using std::Addable<foo>::operator+;
>>> // or using std::Addable<foo> to get all signatures
>>> foo c = a + b;
>>> }
>>>
>>> Has this been considered and would it be feasible?
>>
>> It's been considered, but it does not appear feasible. Doing
>> something like this:
>>
>> using std::Addable<int>::operator+;
>>
>> means that we would essentially be changing the meaning of the built-
>> in operator+ for integers (!)
>
> We're already doing that in templates. How cool is that?! ;-)

We're only doing it in constrained templates, because we turn 'T + T'
into something like Addable<T>::operator+ when we type-check the
definition of the template.

> FWIW, I suspect there is quite a bit of code out there (I know
> we have some) where ordinary functions participate in the same
> overload set as function template specializations (explicit or
> implicit) when resolving calls from function templates. Ending
> up with calls to different functions depending on whether the
> call is made directly from a template or indirectly through an
> intermediate call to a non-template overload would, IMO, be
> surprising. This seems close to the issue we discussed at our
> meeting (the behavior of calls to unconstrained templates from
> constrained ones).

It sounds like a similar issue, yes. Although, how often does a
template make a call through a non-template?

        Cheers,
        Doug