struct Process {
template<typename R>
explicit Process(R (*pfunc)(), bool ret_int=false) {
int pid= fork();
if(pid==-1) {
throw "Error";
}
if(pid==0) {
if(ret_int) {
_exit( pfunc() ); // error: invalid use of void expression
} else {
pfunc(); // ret value ignored
_exit(0);
}
}
};
}
The issue is _exit(int) require int type.
void f();
Process proc(f); // error: R is void
So, how to make the Process ctor work for different R type?
if constexpr(!std::is_same_v<R,void>)
_exit( pfunc() );
} else {
pfunc();
_exit(0);
}
Thanks. I need C++11 way.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 547 |
Nodes: | 16 (2 / 14) |
Uptime: | 60:35:51 |
Calls: | 10,398 |
Calls today: | 6 |
Files: | 14,067 |
Messages: | 6,417,476 |
Posted today: | 1 |