I am posting this as a new thread because I do not want to undermine the ongoing discussion of what I will term the "namespace class" proposal.
Assuming that proposal is successful I see opportunity to address another C++ rough edge. As in the former proposal this adds no actual new functionality to C++ but it would make it more pleasant to use. (In some respects this is a less ambitious, less complex attack on the usage sweet spot that the various Uniform Call Syntax proposals seem to address.)
A tension I have encountered repeatedly (and resolve differently on different occasions) is the requirement to make a function a class member in-order to confer upon it method invocation syntax.
When I implement an abstraction I start with a base set of methods that can only be implemented as true class members (i.e. they require access to the class' internals). Often after that I have an additional set of services, wrappers, what-have-you that I want to present as part of how a client should think about the class even though they all can be implemented entirely in terms my earlier base methods. Ideally I want my users to use method invocation syntax to call operations in this second set. And indeed I can achieve that by including those operations in the class definition. Often though that seems a high price to pay merely to achieve syntactic uniformity.
Already today a classic namespace need not be defined all at once. Disparate sites can open the same namespace in order to add entries. I would like to suggest that "namespace class" have a similar behavior:
- If a "namespace class" function definition has a signature that matches a method within the corresponding class still missing a definition then it "completes" that method.
- Otherwise such a"namespace class" function becomes a member of the namespace class (but not the class). It must be called using method invocation syntax. Its implementation can use unqualified naming to refer to public members of the clas. OTOH it is granted no special access (it is restricted to exploiting the public interface).
- No virtual nor static functions.
- No data (neither static nor instance).
A const method qualifier should be allowed with the obvious semantics.
/john