 
      
    | You are here | rodusek.com | ||
| | | | | quuxplusone.github.io | |
| | | | | Someone on the cpplang Slack asks: How can I view a std::pair<T, T> as if it were a range of two Ts? That is, fill in the blank in this sample program: template<std::ranges::range R> void increment_all(R&& rg) { for (auto&& elt : rg) { elt = elt + 1; } } template<class T> auto F(std::pair<T, T>& kv) { ~~~~ } int main() { std::pair<int, int> kv = {1, 2}; increment_all(F(kv)); assert(kv.first == 2 && kv.second == 3); std::ranges::fill(F(kv), 4); assert(kv.first == 4 && kv.second == 4); } | |
| | | | | www.foonathan.net | |
| | | | | Let me share a useful insight with you: constexpr is a platform. Just like you write code that targets Windows or a microcontroller, you write code that targets compile-time execution. In both cases you restrict yourself to the subset of C++ that works on your target platform, use conditional compilation if your code needs to be portable, and execute it on the desired target platform. You can thus view constexpr as another platform you can target; it just so happens to be run by your compiler. This insig... | |
| | | | | lapinozz.github.io | |
| | | | | My goodbye to template metaprogramming. One last tribute; computing A Star pathfinding algorithm at compile-time | |
| | | | | artificial-mind.net | |
| | | Articles about Graphics, C++, Optimization, Game Development, Programming Languages, and more. Personal blog of Philip Tretter writing under the alias of Artificial Mind. | ||