Hi all,
I've been thinking about the feature here and I think that re-opening the class scope is out-of-scope for this problem.
I think the main problem with reopening the class scope is that suddenly you might be able to add a new function to library code where it was not intended for the user to be able to add library code, especially not new code that can access the library's internals.
Therefore, I think the PEMs should remain local to a translation unit to avoid ODR violations and to avoid breaking encapsulation of external libraries.
I do think something akin to Rust's impl blocks would be nice, but I think that's where PEMs come in. We could define a PEM as:
// Foo.h
class Foo {
private:
int m_var;
public:
Foo();
void RecalculateVar();
};
// Foo.cpp
private impl Foo {
int CalculateNewVar() {
int newVar = // Complex calculation goes here...
return m_var + newVar;
}
}
Foo::Foo()
: m_var(0)
{
m_var = CalculateNewVar();
}
void Foo::RecalculateVar() {
// Gets called by some thread every X minutes
m_var = CalculateNewVar();
}
I think that's a nice start to PEMs. We can move complexity and symbols out of the header file yet allow functions access to private member variables and prevent any ODR violations in the process.
I would also then mandate that functions in PEMs cannot overload non-static member functions because it would greatly improve teachability rather than explaining why your best fit overload defined in a PEM does not get selected for overload resolution.
Best,
Rhidian