A sixth alternative UFCS approach #955
Replies: 1 comment 1 reply
-
Thanks! I've thought of unifying all functions, but in this case going that far wouldn't meet the benefit:cost bar. I would ask: What problem is that additional unification solving? (i.e., what important use cases aren't enabled by the UFCS as currently implemented, or what % of existing bugs/guidance literature would be eliminated by this change) Note that virtual functions not only are members, but they also have access (privates) and layout (vtable) implications. Adding another virtual function requires adding a vtable slot and recompiling the world (or at least as much of the world as can transitively be sensitive to the layout of that class). As long as virtual functions are limited to declaration inside a class, they are under the control of the class author. Just some thoughts. |
Beta Was this translation helpful? Give feedback.
-
I was just reading the UFCS design notes.
I noticed that one approach to UFCS, which is the one I (think I) like best, seems to be missing. It's another way to "slice the Gordian knot": Instead of choosing one kind of function and disallowing the other, Make member functions and nonmember functions be one and the same thing. That is, if you have class
ns::A
and you define (a non-virtual)ns::f(A&, B)
, it's as though you've definedns::A::f(B) &
- and vice-versa, if you've defined the former, you've defined the latter.(This also opens up the possibility of virtual non-member functions and maybe also multiple dispatch, which would completely remove the distinction between member functions and independent ones.)
Has this been discussed in any of the times UFCS has been brought up? Or - was this considered too far from what C++ is?
Beta Was this translation helpful? Give feedback.
All reactions