4 ms·
People like to harp on C++, but templates permit code that is simultaneously maximally clear and efficient: #include <utility> swap(s[i], s[j]);
by tobinfricke 6y ago
People like to harp on C++, but templates permit code that is simultaneously maximally clear and efficient:
#include <utility>
swap(s[i], s[j]);
- Iwan-Zotow 6y agoPrefer pythonic style std::tie(b, a) = std::make_tuple(a, b);
- CamperBob2 6y agoWhy? That's about 400% harder to read. Even someone who doesn't know how to program in any language can probably infer what the C++ example does.
- ChrisRR 6y agoI know normally python is simpler and easier to read, but this is not one of those times. The example C++ is much easier to read and more intuitive as to what it does.
- tobinfricke 6y agoTo be fair, the Python syntax is just: a, b = b, a The "std::tie(b, a) = std::make_tuple(a, b)" is an attempt to replicate the Python style in C++... which, I agree, is certainly not clear, and, unlike using the "swap" algorithm, it's also unclear whether it will result in efficient code.