While looking up info on Regularity, I came across this article that has an interesting take on default constructibility:
Stepanov-Regularity and Partially-Formed Objects vs. C++ Value TypesThe article shows an example of two rather different value type classes that both support default initialization. One is a
Rect with simple
int fields, the other is a
Pen class implemented with the
pimpl idiom which contains a private pointer.
The article defines an object as being in a partially-formed state if it can be assigned to or destroyed. Other behaviours may be undefined. An implication of that is that some fields may be uninitialized (Ex: a struct's coordinates), but not ones that need to be in a valid state during assignment or destruction (Ex: a pointer to a resource which is freed by the destructor, or during re-assignment where the old value is destructed).
Note that in the above, a pointer field doesn't necessarily have to point to a valid object, it just needs to be safe to use during destruction, or re-assignment. An example is initializing a pointer field to
nullptr, rather than leaving the pointer uninitialized, dangling, or pointing to a default object. It is safe to pass
nullptr to
delete. This means that partially-formed objects can do minimal field initialization, and adhere to the C++ principle of not paying for things you're not using.
An interesting side note from the article, is that value type structs should have a noexcept constructor. This is in contrast to an RAII type object, used to manage an external resource, which will raise an exception from the constructor if the resource can't be allocated. Note that neither the
Rect, nor the
Pen class discussed in the article are RAII type objects. Rather, both objects in this article support default initialization (a constructor with no parameters). Default initialization would be unusual for RAII type objects, since their constructors usually takes parameters to identify the resource they are acquiring.