The most severe problem with argument-dependent lookup is that most of C++ programmers even experienced ones have no idea what it is.On the other hand it allows operators to work as expected by most programmers and also allows to connect free functions to class.So, I guess the consensus is that ADL has to be fixed by no-one knows how to fix it right.A recent proposal by Dave Abrahams N3490 is written from a perspective of a library author. He argues that is sufficient to provide facility to explicitly disable ADL byusing = delete;And then explicitly enable ADL for some of functions expected to be found via ADL byusing swap;The solution might be acceptable for library code but I do not think that it would work for user code.First of all, in order to disable ADL users have to be aware of ADL. Second adding 'using = delete;' will break even hello world program#include <iostream>
using = delete;
int main()
{
std::cout << "Hello, world!" << std::endl; // operator << is not found
return 0;
}Do we expect users to write 'using' for every operator?
Third is that there's useful idea that non-member functions should be preferred over member functions in class design.Having ADL for free functions that form a part of public interface of a class is actually a good thing.My idea is that it's not the user of a function has to decide whether it should be found by ADL, it's the author of a class.For example, we could declare such functions with operator keyword. It is expected for operators to be found by ADL anyway.template<typename T>void operator swap(T& first, T& second);Going further, we may allow to call operator functions as member functions. Then, there would be no need of notion of pure ADL, used for range-based for loop.I know that there a lot of subtle details that should be figured out. And that's limiting ADL only to set of specially declared functions is a big change and should be done in stages.But if we are going to fix ADL, then my understanding is that it should be fixed in this direction.
"First, we provide a way to turn off ADL for non-operator names"
So, "using = delete;" isn't intended to affect operator names. The above code would still work as before.
I really like the idea of named operators. It seems it would break a lot of
code though.
Regards,
--
Felipe Magno de Almeida
A name is a use of identifier, operator-function-id, literal-operator-id, conversion-function-id, template-id, etc. Operators appeared out of unqualified-id are not took into account. So there is simply no need to worry about this 'hello world'.
Четвер, 15 листопада 2012 р. 20:58:04 UTC+2 користувач FrankHB1989 написав:A name is a use of identifier, operator-function-id, literal-operator-id, conversion-function-id, template-id, etc. Operators appeared out of unqualified-id are not took into account. So there is simply no need to worry about this 'hello world'.Sorry, I did not quite get your comment.
The most severe problem with argument-dependent lookup is that most of C++ programmers even experienced ones have no idea what it is.On the other hand it allows operators to work as expected by most programmers and also allows to connect free functions to class.So, I guess the consensus is that ADL has to be fixed by no-one knows how to fix it right.
coding style
that bans all unqualified calls except for operators.
Пʼятниця, 16 листопада 2012 р. 18:20:11 UTC+2 користувач Ville Voutilainen написав:
--
Method is an OOP term.C++ as multi-paradigm language supports object-oriented style, so terms of OOP have mapping to terms used in C++.You may dislike it, but I hope that everybody understands what it means.
--
Jean-Marc Bourguet
--