Bond
 
Loading...
Searching...
No Matches
bond::ext::capped_allocator< Alloc, Counter > Class Template Reference
Inheritance diagram for bond::ext::capped_allocator< Alloc, Counter >:
bond::detail::allocator_holder< Alloc, Enable >

Public Member Functions

 capped_allocator (detail::value_or_reference< Counter > count, const Alloc &alloc={}, bool subtract_on_deallocate=true)
 Constructs capped allocator adapter. More...
 
template<typename C = Counter, typename boost::enable_if< std::uses_allocator< C, Alloc > >::type * = nullptr>
 capped_allocator (typename C::value_type max_value, const Alloc &alloc={}, bool subtract_on_deallocate=true)
 Constructs capped allocator adapter. More...
 
template<typename OtherAlloc , typename boost::enable_if< std::is_convertible< OtherAlloc, Alloc > >::type * = nullptr>
 capped_allocator (const capped_allocator< OtherAlloc, Counter > &other)
 Converts from a compatible allocator. More...
 

Detailed Description

template<typename Alloc, typename Counter>
class bond::ext::capped_allocator< Alloc, Counter >

STL-compatible allocator adapter that fails allocations by throwing std::bad_alloc if the maximum number of bytes to be allocated is exceeded

Template Parameters
Allocunderlying allocator type.
Counterunderlying counter type.
Remarks
The provided counter is used to measure allocations in bytes.

Constructor & Destructor Documentation

◆ capped_allocator() [1/3]

template<typename Alloc , typename Counter >
bond::ext::capped_allocator< Alloc, Counter >::capped_allocator ( detail::value_or_reference< Counter >  count,
const Alloc &  alloc = {},
bool  subtract_on_deallocate = true 
)
explicit

Constructs capped allocator adapter.

Parameters
countcounter value to use (see remarks for more details).
allocthe base allocator instance.
subtract_on_deallocateflag to indicate if counter must be adjusted for deallocation.
Remarks
When Counter is not a reference type, then count can be one of
  • an instance of Counter in which case it will be passed by-value,
  • an instance of std::ref/boost::ref of a Counter in which case only a reference will be held,
  • max value for the Counter which will be used to construct one.

When Counter is a reference type, then only a reference to an existing instance can be passed.

◆ capped_allocator() [2/3]

template<typename Alloc , typename Counter >
template<typename C = Counter, typename boost::enable_if< std::uses_allocator< C, Alloc > >::type * = nullptr>
bond::ext::capped_allocator< Alloc, Counter >::capped_allocator ( typename C::value_type  max_value,
const Alloc &  alloc = {},
bool  subtract_on_deallocate = true 
)
explicit

Constructs capped allocator adapter.

Parameters
max_valuemax counter value.
allocthe base allocator instance.
subtract_on_deallocateflag to indicate if counter must be adjusted for deallocation.
Remarks
The overload is used when Counter is allocator-aware.

◆ capped_allocator() [3/3]

template<typename Alloc , typename Counter >
template<typename OtherAlloc , typename boost::enable_if< std::is_convertible< OtherAlloc, Alloc > >::type * = nullptr>
bond::ext::capped_allocator< Alloc, Counter >::capped_allocator ( const capped_allocator< OtherAlloc, Counter > &  other)

Converts from a compatible allocator.