You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// If there is no entry to the key, we just return an empty default
// TODO: make this case detectable from the outside
if (it == map.end()) {
staticconstauto empty = T{};
return empty;
}
This currently makes it hard to impossible to check whether a value for a given key has been explicitly set to an empty / default value, or whether no value was set for a given key. Arguably for vectors and strings an empty value could indicate an unset value, but for int, float, double the "special value" of 0 might actually be a valid value for some parameters and it should be possible to distinguish that from an unset value.
The most straight forward solution in this case would be to make the return value a std::optional. The main drawback is that std::optional does not allow us to return a const & any longer so we will potentially introduce some more copies. Since set (and setValue) currently allow to reset values, this is also a way to invalidate these const &, so I think returning a copy instead of a const ref would by somewhat desirable from a thread safety point of view.
@wdconinc@nathanwbrei not sure how prevalent the use of these parameters are for the EIC. They are also used for Frame::putParameter and Frame::getParameter, so a change in behavior for the GenericParameters might also be visible when using Frames.
The text was updated successfully, but these errors were encountered:
I just ran a few searches, and it doesn't seem like we use GenericParameters anywhere. The linked PR should be good to merge from our point of view. Thanks for checking.
Currently the
GenericParameters
return an empty / default constructed value in case a key is not found:podio/include/podio/GenericParameters.h
Lines 216 to 222 in b94cc63
This currently makes it hard to impossible to check whether a value for a given key has been explicitly set to an empty / default value, or whether no value was set for a given key. Arguably for vectors and strings an empty value could indicate an unset value, but for
int
,float
,double
the "special value" of0
might actually be a valid value for some parameters and it should be possible to distinguish that from an unset value.The most straight forward solution in this case would be to make the return value a
std::optional
. The main drawback is thatstd::optional
does not allow us to return aconst &
any longer so we will potentially introduce some more copies. Sinceset
(andsetValue
) currently allow to reset values, this is also a way to invalidate theseconst &
, so I think returning a copy instead of a const ref would by somewhat desirable from a thread safety point of view.@wdconinc @nathanwbrei not sure how prevalent the use of these parameters are for the EIC. They are also used for
Frame::putParameter
andFrame::getParameter
, so a change in behavior for theGenericParameters
might also be visible when using Frames.The text was updated successfully, but these errors were encountered: