当前位置: 首页>>代码示例>>C++>>正文


C++ allocator::destroy方法代码示例

本文整理汇总了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);
    }
}
开发者ID:bowanggithub,项目名称:C-primer,代码行数:9,代码来源:ex13.44.cpp

示例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());
	}
}
开发者ID:chris918,项目名称:Cpp-Primer-5th-Edition-Answer,代码行数:15,代码来源:ex13_39_40.cpp

示例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_);
            }
        }
开发者ID:keitee,项目名称:kb,代码行数:13,代码来源:t_ex_strvec.cpp

示例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));
	}
}
开发者ID:chris918,项目名称:Cpp-Primer-5th-Edition-Answer,代码行数:28,代码来源:ex13_39_40.cpp

示例5: free

void str_vec::free()
{
    for(std::string *p = first_free;p > elements;)
        alloc.destroy(--p);
    alloc.deallocate(elements,cap-elements);
}
开发者ID:Edward-surpass,项目名称:Cplusplusprimer5,代码行数:6,代码来源:14.26f.cpp

示例6: free

void String::free() {
    if (cStringBegin) {
        std::for_each(cStringBegin, cStringEnd, [this](char &c){alloc.destroy(&c);});
        alloc.deallocate(cStringBegin, cStringEnd - cStringBegin);
    }
}
开发者ID:Mlieou,项目名称:cpp_primer,代码行数:6,代码来源:String.hpp


注:本文中的std::allocator::destroy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。