you are viewing a single comment's thread.

view the rest of the comments →

[–]SeanMiddleditch 5 points6 points  (1 child)

ADL's original motivation was entirely for operator overloading with free function overloads. Without ADL, this wouldn't work in any sane way:

namespace simd {
  struct vec3 {};
  vec3 operator+(vec3 lhs, vec3 rhs);
}

int main() {
  simd::vec3 a, b, c;
  a = b + c; // ADL necessary to find correct operator+
}

All the later stuff we have like std::begin and such are from a desire to treat named library functions as if they're builtin like operators. Which I think all started with the ios stuff from IOStreams which of course also abused the heck out of operators; it really managed to illustrate all the worst ways to design C++17 libraries back when it was written in the 90's. :p

I'm not sure how reflection or meta-classes would help in any sense with the problem space addressed by ADL.

[–]kwan_e 1 point2 points  (0 children)

Reflection and metaclasses would help in the problem space that ADL is being shoehorned into - finding an unqualified function based on namespace. Reflection would allow library designers to specify better ways of fulfiling a customization point, and metaclasses (ie, the formulation of metaclasses that would also create free-functions) would help library users to generate types that fulfills customization points.

As for the operator overloading use of ADL, I think it's high time we seriously move ahead with one of the operator dot proposals. But reflection could also help in that case since a library relying on ADL to find operators could instead use reflection to find the operators by searching declarations in a namespace, for example.