bool OpenFile( const std::string& path, File& f, std::string& err )
or similar, you get the point. At the moment I'm using a class like llvm's ErroOr<T> [1] and I'm loving it so far. The aformentioned function would be written as ErrorOr<File> OpenFile( const std::string& path )
and contain an std::error_code if opening failed, or else a File instance.[1] http://www.llvm.org/docs/doxygen/html/classllvm_1_1ErrorOr.h...
const auto result = alg::find( range, pred );
if( result )
doStuff( *result ); //*result is reference to found element
instead of typcial const auto end = range.cend();
const auto result = std::find( range.cbegin(), end, pred );
if( result != end )
doStuff( *result );
Not that much of a gain, but once used to it I could never go back. And I realize now this could actually just be rewritten using your maybe class or std::optional.IMO constructors should be setting sane defaults and nothing more. If you need to do work that could fail put that into an "init()" function with a return type that can signal an error.
I worked for quite a while on platforms that didn't have exceptions and this was the standard pattern for keeping RAII without needing them. If you wrap the return value correctly(like with Result<T,E>) you can also guarantee that your clients need to deal with the error case(or fail to handle it with unwrap()) as opposed to getting caught by an exception that wasn't declared or documented.
That allows you to construct the object in an invalid state. The whole point of RAII is to avoid that. The acronym literally means not having a separate init() function.
FWIW some quick googling shows that having a constructor acquire a resource is not a requirement(https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Resource_A...). The important part about RAII is that the automatic releasing of resources when out of scope(through a no-throw destructor).
This is still RAII, you're just not using a constructor to acquire. Rust doesn't have constructors and is still RAII.
In any case, .unwrap() is perfectly fine in applications, it's only in libraries that they're discouraged.
To me success includes being able to find (not frequently replace - I like working with the same people for many years - but find new ones in order to grow) developers that can contribute to the code base, and some of the best ones I know can't be bothered to learn much of C++. Go figure. Maybe you and I legitimately disagree because we work on different things, and maybe one of us is wrong.
Your definition of 'successfully' is vastly different from the Megacorp definition of 'successfully'. I interview C++ programmers _all the time_, and let me tell you: practically the only reason those restricted subsets of C++ exist is to allow bad programmers to work at Megacorp.
There are a lot of really unqualified C++ programmers in the world, and by far the biggest problem faced by Megacorp is employee churn, not code quality and not product deadlines.
The use of 'C++ subsets' solves the employee churn problem at the cost of code quality.