Hi,
Some suggestions on how to improve this proposal and discussion:
Though it does not reference it this proposal copies the concept from C#.
See for example:
http://stackoverflow.com/questions/3601901/why-use-partial-classesI think the semantics and intent differ slightly.
Your intent seems to be to implement opaque types (or at least move in that direction).
Why wouldn't a proposal to properly support opaque types be better than this?
I believe the standard answer is that the ABI would require changes,
for example, to store the size of the object.
Does your proposal affect the ABI?
C# partial classes seem to be used to split the implementation of a class over several files.
The idea of splitting the implementation of something over several files has merit
but I believe this is mostly covered by the status quo.
In C# one key use is generating code for separate parts of the implementation.
You can of course implement the interface from one C++ header file across
multiple separate .cpp files but the interface must be shared.
One thing C++ currently lacks is extension methods. This is covered by other proposals
such as uniform call syntax:
http://mariusbancila.ro/blog/2014/10/15/extension-methods-in-cpp/ https://isocpp.org/blog/2016/02/a-bit-of-background-for-the-unified-call-proposalThere are other ways for example using templates to select free or member functions as appropriate.
Now back to your proposal.
A type used only by reference can be forward declared.
However, as you discuss, you cannot use forward declaration if you want to use the interface
but hide the implementation.
Aside from the pimpl idiom, the standard C++ way of doing this would be to have an
abstract base class defining the interface and having your client code
depend on that rather than upon a specific implementation.
i.e. polymorphic types as you mention.
I believe most modern C++ compilers are able to elide the vtable pointer
completely even virtual functions are used. If you don't declare any functions
as virtual then this problem should not exist at all.
But to do this you do need to recompile. So this is a compilation performance issue.
You say this proposal doesn't interfere with others but modules potentially offer a way of
significantly improving compile times. Would speeding up compilation with partial classes
still be worthwhile in this context? Would it be worth solving this problem
before modules or after modules or trying to integrate it with the modules TS? and why?
In one place you suggest that your proposal actually just introduces a way
of declaring forward declarations more than just the type name.
Why not a proposal for forward declaring class methods instead?
E.g.
class Foo;
int Foo::Bar(const someArg& snafu);
This would be more general purpose and not require a new "partial" keyword.
it might even be extended to cover free function extension methods if
a suitable syntax can ever be found. E.g.
class Foo;
int Bar(class Foo* this,const someArg& snafu);
Class would normally be illegal here, so it could be used to explicitly declare
an extension method. With uniform call syntax it might not be necessary at all.
Regards,
Bruce.