3 ms·
Great question! We could also use a deleter, set up when we create the object, but thats often too early to know what parameters to pass into the destructor. I
by verdagon 6y ago
Great question! We could also use a deleter, set up when we create the object, but thats often too early to know what parameters to pass into the destructor.
In some cases, you do know the destruction parameters up-front, and there I would agree that a deleter is great.
Sometimes you can't know the parameters up front, so can't easily get them into the deleter when you initialize. The call-once std::function and the future are good examples: These both take parameters which you might not know until later on. If you already know the values of a future when you're creating it, it probably wouldn't be a future.
future.~resolve(resultOfSomeAsynchronousCalculation);