本文整理汇总了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;
}
}
示例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;
}
示例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++;}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例8: push_back
void StrVec::push_back(const string& s) {
chk_n_alloc();
alloc.construct(first_free++, s);
}
示例9: create
static T* create() {
T* p = alloc_.allocate(1);
if (!p) return nullptr;
alloc_.construct(p);
return p;
};