B
bluekite2000
and why doesnt the standard vector have such conversion available?
and why doesnt the standard vector have such conversion available?
and why doesnt the standard vector have such conversion available?
What if b is already constructed?
b = vector said:Another question
Say you have
vector<float> a(3);
//init a
vector<std::complex<float> > c(3);
//init c
Now I want something like
real(c)=a;
Currently I have
for(int i=0;i<c.size();i++)
c.real()=a;
Which I dont really like.
Ali Çehreli said:Then it's assignment:
b = vector<double>(a.begin(), a.end());
and why doesnt the standard vector have such conversion available?
Actually, a probably better expression (for clarity,
maintainability, and performance) is:
b.assign( a.begin(), a.end() );
There is no "assign" function on std::vector.
//Or:
B.resize(A.size());
std::copy(A.begin(), A.end(), B.begin());
Clark S. Cox III wrote:
23.2.4.1 vectors constructors, copy, and assignment
<snip>
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
Effects:
erase(begin(), end());
insert(begin(), first, last);
template <class Size, class U> void assign(Size n, const U& u = U());
Effects:
erase(begin(), end());
insert(begin(), n, t);
<snip>
Maybe your compiler lacks member template support?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.