Possible Duplicate:
What are your favorite C++ Coding Style idioms
Dear C++ fans,
Could you list here your favorite C++ idioms? It is better to list those which are useful yet not well-known.
Firstly, I put one of mine:
To avoid tedious repeating for (size_t i = 0; i < n; ++i) {...}
, I use a macro like this:
#define LOOP(n) for (size_t _i = 0; _i < n; ++_i)
_i is a placeholder as bind uses.
So I can write:
vector<int> coll(100);
LOOP (100)
{
coll[_i] = _i;
}
LOOP (100)
{
auto a = _i;
LOOP (100)
{
auto b = _i;
cout << a << b;
}
}
RAII is on the top of my list. There are so many cases when it just comes in handy...
Most useful as a generic implementation like Andrei Alexandrescu's libloki.
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