The sr.tFuture
is initialized with 'empty' state instead of 'pending' and I found out when I remove tFuture()
from the constructor initialization list, the state of sr.tFuture
becomes pending which is correct. But I don't quite understand the reason. Is it because the value of tFuture
on the declaration part gets overwritten when tFuture()
gets invoked and cause tFuture
to not get associated with any promise?
struct SharedResource
{
SharedResource(const SharedResource&) = delete;
SharedResource& operator=(const SharedResource&) = delete;
SharedResource() :
tPromise(), tFuture()
{}
std::promise<void> tPromise;
std::future<void> tFuture = tPromise.get_future();
};
int main()
{
SharedResource sr;
}