Talk:cpp/thread/future/get
vc2012\\vc11\\crt\\future.cpp
there is an error with the
static const char *const _Future_messages[] =
{ // messages for future errors
"broken promise",
"future already retrieved",
"promise already satisfied",
"no state"
};
this code generated an invalid acceso to "_Future_messages" because
_Mycode.value() return 4.
const char *__CLR_OR_THIS_CALL what() const _THROW0() { // get message string return (_Get_future_error_what(_Mycode.value())); }
// code example
std::future<int> empty;
try {
int n = empty.get();
} catch (const std::future_error& e) {
const error_code eCode = e.code();
char *sValue = (char*)e.what();
std::cout << "Caught a future_error with code " << eCode.message()
<< " - what" << sValue << endl;
}
- works for me, and for the online compilers (even http://ideone.com/bkXoAM ). Perhaps you need to direct this query to Microsoft Connect? --Cubbi (talk) 03:37, 16 October 2013 (PDT)
The statement 'Any shared state is released' appears to be wrong. The standards says that shared state is released in std::future's destructor (or on reassignment).
In particular, the reference specialisation is returning a reference to the value in the shared state.
- The standard says that future::get "releases any shared state", in futures.unique_future/15.2. --Cubbi (talk) 07:30, 31 March 2017 (PDT)