本文整理汇总了C++中std::allocator::destroy方法的典型用法代码示例。如果您正苦于以下问题:C++ allocator::destroy方法的具体用法?C++ allocator::destroy怎么用?C++ allocator::destroy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::allocator
的用法示例。
在下文中一共展示了allocator::destroy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: free
void String::free()
{
if (elements)
{
std::for_each(elements,end,
[this](char& c) {alloc.destroy(&c);});
alloc.deallocate(elements,end-elements);
}
}
示例2: free
/**
* @brief destroy the elements and deallocate the space previously allocated.
*/
void StrVec::free()
{
if (element) // if not nullptr
{
//! destory it in reverse order.
for (auto p = first_free; p != element; /* empty */)
alloc.destroy(--p);
alloc.deallocate(element, capacity());
}
}
示例3: free
void free()
{
// may not pass deallocate() a nullptr.
if (element_)
{
// move backward and use "--p" to delete [element_, free)
// call type dtor, which is string dtor.
for (auto p = free_; p != element_; /* empty */ )
alloc.destroy(--p);
alloc.deallocate(element_, cap_ - element_);
}
}
示例4: resize
/**
* @brief Resizes it to the specified number of elements.
* @param __new_size Number of elements it should contain.
* @param __x Data with which new elements should be populated.
*
* This function will resize it to the specified
* number of elements. If the number is smaller than the
* current size the it is truncated, otherwise
* the it is extended and new elements are populated with
* given data.
*/
void StrVec::resize(std::size_t n, const std::string &s)
{
if (n < size())
{
//! destroy the range : [element+n, first_free) using destructor
for (auto p = element + n; p != first_free; /* empty */)
alloc.destroy(p++);
//! move frist_free point to the new address element + n
first_free = element + n;
}
else if (n > size())
{
for (auto i = size(); i != n; ++i)
push_back(std::string(s));
}
}
示例5: free
void str_vec::free()
{
for(std::string *p = first_free;p > elements;)
alloc.destroy(--p);
alloc.deallocate(elements,cap-elements);
}
示例6: free
void String::free() {
if (cStringBegin) {
std::for_each(cStringBegin, cStringEnd, [this](char &c){alloc.destroy(&c);});
alloc.deallocate(cStringBegin, cStringEnd - cStringBegin);
}
}