Re: The Synthizer Thread
@297, Would reducing the amount of times you throw exceptions be of any benefit to the library? C++ has <optional> now, so this function, for example:
std::shared_ptr<ByteStream> getStreamForProtocol(const std::string &protocol, const std::string &path, const std::string &options) {
auto parsed = parseOptions(options);
auto l = std::shared_lock{byte_stream_registry_lock};
if (byte_stream_registry.count(protocol) == 0)
throw EByteStreamUnsupportedOperation("Unregistered protocol " + protocol);
auto &f = byte_stream_registry[protocol];
auto o = f(path, parsed);
if (o == nullptr)
throw EByteStream("Protocol " + protocol + " returned nullptr. No further information available.");
return o;
}
Could be rewritten as:
std::optional<std::shared_ptr<ByteStream>> getStreamForProtocol(const std::string &protocol, const std::string &path, const std::string &options) {
auto parsed = parseOptions(options);
auto l = std::shared_lock{byte_stream_registry_lock};
if (byte_stream_registry.count(protocol) == 0)
return std::nullopt;
auto &f = byte_stream_registry[protocol];
auto o = f(path, parsed);
if (o == nullptr)
return std::nullopt;
return o;
}
The only problem is that this caries no error information with it. We could trivially improvise something like a Result<> return type like Rust has to do that though. Thoughts on this kind of architecture -- would it actually have any benefitsor would it complicate the API?
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector