Quick Links: |
Provide hashAppend
for std::optional
.
More...
Namespaces | |
namespace | bslh |
hashAppend
for std::optional
. 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. std::optional
first appears. std::optional<bool>
for this, and demonstrate that such a value can be correctly hashed. std::optional<bool> optionalTrue = true; std::optional<bool> optionalFalse = false; std::optional<bool> optionalUnset;
bslh::Hash<> hasher;
size_t optionalTrueHash = hasher(optionalTrue); size_t optionalFalseHash = hasher(optionalFalse); size_t optionalUnsetHash = hasher(optionalUnset);
size_t expectedTrueHash = hasher(true); size_t expectedFalseHash = hasher(false);
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. assert(expectedTrueHash == optionalTrueHash); assert(expectedFalseHash == optionalFalseHash); assert(expectedTrueHash != optionalUnsetHash); assert(expectedFalseHash != optionalUnsetHash);