Why is member look-up not allowed in return types of out-of-line definitions?

107 Views Asked by At

Consider the following code:

struct T {
    using iterator = int*;
    iterator begin() const;
    iterator end() const;
    /* ... */
};

// OK, member look-up allowed in trailing return types (since C++11)
auto T::begin() const -> iterator { /* ... */ }

// error: iterator does not name a type
iterator T::end() const { /* ... */ }

What is the rationale for making the second form impossible? It would obviously be useful if we could refer to the names of members in the return type. C++11 has remedied this somewhat, but what about C++98, or pre-standard "C with classes"?

I understand that it would require some form of look-ahead, since the parser cannot understand iterator until it has parsed T::end(). It shouldn't break compatibility with C, since C doesn't have out-of-line members, so we could implement this any way we want.

Is this too difficult for the compiler to implement -and if so, why-, or is it simply a design decision?

0

There are 0 best solutions below