Quick Links:

bal | bbl | bdl | bsl

Classes | Typedefs | Functions

Component bslstl_ownerless
[Package bslstl]

Provide an ordering for shared and weak pointers. More...

Classes

struct  bsl::owner_less< shared_ptr< ELEMENT_TYPE > >
struct  bsl::owner_less< weak_ptr< ELEMENT_TYPE > >
struct  bsl::owner_less< void >

Typedefs

typedef shared_ptr< ELEMENT_TYPE > bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::first_argument_type
typedef shared_ptr< ELEMENT_TYPE > bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::second_argument_type
typedef weak_ptr< ELEMENT_TYPE > bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::first_argument_type
typedef weak_ptr< ELEMENT_TYPE > bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::second_argument_type

Functions

 bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::owner_less ()
 bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::owner_less (const owner_less &original)
 bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::~owner_less ()
owner_less & bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::operator= (const owner_less &rhs)
bool bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::operator() (const shared_ptr< ELEMENT_TYPE > &a, const shared_ptr< ELEMENT_TYPE > &b) const BSLS_KEYWORD_NOEXCEPT
bool bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::operator() (const shared_ptr< ELEMENT_TYPE > &a, const weak_ptr< ELEMENT_TYPE > &b) const BSLS_KEYWORD_NOEXCEPT
bool bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::operator() (const weak_ptr< ELEMENT_TYPE > &a, const shared_ptr< ELEMENT_TYPE > &b) const BSLS_KEYWORD_NOEXCEPT
 bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::owner_less ()
 bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::owner_less (const owner_less &original)
 bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::~owner_less ()
owner_less & bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::operator= (const owner_less &rhs)
bool bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::operator() (const weak_ptr< ELEMENT_TYPE > &a, const weak_ptr< ELEMENT_TYPE > &b) const BSLS_KEYWORD_NOEXCEPT
bool bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::operator() (const shared_ptr< ELEMENT_TYPE > &a, const weak_ptr< ELEMENT_TYPE > &b) const BSLS_KEYWORD_NOEXCEPT
bool bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::operator() (const weak_ptr< ELEMENT_TYPE > &a, const shared_ptr< ELEMENT_TYPE > &b) const BSLS_KEYWORD_NOEXCEPT
 bsl::owner_less< void >::owner_less ()
 bsl::owner_less< void >::owner_less (const owner_less &original)
 bsl::owner_less< void >::~owner_less ()
owner_less & bsl::owner_less< void >::operator= (const owner_less &rhs)
template<class ELEMENT_TYPE_A , class ELEMENT_TYPE_B >
bool bsl::owner_less< void >::operator() (const shared_ptr< ELEMENT_TYPE_A > &a, const shared_ptr< ELEMENT_TYPE_B > &b) const BSLS_KEYWORD_NOEXCEPT
template<class ELEMENT_TYPE_A , class ELEMENT_TYPE_B >
bool bsl::owner_less< void >::operator() (const shared_ptr< ELEMENT_TYPE_A > &a, const weak_ptr< ELEMENT_TYPE_B > &b) const BSLS_KEYWORD_NOEXCEPT
template<class ELEMENT_TYPE_A , class ELEMENT_TYPE_B >
bool bsl::owner_less< void >::operator() (const weak_ptr< ELEMENT_TYPE_A > &a, const shared_ptr< ELEMENT_TYPE_B > &b) const BSLS_KEYWORD_NOEXCEPT
template<class ELEMENT_TYPE_A , class ELEMENT_TYPE_B >
bool bsl::owner_less< void >::operator() (const weak_ptr< ELEMENT_TYPE_A > &a, const weak_ptr< ELEMENT_TYPE_B > &b) const BSLS_KEYWORD_NOEXCEPT

Detailed Description

Outline
Purpose:
Provide an ordering for shared and weak pointers.
Classes:
bsl::owner_less ordering comparator for shared_ptr and weak_ptr
Canonical Header:
bsl_memory.h
See also:
Component bslstl_sharedptr
Description:
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.
Usage:
This section illustrates intended use of this component.
Example 1: Basic Use of owner_less<void>:
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:
      typedef bsl::map<bsl::shared_ptr<int>, int, bsl::owner_less<void> >
                                                                         Map;
      Map                  container;

      bsl::shared_ptr<int> sharedPtr1 = bsl::make_shared<int>(1);
      bsl::shared_ptr<int> sharedPtr2 = bsl::make_shared<int>(2);
      bsl::weak_ptr<int>   weakPtr1(sharedPtr1);

      container[sharedPtr1] = 1;
      container[sharedPtr2] = 2;
Now, we make sure, that shared pointers can be used to perform lookup:
      Map::const_iterator iter = container.find(sharedPtr1);
      assert(container.end() != iter        );
      assert(1               == iter->second);

      iter = container.find(sharedPtr2);
      assert(container.end() != iter);
      assert(2               == iter->second);
Finally, we simulate the situation of accessing the container from another thread and perform lookup using weak pointers:
      iter = container.find(weakPtr1);
      assert(container.end() != iter        );
      assert(1               == iter->second);

      bsl::weak_ptr<int> weakPtr3(bsl::make_shared<int>(3));
      iter = container.find(weakPtr3);
      assert(container.end() == iter);

Typedef Documentation

template<class ELEMENT_TYPE >
typedef shared_ptr<ELEMENT_TYPE> bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::first_argument_type [inherited]
template<class ELEMENT_TYPE >
typedef shared_ptr<ELEMENT_TYPE> bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::second_argument_type [inherited]
template<class ELEMENT_TYPE >
typedef weak_ptr<ELEMENT_TYPE> bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::first_argument_type [inherited]
template<class ELEMENT_TYPE >
typedef weak_ptr<ELEMENT_TYPE> bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::second_argument_type [inherited]

