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


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

本文整理汇总了C++中allocator::construct方法的典型用法代码示例。如果您正苦于以下问题:C++ allocator::construct方法的具体用法?C++ allocator::construct怎么用?C++ allocator::construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在allocator的用法示例。


在下文中一共展示了allocator::construct方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: push_front

void BigNumber::push_front(int num,const unsigned char c)
{//Push multiple characters front
    if(!len){
        cap=len=num+1;
        val=alloc.allocate(cap);
        first_free=val;
        dot=0;
        while(num--) alloc.construct(first_free++,c);
        alloc.construct(first_free++,'+');
    }else{
        int newcap=len+num;
        int newdot=dot;
        unsigned char *newval=alloc.allocate(newcap);
        unsigned char *newfirst_free=newval;
        unsigned char *oldval=val;
        while(num--) alloc.construct(newfirst_free++,c);
        while(oldval!=first_free)
            alloc.construct(newfirst_free++,*oldval++);
        release();
        val=newval;
        first_free=newfirst_free;
        cap=len=newcap;
        dot=newdot;
    }
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:25,代码来源:BigNumber+Class.cpp

示例2: free

String &String::operator+(const String &str)
{
    size_t sz_temp = sz + str.sz;
    char *p = alloc.allocate(sz_temp);
    char *q = p;
    for(size_t i = 0;i < sz_temp; ++i)
    {
        if(i < sz)
            alloc.construct(q++,s[i]);
        else
            alloc.construct(q++,str.s[i-sz]);
    }
    free();
    s = p;
    sz = sz_temp;
    return *this;
}
开发者ID:Edward-surpass,项目名称:Cplusplusprimer5,代码行数:17,代码来源:14.26ff.cpp

示例3: push_back

void BigNumber::push_back(const unsigned char c)
{//Push a character back
    if(!len||len>=cap){
        int newcap=cap?(2*cap):2;
        int newdot=dot;
        unsigned char *newval=alloc.allocate(newcap);
        unsigned char *newfirst_free=newval;
        unsigned char *oldval=val;
        while(oldval!=first_free) alloc.construct(newfirst_free++,*oldval++);
        alloc.construct(newfirst_free++,c);
        release();
        val=newval;
        first_free=newfirst_free;
        len=first_free-val;
        cap=newcap;
        dot=newdot;
    }else{alloc.construct(first_free++,c);len++;}
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:18,代码来源:BigNumber+Class.cpp

示例4: while

BigNumber& BigNumber::reverse_copy(BigNumber &A)
{//Reverse copy
    cap=len=A.len;
    val=alloc.allocate(cap);
    first_free=val;
    dot=0;
    unsigned char *begin=A.first_free;
    while(begin!=A.val){
        alloc.construct(first_free++,*--begin);
        if(*begin=='.') dot=first_free-val-1;
    }
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:12,代码来源:BigNumber+Class.cpp

示例5: release

BigNumber& BigNumber::operator=(long long num)
{//Copy a long long integer
    release();
    cap=21;
    val=alloc.allocate(cap);
    first_free=val;
    bool flag=true;
    long long e=num%10;
    num/=10;
    if(e<0) e=-e;
    if(num<0) {flag=false;num=-num;}
    alloc.construct(first_free++,e+48);
    while(num){
        e=num%10;
        num/=10;
        alloc.construct(first_free++,e+48);
    }
    if(flag) alloc.construct(first_free++,'+');
    else alloc.construct(first_free++,'-');
    len=first_free-val;
    dot=0;
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:22,代码来源:BigNumber+Class.cpp

示例6: reallocate

void StrVec::reallocate() {
	auto newcapacity = size() ? 2 * size() : 1;
	auto newdata = alloc.allocate(newcapacity);
	auto dest = newdata;
	auto elem = elements;
	0
	for (size_t i = 0; i != size(); ++i) {
		alloc.construct(dest++, std::move(*elem++));
	}
	free();
	elements = newdata;
	first_free = dest;
	cap = elements + newcapacity;
}
开发者ID:PayneSun,项目名称:FirstRepository,代码行数:14,代码来源:source.cpp

示例7: cut_tail

void BigNumber::cut_tail(int num)
{
    int newcap = num + 3;
    int newdot;
    unsigned char *newval = alloc.allocate(newcap);
    unsigned char *newfirst_free = newval;
    unsigned char *oldval = val;
    while((first_free - oldval) != newcap) ++oldval;
    unsigned char *start = oldval;
    while(oldval != first_free){
        if(*oldval == '.') newdot = oldval - start;
        alloc.construct(newfirst_free++,*oldval++);
    }
    release();
    val=newval;
    first_free=newfirst_free;
    len=first_free-val;
    cap=newcap;
    dot=newdot;
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:20,代码来源:BigNumber+Class.cpp

示例8: push_back

void StrVec::push_back(const string& s) {
	chk_n_alloc();
	alloc.construct(first_free++, s);
}
开发者ID:PayneSun,项目名称:FirstRepository,代码行数:4,代码来源:source.cpp

示例9: create

 static T* create() {
     T* p = alloc_.allocate(1);
     if (!p) return nullptr;
     alloc_.construct(p);
     return p;
 };
开发者ID:Stone1973,项目名称:crossbow,代码行数:6,代码来源:singleton.hpp


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