本文整理汇总了C++中copy函数的典型用法代码示例。如果您正苦于以下问题:C++ copy函数的具体用法?C++ copy怎么用?C++ copy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了copy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _substract
/* basic a - b; where both a and b are positive numbers */
slist* _substract(slist *a, slist *b)
{
slist *diff = NULL;
if (a == NULL && b == NULL) {
diff = insert(diff, 0);
return (diff);
}
if (a == NULL) {
diff = copy(b);
diff = push_back(diff, -1);
return (diff);
}
if (b == NULL) {
return (copy(a));
}
unsigned int carry = 0;
unsigned int negative = 0;
slist *g = greater(a, b); /* greater pointer */
slist *l = NULL; /* lesser pointer */
if (g == NULL) { /* both are equal */
diff = insert(diff, 0);
return (diff);
} else if (g == a) {
l = b;
} else {
l = a;
negative = 1;
}
while (g && l) {
if ((g->data - carry) >= l->data) {
diff = push_back(diff, (g->data - carry - l->data));
carry = 0;
} else {
diff = push_back(diff, (10 + g->data - carry - l->data));
carry = 1;
}
g = g->next;
l = l->next;
}
if (g == NULL && l == NULL) {
/* diff has correct result */
} else if (l == NULL) {
while (g) {
diff = push_back(diff, g->data - carry);
carry = 0;
}
} else if (g == NULL) {
/* something went wrong, we shouldn't have been here */
/* err!!? */
} else {
/* not possible; */
}
if (negative)
diff = push_back(diff, -1);
return (diff);
}
示例2: copy
word::word(const word& other)
{
copy(other);
}
示例3: copy
void DSA_controller::GetPattern(string ith_Pattern)
{
copy(ith_Pattern.begin(),ith_Pattern.end(),back_inserter(tempPattern));
reverse(tempPattern.begin(), tempPattern.end());
}
示例4: copy
CMfxTrack::CMfxTrack( const CMfxTrack& rhs )
{
copy( rhs );
}
示例5: copy
CityWeather &
CityWeather::operator=(const CityWeather & other)
{
return copy( other );
}
示例6: copy
void TextEvent::setType(int type){
ProtocolEntry *toCopy = copy();
_type = type;
protocol(toCopy, this);
}
示例7: copy
std::string field::value() const
{
std::string s;
copy(_payload.begin(), _payload.end(), back_inserter(s));
return s;
}
示例8: return
CCFiniteTimeAction * CCActionInstant::reverse() {
return (CCFiniteTimeAction*) (copy()->autorelease());
}
示例9: copy
// copy constructor
Exception::Exception (const Exception & xpt)
{
copy (xpt);
}
示例10: check
template<class R> const View<T>& operator =(const R& r) const {
check(boost::size(r) == this->size(), "can't assign range " + str(r) +
" to view " + str(*this));
copy(r, *this);
return *this;
}
示例11:
CCLuaValue& CCLuaValue::operator=(const CCLuaValue& rhs)
{
if (this != &rhs) copy(rhs);
return *this;
}
示例12: copy
CCLuaValue::CCLuaValue(const CCLuaValue& rhs)
{
copy(rhs);
}
示例13: getOption
//.........这里部分代码省略.........
// Lagrange multipliers for the nonlinear constraints that aren't eliminated
lam_f2 = ssym("lam_f2",nf2);
if(verbose_){
cout << "Allocated intermediate variables." << endl;
}
// Lagrange multipliers for constraints
lam_g = vertcat(lam_v_eq,lam_f2);
// Lagrangian function
SX lag = f + inner_prod(lam_x,x);
if(!f2.empty()) lag += inner_prod(lam_f2,f2);
if(!v.empty()) lag += inner_prod(lam_v_eq,v_def);
// Gradient of the Lagrangian
SX lgrad = casadi::gradient(lag,x);
if(!v.empty()) lgrad -= vertcat(SX::zeros(nu),lam_v_eq); // Put here to ensure that lgrad is of the form "h_extended -v_extended"
makeDense(lgrad);
if(verbose_){
cout << "Generated the gradient of the Lagrangian." << endl;
}
// Condensed gradient of the Lagrangian
f1 = lgrad[Slice(0,nu)];
nf1 = nu;
// Gradient of h
SX v_eq_grad = lgrad[Slice(nu,nu+nv)];
// Reverse lam_v_eq and v_eq_grad
SX v_eq_grad_reversed = v_eq_grad;
copy(v_eq_grad.rbegin(),v_eq_grad.rend(),v_eq_grad_reversed.begin());
SX lam_v_eq_reversed = lam_v_eq;
copy(lam_v_eq.rbegin(),lam_v_eq.rend(),lam_v_eq_reversed.begin());
// Augment h and lam_v_eq
v_eq.append(v_eq_grad_reversed);
v.append(lam_v_eq_reversed);
}
// Residual function G
SXVector G_in(G_NUM_IN);
G_in[G_X] = x;
G_in[G_LAM_X] = lam_x;
G_in[G_LAM_G] = lam_g;
SXVector G_out(G_NUM_OUT);
G_out[G_D] = v_eq;
G_out[G_G] = g;
G_out[G_F] = f;
rfcn_ = SXFunction(G_in,G_out);
rfcn_.setOption("number_of_fwd_dir",0);
rfcn_.setOption("number_of_adj_dir",0);
rfcn_.setOption("live_variables",true);
rfcn_.init();
if(verbose_){
cout << "Generated residual function ( " << shared_cast<SXFunction>(rfcn_).getAlgorithmSize() << " nodes)." << endl;
}
// Difference vector d
SX d = ssym("d",nv);
if(!gauss_newton_){
vector<SX> dg = ssym("dg",nv).data();
示例14: motif4generate
//.........这里部分代码省略.........
MATRIX_T* M = log_ord_index(M4, ind, M4_cols);
VECTOR_ID(free)(M4_cols);
for (int i = 0; i < (int)M->size1; i++) {
VECTOR_ID(view) M_row_i = MATRIX_ID(row)(M, i);
VECTOR_ID(mul)(&M_row_i.vector, w);
}
// id=ID4(ind);
VECTOR_T* id = logical_index(ID4, ind);
VECTOR_ID(add_constant)(id, -1.0);
// l=N4(ind);
VECTOR_T* l = logical_index(N4, ind);
// x=sum(M,2)./l;
VECTOR_T* x = sum(M, 2);
VECTOR_ID(div)(x, l);
// M(M==0)=1;
MATRIX_T* M_eq_0 = compare_elements(M, fp_equal, 0.0);
logical_index_assign(M, M_eq_0, 1.0);
MATRIX_ID(free)(M_eq_0);
// i=prod(M,2).^(1./l);
VECTOR_T* prod_M = prod(M, 2);
MATRIX_ID(free)(M);
VECTOR_T* l_pow_neg_1 = pow_elements(l, -1.0);
VECTOR_ID(free)(l);
VECTOR_T* i = pow_elements(prod_M, l_pow_neg_1);
VECTOR_ID(free)(prod_M);
VECTOR_ID(free)(l_pow_neg_1);
// q = i./x;
VECTOR_T* q = copy(i);
VECTOR_ID(div)(q, x);
VECTOR_ID(free)(x);
// [idu j]=unique(id);
VECTOR_T* j;
VECTOR_T* idu = unique(id, "last", &j);
VECTOR_ID(free)(id);
// j=[0;j];
VECTOR_T* temp = VECTOR_ID(alloc)(j->size + 1);
VECTOR_ID(set)(temp, 0, -1.0);
VECTOR_ID(view) temp_subv = VECTOR_ID(subvector)(temp, 1, j->size);
VECTOR_ID(memcpy)(&temp_subv.vector, j);
VECTOR_ID(free)(j);
j = temp;
// mu=length(idu);
int mu = length(idu);
// i2=zeros(mu,1);
VECTOR_T* i2 = zeros_vector(mu);
// q2=i2; f2=i2;
VECTOR_T* q2 = copy(i2);
VECTOR_T* f2 = copy(i2);
// for h=1:mu
for (int h = 0; h < mu; h++) {
// i2(h)=sum(i(j(h)+1:j(h+1)));
int j_h = (int)VECTOR_ID(get)(j, h);
int j_h_add_1 = (int)VECTOR_ID(get)(j, h + 1);
示例15: StringTrim
std::string StringTrim(const std::string& str)
{
std::string copy(str);
StringTrimInPlace(copy);
return copy;
}