unsigned i for (i = 0; i < piles[from].size(); i++) piles[to].push_back(piles[from][i])
for (unsigned i = 0; i < names.size(); i++)
const std::string & v = names[i]
if samecode_utils::is_register(v)
vars.push_back(v)
outi copy(outi d, ini b, ini e)
while b != e
*d++ = *b++
return d
std::vector v1(10);
std::list l2;
copy(l2.begin(), v1.begin(), v1.end())
std::vectorv1(10); std::list l2(v1.begin(), v1.end());
<iterator>.
*, pre and post ++, and assignment.
template < class ContainerT >
class back_insert_iterator { ... };
vector<int> ivec; back_insert_iterator<vector<int> > bi(ivec);
std::back_inserter(c).
copy( l1.begin(), l1.end(), back_insert_iterator<vector<int> >(v1)) copy( l1.begin(), l1.end(), back_inserter(v1))
*bi++ = v pushes v onto the end of c.
template < class ContainerT >
back_insert_iterator {
ContainerT cont
back_insert_iterator(ContainerT c)
: cont(c) { }
operator = (ContainerT::value_type v)
cont.push_back(v);
operator * (void)
return * this;
// similarly for pre and post ++
}
vector<int> ivec; back_insert_iterator<vector<int> > bi(ivec);bi[1] = 3
push_back().
*bi++ = 3 // ok but redundant.bi = 4// ok but confusing.
template < class ContainerT >
class front_insert_iterator { ... };
vector<int> ivec; front_insert_iterator<vector<int> > fi(ivec);
std::front_inserter(c).
std::copy( l1.begin(), l1.end(), std::front_inserter(v1))
template < class ContainerT >
class insert_iterator { ... };
vector<int> ivec(10); insert_iterator<vector<int> > bi(ivec, ivec.begin() + 1);
std::inserter(c).
*bi++ = v inserts v at the initial iterator.
unsigned ifor (i = 0; i < piles[from].size(); i++)piles[to].push_back(piles[from][i])std::copy( piles[from].begin(), piles[from].end(), std::back_inserter(piles[to]))
for (unsigned i = 0; i < names.size(); i++)const std::string & v = names[i]if samecode_utils::is_register(v)vars.push_back(v)std::remove_copy_if( names.begin(), names.end(), std::back_inserter(vars), samecode_utils::is_register) )
std::ostream &
operator << (std::ostream & os, pile p)
pile_iter i
for (i = p.begin(); i != p.end(); i++)
os << *i
return os
while iss >> c cards.push_back(c)
<iterator>.
template < class ElementT >
class ostream_iterator { ... };
ostream_iterator<int> osi(cout)
const char *.
ostream_iterator<int> osi(cout, ", ")
operator << (ElementT) must be defined.
* and ++ are no-ops; = does the write.
ostream_iterator<int> osi(cout, " "); *osi++ = 1; // write 1 to std-outosi = 2;// write 2 to std-out
template < class ElementT >
class istream_iterator { ... };
std::istream_iterator<int> isi(cin)
operator >> (ElementT) must be defined.
== against the EOS iterator, not .eof().
* returns the most recently read value.
-> returns a field in the most recently read value.
++ reads a new value and returns an istream iterator to it.
++ reads a new value and returns an istream iterator to
the previously read value.
i == j does not imply
*i == *j.
i == j does not imply ++i == ++j. (why?)
std::ostream & operator << (std::ostream & os, pile p)pile_iter ifor (i = p.begin(); i != p.end(); i++)os << *istd::copy(p.begin(), p.end(), std::ostream_iterator(os)); return os
while (iss >> c)cards.push_back(c);std::copy( std::istring_stream<card>(iss), std::istring_stream<card>(), std::back_inserter(cards));
This page last modified on 20 March 2003.