 
      
    | You are here | mpark.github.io | ||
| | | | | nelari.us | |
| | | | | A small look at some useful template techniques, in the context of trying to bind functions to a virtual machine. I wrote this post mostly for myself so that these techniques would be listed all in one place. | |
| | | | | 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 | |
| | | | | The size of std::array is known at compile-time given the type. Yet it only provides a regular .size() member function: template struct array { constexpr std::size_t size() const { return N; } }; This is annoying if you're writing generic code that expects some sort of compile-time sized range. | |
| | | | | www.kuniga.me | |
| | | NP-Incompleteness: | ||