*/
Allocator d_allocator;
-protected:
+ protected:
/**
* Private copy constructor used only by save(). d_list and
* d_sizeAlloc are not copied: only the base class information and
* d_size are needed in restore.
*/
- CDList(const CDList& l) :
- ContextObj(l),
- d_list(NULL),
- d_size(l.d_size),
- d_callDestructor(false),
- d_sizeAlloc(0),
- d_cleanUp(l.d_cleanUp),
- d_allocator(l.d_allocator) {
- Debug("cdlist") << "copy ctor: " << this
- << " from " << &l
- << " size " << d_size << std::endl;
+ CDList(const CDList& l)
+ : ContextObj(l),
+ d_list(nullptr),
+ d_size(l.d_size),
+ d_callDestructor(false),
+ d_sizeAlloc(0),
+ d_cleanUp(l.d_cleanUp),
+ d_allocator(l.d_allocator)
+ {
+ Debug("cdlist") << "copy ctor: " << this << " from " << &l << " size "
+ << d_size << std::endl;
}
CDList& operator=(const CDList& l) = delete;
Debug("cdlist") << "grow " << this << " " << getContext()->getLevel()
<< ": grow!" << std::endl;
- if(d_list == NULL) {
+ const size_t maxSize =
+ std::allocator_traits<AllocatorT>::max_size(d_allocator);
+ if (d_list == nullptr)
+ {
// Allocate an initial list if one does not yet exist
d_sizeAlloc = INITIAL_SIZE;
Debug("cdlist") << "initial grow of cdlist " << this
<< " level " << getContext()->getLevel()
<< " to " << d_sizeAlloc << std::endl;
- if(d_sizeAlloc > d_allocator.max_size()) {
- d_sizeAlloc = d_allocator.max_size();
+ if (d_sizeAlloc > maxSize)
+ {
+ d_sizeAlloc = maxSize;
}
- d_list = d_allocator.allocate(d_sizeAlloc);
- if(d_list == NULL) {
+ d_list =
+ std::allocator_traits<AllocatorT>::allocate(d_allocator, d_sizeAlloc);
+ if (d_list == nullptr)
+ {
throw std::bad_alloc();
}
- } else {
+ }
+ else
+ {
// Allocate a new array with double the size
size_t newSize = GROWTH_FACTOR * d_sizeAlloc;
- if(newSize > d_allocator.max_size()) {
- newSize = d_allocator.max_size();
+ if (newSize > maxSize)
+ {
+ newSize = maxSize;
Assert(newSize > d_sizeAlloc)
<< "cannot request larger list due to allocator limits";
}
- T* newList = d_allocator.allocate(newSize);
+ T* newList =
+ std::allocator_traits<AllocatorT>::allocate(d_allocator, newSize);
Debug("cdlist") << "2x grow of cdlist " << this
<< " level " << getContext()->getLevel()
<< " to " << newSize
<< " (from " << d_list
<< " to " << newList << ")" << std::endl;
- if(newList == NULL) {
+ if (newList == nullptr)
+ {
throw std::bad_alloc();
}
std::memcpy(newList, d_list, sizeof(T) * d_sizeAlloc);
- d_allocator.deallocate(d_list, d_sizeAlloc);
+ std::allocator_traits<AllocatorT>::deallocate(
+ d_allocator, d_list, d_sizeAlloc);
d_list = newList;
d_sizeAlloc = newSize;
}
while(d_size != size) {
--d_size;
d_cleanUp(&d_list[d_size]);
- d_allocator.destroy(&d_list[d_size]);
+ std::allocator_traits<AllocatorT>::destroy(d_allocator,
+ &d_list[d_size]);
}
} else {
d_size = size;
public:
/**
- * Main constructor: d_list starts as NULL, size is 0
+ * Main constructor: d_list starts as nullptr, size is 0
*/
CDList(Context* context,
bool callDestructor = true,
const CleanUp& cleanup = CleanUp(),
- const Allocator& alloc = Allocator()) :
- ContextObj(context),
- d_list(NULL),
- d_size(0),
- d_callDestructor(callDestructor),
- d_sizeAlloc(0),
- d_cleanUp(cleanup),
- d_allocator(alloc) {
+ const Allocator& alloc = Allocator())
+ : ContextObj(context),
+ d_list(nullptr),
+ d_size(0),
+ d_callDestructor(callDestructor),
+ d_sizeAlloc(0),
+ d_cleanUp(cleanup),
+ d_allocator(alloc)
+ {
}
/**
truncateList(0);
}
- this->d_allocator.deallocate(this->d_list, this->d_sizeAlloc);
+ std::allocator_traits<AllocatorT>::deallocate(
+ d_allocator, this->d_list, this->d_sizeAlloc);
}
/**
<< ": construct! at " << d_list
<< "[" << d_size << "] == " << &d_list[d_size]
<< std::endl;
- d_allocator.construct(&d_list[d_size], data);
+ std::allocator_traits<AllocatorT>::construct(
+ d_allocator, &d_list[d_size], data);
Debug("cdlist") << "push_back " << this
<< " " << getContext()->getLevel()
<< ": done..." << std::endl;
* wrapper around a pointer. Note that for efficiency, we implement
* only prefix increment and decrement. Also note that it's OK to
* create an iterator from an empty, uninitialized list, as begin()
- * and end() will have the same value (NULL).
+ * and end() will have the same value (nullptr).
*/
class const_iterator {
T const* d_it;
typedef const T* pointer;
typedef const T& reference;
- const_iterator() : d_it(NULL) {}
+ const_iterator() : d_it(nullptr) {}
inline bool operator==(const const_iterator& i) const {
return d_it == i.d_it;