BDE 4.14.0 Production release
|
Provide hashAppend
for std::optional
.
This component provides a free function template, bslh::hashAppend
, overloaded for the std::optional
class template. Including this function allows for std::optional
types (and types that contain them) to be used as keys in BDE hashed containers.
Note that use of this component requires that the language standard be 2017 or later, as that is when std::optional
first appears.
This section illustrates intended usage of this component.
Suppose we want to maintain a boolean condition as either true, false, or unspecified, and have it fit within the BDE hash framework. We can use std::optional<bool>
for this, and demonstrate that such a value can be correctly hashed.
First, we set up three such optional values to represent the three possible states we wish to represent.
Then, we create a hashing object.
Next, we hash each of our values.
Then we hash the underlying values.
Finally, we verify that the std::optional
hasher produces the same results as the underlying hashers. For the disengaged hash, we will just check that the value differs from either engaged value.