BDE 4.14.0 Production release
|
Provide an ordering for shared and weak pointers.
shared_ptr
and weak_ptr
Canonical header: bsl_memory.h
This component provides the C+11 standard binary comparison functor, bsl::owner_less
, that determines the order of two smart pointer objects by the relative order of the address of their bslma::SharedPtrRep
data. Note that this class is an empty POD type.
This section illustrates intended use of this component.
Suppose we need a map accepting shared pointers as keys. We also expect that this container will be accessible from multiple threads and some of them will store weak versions of smart pointers to break reference cycles. To avoid excessive conversions we can use a transparent comparator to enable heterogeneous lookup with bsl::weak_ptr
objects as parameters for search functions.
First, we create a container and populate it:
Now, we make sure, that shared pointers can be used to perform lookup:
Finally, we simulate the situation of accessing the container from another thread and perform lookup using weak pointers: