468,103 Members | 1,322 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

return result of "copy", "remove_copy"

Hello,

The C++ reference says the return result of "copy" is an output
iterator. I'm wondering how I can assign the returned iterator to
some other iterator. I tried

int main(){
string s("abcdefg");
vector<charv;
vector<char>::iterator k = copy(s.begin(),s.end(),back_inserter(v));
return 0;
}

because for "copy", the returned iterator should point to the last
element in the destination range. However, the code above couldn't
compile. What's my problem? Moreover, does "copy" return the iterator
pointing to the last element or one past the last element?

As for "remove_copy", does it return the iterator pointing to one past
the last element? How can I assign the return result to some
iterator? I think it should be the same as for "copy".

Thanks,
Jess

Jul 6 '07 #1
3 1645
On Jul 6, 10:51 am, Jess <w...@hotmail.comwrote:
Hello,

The C++ reference says the return result of "copy" is an output
iterator. I'm wondering how I can assign the returned iterator to
some other iterator. I tried

int main(){
string s("abcdefg");
vector<charv;
vector<char>::iterator k = copy(s.begin(),s.end(),back_inserter(v));
copy will return the back_insert_iterator

std::back_insert_iterator<std::vector<char k = copy(s.begin(),
s.end(), back_insertor(v));

Moreover, does "copy" return the iterator
pointing to the last element or one past the last element?
last element
>
As for "remove_copy", does it return the iterator pointing to one past
the last element?

no. last element.
How can I assign the return result to some
iterator? I think it should be the same as for "copy".
Yeah.
Thanks,
Jess

Jul 6 '07 #2
"Neelesh Bodas" <ne***********@gmail.comwrote in message
news:11**********************@a26g2000pre.googlegr oups.com...
> Moreover, does "copy" return the iterator
pointing to the last element or one past the last element?
last element
I think not. The typical implementation does something similar to this:

template<class In, class Out>
Out copy(In begin, In end, Out dest)
{
while (begin != end)
*out++ = *begin++;
return out;
}

so what it returns is an iterator referring to the point after the last
element of the result.
Jul 7 '07 #3
Thanks for the replies!
Jess

Jul 8 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Chagh | last post: by
3 posts views Thread by uthuras | last post: by
reply views Thread by Florian | last post: by
7 posts views Thread by Big Moxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.