On Fri, 12 Jul 2024 at 17:58, Dalbey, Keith via Gcc <gcc@gcc.gnu.org> wrote:
>
> I'm not going to argue about the change for CONCRETE operators, I'm going to 
> argue about the loss of power/flexibility for TEMPLATED operators, because it 
> defeats the whole purpose of TEMPLATED functions/operators otherwise

This is quite silly hyperbole. There are many, many good uses of
function templates that are not affected by when lookup is done, and
finding invalid declarations in the wrong scope is not "the whole
purpose" of function templates.

It's hard to take the rest of your email seriously after that.


>
> I've attached the header file in question... it's mostly about outputting STL 
> containers (like vectors, pairs, std::shared_ptr, the file name originates 
> when I was just using it for vectors but I since expanded it to other STL 
> containers, not sure that std::shared_ptr technically qualifies as a 
> "container")

The header isn't very helpful, can you show a minimal example of what
you're doing that no longer works? Maybe we can suggest how to do it
properly.

>From the header:
//put all the operator<< in the global namespace so they won't be
hidden by other custom operator<< in local namespaces

That's not how to do operator overloading, so no wonder it doesn't
work now. Lookup for operators uses Argument Dependent Lookup, which
depends on the correct use of namespaces so that the appropriate
overloads are found in associated namespaces of the argument types.

template <typename F, typename S>
inline std::ostream& operator<<(std::ostream& os, const std::pair<F,S>& pr)

You should not add overloads like this for types you don't control. If
you're going to add this to the global namespace, where is typically
not going to be an associated namespace of its arguments, so ADL won't
work, then you need to make sure that the overload has been declared
prior to its use. That's really not unreasonable. Either use
namespaces properly so things can be found by ADL, or declare them
before use.

It's not reasonable to expect lookup to magically find later
declarations just because you used templates and you think that means
"find later declarations but only using infix operator syntax".

Reply via email to