core: Add hashing functor for creating hash of a Ptr
This commit is contained in:
committed by
Tommaso Pecorella
parent
8cfe1b5e2e
commit
7c48447ffa
@@ -60,6 +60,7 @@ us a note on ns-developers mailing list.</p>
|
||||
<li>In class <b>Ipv4InterfaceAddress</b>, a new function IsInSameSubnet () is added to check if both the IPv4 addresses are in the same subnet. Also, it is consistent with <b>Ipv6InterfaceAddress::IsInSameSubnet ()</b>.</li>
|
||||
<li>In class <b>ConfigStore</b>, a new Attribue <b>SaveDeprecated</b> allows to not save DEPRECATED Attributes. The default value is <b>false</b> (save DEPRECATED Attributes).</li>
|
||||
<li>In class <b>TracedCallback</b>, a new function <b>IsEmpty</b> allows to know if the TracedCallback will call any callback.</li>
|
||||
<li>A new specialization of std::hash for Ptr allows to use seamlessly Ptrs as keys in unordered_map and unordered_set.</li>
|
||||
</ul>
|
||||
<h2>Changes to existing API:</h2>
|
||||
<ul>
|
||||
|
||||
@@ -36,6 +36,7 @@ New user-visible features
|
||||
- (config-store) OBSOLETE Attributes are not anymore saved.
|
||||
- (config-store) New ConfigStore::SaveDeprecated Attribute (default false) to avoid to save DEPRECATED attributes.
|
||||
- (core) Add TracedCallback::IsEmpty to know if a TracedCallback has any callback associated.
|
||||
- (core) Add std::hash<ns3::Ptr<T>> to allow seamless use of Ptr as key in unordered_maps.
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
@@ -695,4 +695,39 @@ Ptr<T>::operator Tester * () const
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
/****************************************************
|
||||
* Global Functions (outside namespace ns3)
|
||||
***************************************************/
|
||||
|
||||
/**
|
||||
* \ingroup ptr
|
||||
* Hashing functor taking a `Ptr` and returning a @c std::size_t.
|
||||
* For use with `unordered_map` and `unordered_set`.
|
||||
*
|
||||
* \note When a `Ptr` is used in a container the lifetime of the underlying
|
||||
* object is at least as long as the container. In other words,
|
||||
* you need to remove the object from the container when you are done with
|
||||
* it, otherwise the object will persist until the container itself is
|
||||
* deleted.
|
||||
*
|
||||
* \tparam T \deduced The type held by the `Ptr`
|
||||
*/
|
||||
template<class T>
|
||||
struct
|
||||
std::hash<ns3::Ptr<T>>
|
||||
{
|
||||
/**
|
||||
* The functor.
|
||||
* \param p The `Ptr` value to hash.
|
||||
* \return the hash
|
||||
*/
|
||||
std::size_t
|
||||
operator () (ns3::Ptr<T> p) const
|
||||
{
|
||||
return std::hash<const T *> () (ns3::PeekPointer (p));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* PTR_H */
|
||||
|
||||
Reference in New Issue
Block a user