Function Documentation

template<class ELEMENT_TYPE >
bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::owner_less (  )  [inherited]

Create an owner_less object.

template<class ELEMENT_TYPE >
bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::owner_less ( const owner_less< shared_ptr< ELEMENT_TYPE > > &  original  )  [inherited]

Create an owner_less object. Note that as owner_less is an empty (stateless) type, this operation has no observable effect.

template<class ELEMENT_TYPE >
bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::~owner_less (  )  [inherited]

Destroy this object.

template<class ELEMENT_TYPE >
owner_less& bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::operator= ( const owner_less< shared_ptr< ELEMENT_TYPE > > &  rhs  )  [inherited]

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. Note that as owner_less is an empty (stateless) type, this operation has no observable effect.

template<class ELEMENT_TYPE >
bool bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::operator() ( const shared_ptr< ELEMENT_TYPE > &  a,
const shared_ptr< ELEMENT_TYPE > &  b 
) const [inherited]
template<class ELEMENT_TYPE >
bool bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::operator() ( const shared_ptr< ELEMENT_TYPE > &  a,
const weak_ptr< ELEMENT_TYPE > &  b 
) const [inherited]
template<class ELEMENT_TYPE >
bool bsl::owner_less< shared_ptr< ELEMENT_TYPE > >::operator() ( const weak_ptr< ELEMENT_TYPE > &  a,
const shared_ptr< ELEMENT_TYPE > &  b 
) const [inherited]

Return true if the address of the BloombergLP::bslma::SharedPtrRep object used by the specified a is ordered before the address of the BloombergLP::bslma::SharedPtrRep object used by the specified b under the total ordering supplied by std::less<BloombergLP::bslma::SharedPtrRep *>, and false otherwise.

template<class ELEMENT_TYPE >
bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::owner_less (  )  [inherited]

Create an owner_less object.

template<class ELEMENT_TYPE >
bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::owner_less ( const owner_less< weak_ptr< ELEMENT_TYPE > > &  original  )  [inherited]

Create an owner_less object. Note that as owner_less is an empty (stateless) type, this operation has no observable effect.

template<class ELEMENT_TYPE >
bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::~owner_less (  )  [inherited]

Destroy this object.

template<class ELEMENT_TYPE >
owner_less& bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::operator= ( const owner_less< weak_ptr< ELEMENT_TYPE > > &  rhs  )  [inherited]

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. Note that as owner_less is an empty (stateless) type, this operation has no observable effect.

template<class ELEMENT_TYPE >
bool bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::operator() ( const weak_ptr< ELEMENT_TYPE > &  a,
const weak_ptr< ELEMENT_TYPE > &  b 
) const [inherited]
template<class ELEMENT_TYPE >
bool bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::operator() ( const shared_ptr< ELEMENT_TYPE > &  a,
const weak_ptr< ELEMENT_TYPE > &  b 
) const [inherited]
template<class ELEMENT_TYPE >
bool bsl::owner_less< weak_ptr< ELEMENT_TYPE > >::operator() ( const weak_ptr< ELEMENT_TYPE > &  a,
const shared_ptr< ELEMENT_TYPE > &  b 
) const [inherited]

Return true if the address of the BloombergLP::bslma::SharedPtrRep object used by the specified a is ordered before the address of the BloombergLP::bslma::SharedPtrRep object used by the specified b under the total ordering supplied by std::less<BloombergLP::bslma::SharedPtrRep *>, and false otherwise.

bsl::owner_less< void >::owner_less (  )  [inherited]

Create an owner_less object.

bsl::owner_less< void >::owner_less ( const owner_less< void > &  original  )  [inherited]

Create an owner_less object. Note that as owner_less is an empty (stateless) type, this operation has no observable effect.

bsl::owner_less< void >::~owner_less (  )  [inherited]

Destroy this object.

owner_less& bsl::owner_less< void >::operator= ( const owner_less< void > &  rhs  )  [inherited]

Assign to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. Note that as owner_less is an empty (stateless) type, this operation has no observable effect.

template<class ELEMENT_TYPE_A , class ELEMENT_TYPE_B >
bool bsl::owner_less< void >::operator() ( const shared_ptr< ELEMENT_TYPE_A > &  a,
const shared_ptr< ELEMENT_TYPE_B > &  b 
) const [inherited]
template<class ELEMENT_TYPE_A , class ELEMENT_TYPE_B >
bool bsl::owner_less< void >::operator() ( const shared_ptr< ELEMENT_TYPE_A > &  a,
const weak_ptr< ELEMENT_TYPE_B > &  b 
) const [inherited]
template<class ELEMENT_TYPE_A , class ELEMENT_TYPE_B >
bool bsl::owner_less< void >::operator() ( const weak_ptr< ELEMENT_TYPE_A > &  a,
const shared_ptr< ELEMENT_TYPE_B > &  b 
) const [inherited]
template<class ELEMENT_TYPE_A , class ELEMENT_TYPE_B >
bool bsl::owner_less< void >::operator() ( const weak_ptr< ELEMENT_TYPE_A > &  a,
const weak_ptr< ELEMENT_TYPE_B > &  b 
) const [inherited]

Return true if the address of the BloombergLP::bslma::SharedPtrRep object used by the specified a is ordered before the address of the BloombergLP::bslma::SharedPtrRep object used by the specified b under the total ordering supplied by std::less<BloombergLP::bslma::SharedPtrRep *>, and false otherwise.