Use same style for optional and avoid double check

I did not know that `std::optional::value()` did checked access. And I
still prefer a more explicit .has_value() over boolean conversion, but
this seems to be the accepted way to do this.
This commit is contained in:
Robbert van der Helm
2020-06-05 22:27:04 +02:00
parent ff298f3f46
commit 33777d2876
7 changed files with 35 additions and 36 deletions
+4 -5
View File
@@ -245,10 +245,9 @@ void Vst2Bridge::handle_parameters() {
// presence of the `value` field tells us which one we're dealing
// with.
auto request = read_object<Parameter>(host_vst_parameters);
if (request.value.has_value()) {
if (request.value) {
// `setParameter`
plugin->setParameter(plugin, request.index,
request.value.value());
plugin->setParameter(plugin, request.index, *request.value);
ParameterResult response{std::nullopt};
write_object(host_vst_parameters, response);
@@ -477,8 +476,8 @@ class HostCallbackDataConverter : DefaultDataConverter {
// Return a pointer to the `VstTimeInfo` object written in
// the function above
VstTimeInfo* time_info_pointer = nullptr;
if (time_info.has_value()) {
time_info_pointer = &time_info.value();
if (time_info) {
time_info_pointer = &*time_info;
}
return reinterpret_cast<intptr_t>(time_info_pointer);