February 2020
Intermediate to advanced
292 pages
8h 54m
English
In this recipe, we'll write a method with one parameter (std::span) that can be used in different contexts. Then, we'll highlight the flexibility it offers:
#include <iostream>#include <vector>#include <array>#include <span>void print(std::span<int> container){ for(const auto &c : container) std::cout << c << "-";}
int main(){ int elems[]{4, 2, 43, 12}; print(elems); std::vector vElems{4, 2, 43, 12}; print(vElems);}
Let's see how this works.
Read now
Unlock full access