Sequoia
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Friends | List of all members
sequoia::testing::shared_counting_allocator< T, PropagateCopy, PropagateMove, PropagateSwap > Class Template Reference

Somewhat similar to std::allocator but logs (de)allocations via an counter which is shared upon copying. More...

#include <AllocationTestUtilities.hpp>

Classes

struct  rebind
 

Public Types

using value_type = T
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using propagate_on_container_copy_assignment = std::bool_constant< PropagateCopy >
 
using propagate_on_container_move_assignment = std::bool_constant< PropagateMove >
 
using propagate_on_container_swap = std::bool_constant< PropagateSwap >
 
using is_always_equal = std::false_type
 

Public Member Functions

 shared_counting_allocator (const shared_counting_allocator &)=default
 
shared_counting_allocatoroperator= (const shared_counting_allocator &)=default
 
T * allocate (std::size_t n)
 
void deallocate (T *p, std::size_t n)
 
int allocs () const noexcept
 
int deallocs () const noexcept
 

Friends

bool operator== (const shared_counting_allocator &, const shared_counting_allocator &) noexcept=default
 

Detailed Description

template<class T, bool PropagateCopy = true, bool PropagateMove = true, bool PropagateSwap = false>
class sequoia::testing::shared_counting_allocator< T, PropagateCopy, PropagateMove, PropagateSwap >

Somewhat similar to std::allocator but logs (de)allocations via an counter which is shared upon copying.

A fundamental ingredient of the allocation testing framework is the capactity to count the number of allocations which have occured before/after some operation and to compare the difference to a prediction. Experimentation has (tentatively) suggested that the most robust way to do this is for copies of an allocator to share a counter. The benefit of this is that the framework is sensitive to copies of the allocator being taken between the measurement points. For example, the framework can (and has!) detected a typo in an overload of operator== in which one of the arguments was accidentally taken by value, leading to unexpected allocations.

There is also a more subtle difference to std:allocator<T>. Whereas the latter allows construction from std::allocator<U> this possibility is excluded to ensure that constructors of classes taking multiple allocators do not confuse them internally.

In addition to taking the usual T as a template parameter, the class template accepts three bools which control whether or not the allocator is propapaged when the associated container is copied, moved or swapped.


The documentation for this class was generated from the following file: