Zeuthen: Writing a C library, part 1
Posted Jul 7, 2011 12:08 UTC (Thu) by
jwakely (subscriber, #60262)
In reply to:
Zeuthen: Writing a C library, part 1 by gowen
Parent article:
Zeuthen: Writing a C library, part 1
> In general, you can't return both results *and* error codes.
std::future<double> squerrt(double x)
{
std::promise<double> p;
if (x < 0)
p.set_exception(copy_exception(std::domain_error("negative")));
else
p.set_value(sqrt(x));
return p.get_future();
}
int main()
{
double i = squerrt(-1).get(); // boom
}
(
Log in to post comments)