I wounder why the classes std::future
and std::promise
are not marked with the final
specifier. The destructor is not virtual so why was final
not added? What was (is) the rationale?
Have a look at this contrived (admittedly nonsensical) example with std::vector
:
template <class T>
struct Example : private std::vector<T> {
void doStuff(const T& t) { this->push_back(t); }
T retrieveStuff() { return this->operator[](0); }
};
Example<int> e;
e.doStuff(42);
std::cout << e.retrieveStuff() << "\n";
This works, you can't get into UB due to std::vector::~vector
not being virtual
because you can't delete an object through a base class pointer (public
inheritance is needed there).
The inheritance here is just an implementation detail. Not recommended practice, but people probably did and do this. Once the decision is made to not break existing code by making std::vector
or other container types final
, it makes sense to stick to that with different vocabulary types like std::promise
or std::future
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With