Is there a common idiom for doing something twice, as in the following situation?
for ( int i = 0; i < num_pairs; i++ ) {
cards.push_back( Card(i) );
cards.push_back( Card(i) );
}
I have a feeling that there's a clearer way than introducing a new loop variable counting from 0 to 1, especially since it isn't used except for counting.
for ( int i = 0; i < num_pairs; i++ )
for ( int j = 0; j < 2; j++ )
cards.push_back( Card(i) );
(Card
is just some class I made up and not relevant to the question.)
Twice; two times in a row. Usually used to emphasize that something is excessive or has an excessive effect. The student had enough alcohol in his system to kill a person twice over. Having to deal with the insurance company after my husband's death has made me suffer twice over.
think twice. COMMON If you think twice about doing something, you consider it again and usually decide not to do it. She'd better shut her mouth and from now on think twice before saying stupid things. If they don't enjoy the experience, they will think twice before they visit again.
Proverbs are well-known for stating a piece of advice or general fact. For example, ‘a picture is worth a thousand words’ is a proverb – a general truth. Let us consider the idiom ‘ bite off more than you can chew ‘. What you meant is that you are trying to do something that is too hard for you.
It is comparatively easier to remember words unlike idioms because idioms (phrases) contain 3 or more words. And, remembering a chain of words and then speaking them in the correct sequence is not easy.
You probably want to use the fill_n
function in <algorithm>
for ( int i = 0; i < num_pairs; i++ )
std::fill_n(std::back_inserter(cards), 2, Card(i));
Personally I would just leave it how it is. It looks clean, it's easy to understand, and it's quite readable. Just leave a comment mentioning why you do it twice (but you would do that no matter what).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With