This question is all about just finding any solution that doesn't carry too much boilerplate code - while this could generate some opinion based solutions - Im really just looking for any solution (wihtout too much boilerplate code)
The following is causing me a bit of headache - while I can easily fix this, I would like to avoid too much boilerplate code. The following is not legal c++ but shows intent.
char* newBuffer(const char* filename)
{
auto fm = try { //<--try is not legal here
boost::interprocess::file_mapping(filename, boost::interprocess::read_only);
}
catch (boost::interprocess::interprocess__exception& e) {
//report error
return nullptr;//<--this actually makes matters worse since now we cannot just simply wrap in a simpel lambda or function..
}
//rest of function ...
}
I could just move the try at the beginning of the function but that would mean to just try the entire function (bad practice) instead of just try'ing file_mapping constructor.
How would you solve this conundrum and avoid try-block around the entire function ? less boilerplate code is preferred better.
Any answer should also address the issue with returning of nullptr in case of failure.