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
As described in #79 , using std::optional<std::reference_wrapper<T>> is great in terms of the types' descriptiveness i.e. the caller know that getting a std::optional<std::reference_wrapper<T>> means that this object might not exist and you get a reference to it.
Unfortunately, using this can be very clunky.
type names get very long e.g. std::optional<std::reference_wrapper<const CharacterClass>> my_class = ...;
the implicit conversion of std::reference_wrapper<T> to T& works in only a very few cases, thus you often need to write .value().get() because you need to unwrap the optional and the reference wrapper whereas only one calling one function would be preferable
One could implement a new type for this like e.g. OptRef<T> that simplifies the usage of these, but I wonder if obscuring the types by adding another layer of abstraction might be detrimental in the long run.
The text was updated successfully, but these errors were encountered:
I defined the aliases OptRef<T> and OptCRef<T> for std::optional<std::reference_wrapper<T>> and std::optional<std::reference_wrapper<const T>>.
While improving the experience when using these types, this doesn't solve the second issues of needing to use .value().get(). Thus, this issue remains open for now.
After using these aliases for a while, I think they are a good solution while not adding too many layers of abstractions to the code.
So I am closing this issue for now.
As described in #79 , using
std::optional<std::reference_wrapper<T>>
is great in terms of the types' descriptiveness i.e. the caller know that getting astd::optional<std::reference_wrapper<T>>
means that this object might not exist and you get a reference to it.Unfortunately, using this can be very clunky.
std::optional<std::reference_wrapper<const CharacterClass>> my_class = ...;
std::reference_wrapper<T>
toT&
works in only a very few cases, thus you often need to write.value().get()
because you need to unwrap the optional and the reference wrapper whereas only one calling one function would be preferableOne could implement a new type for this like e.g.
OptRef<T>
that simplifies the usage of these, but I wonder if obscuring the types by adding another layer of abstraction might be detrimental in the long run.The text was updated successfully, but these errors were encountered: