3 ms·
Completely agree. I was about to write something along these lines but you did a great job. :-) In a decade using C++, I haven't encountered these problems. I
by afc 6y ago
Completely agree. I was about to write something along these lines but you did a great job. :-)
In a decade using C++, I haven't encountered these problems. I never use exceptions and I do exactly what you suggested in #2: if construction can fail, have a factory method and a private constructor (I use a simple ValueOrError<T> type, rather than optional<T>, to be able to communicate information about the error, though: https://github.com/alefore/edge/blob/876c4328610262b11fda553b87de0b7faa3bf263/src/value_or_error.h#L30 https://github.com/alefore/edge/blob/876c4328610262b11fda553...).
Cheers!
- thisgoodlife 6y agoI like the way how google does it with StatusOr and some status macros https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/stubs/statusor.h https://github.com/protocolbuffers/protobuf/blob/master/src/... https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/stubs/status_macros.h https://github.com/protocolbuffers/protobuf/blob/master/src/...