Closed JeffGarland closed 4 years ago
We could consider having a throwing constructor, and a non-throwing free factory function:
class process {
friend make_process(..., std::error_code& errc);
public:
process(...);
};
// Can't be noexcept with the Lakos rule :(
process make_process(..., std::error_code& errc);
Yes -- that fixes the invariant part. Still I find the consistency with thread to be compelling -- I don't want to have to 'remember' that that process api is distinct.
And I think there's nothing preventing user writing the analog to make_process:
pair<process, error_code> safe_process( process& p, ... )
{
error_code ec;
try {
p = process( ... );
}
catch (system_error& se) {
ec = se.code();
}
return {p, ec};
}
Note this I believe is enabled by the ability to default construct -- and actually that constructor is will be noexcept:
// An empty process is similar to a default constructed thread. It holds an empty
// handle and is a place holder for a process that is to be launched later.
process() = default;
I've added a section to discuss the tradeoffs
So as we've probably already discussed, I believe the crux of this comes down to not using the process constructor to spawn. So you'd always have to construct and then call a function like 'spawn' which could report an error with a return. Something along the lines of
Things I can see against this: