W
woessner
I've been flipping through the Josuttis book trying to find it there's
a better way to accomplish this. Haven't come across anything so I
thought I'd turn to the group.
Suppose I have 2 containers, a large one and a small one. I would like
to replace the elements of the larger container with the elements of
the smaller container, but in such a way the the elements are repeated
(or tiled, hence the subject) until the larger container is full.
Here's a simple example: I have a deque<bool> and I'd like to fill it
up with alternating 1's and 0's. Naievely, this is how I would go
about it:
deque<bool>::iterator it;
deque<bool> coll(100);
for(it = coll.begin(); it != coll.end(); ++it)
{
*it = false;
*++it = true;
}
Of course this assumes that the size of coll is even. In general, this
translates to the size of the larger container being an integer
multiple of the size of the smaller container. I can live with that
assumption.
But even with the safety assumption, this seems clumsy and error prone.
Is there a better way to accomplish this?
Thanks in advance,
Bill
a better way to accomplish this. Haven't come across anything so I
thought I'd turn to the group.
Suppose I have 2 containers, a large one and a small one. I would like
to replace the elements of the larger container with the elements of
the smaller container, but in such a way the the elements are repeated
(or tiled, hence the subject) until the larger container is full.
Here's a simple example: I have a deque<bool> and I'd like to fill it
up with alternating 1's and 0's. Naievely, this is how I would go
about it:
deque<bool>::iterator it;
deque<bool> coll(100);
for(it = coll.begin(); it != coll.end(); ++it)
{
*it = false;
*++it = true;
}
Of course this assumes that the size of coll is even. In general, this
translates to the size of the larger container being an integer
multiple of the size of the smaller container. I can live with that
assumption.
But even with the safety assumption, this seems clumsy and error prone.
Is there a better way to accomplish this?
Thanks in advance,
Bill