Create a std::span from a Pointer and a Size
Learn how to create std::span from a pointer and a size.
We'll cover the following...
You can create a std::span
from a pointer and a size.
Press + to interact
#include <algorithm>#include <iostream>#include <span>#include <vector>int main() {std::cout << '\n';std::cout << std::boolalpha;std::vector myVec{1, 2, 3, 4, 5};std::span mySpan1{myVec};std::span mySpan2{myVec.data(), myVec.size()};bool spansEqual = std::equal(mySpan1.begin(), mySpan1.end(),mySpan2.begin(), mySpan2.end());std::cout << "mySpan1 == mySpan2: " << spansEqual << '\n';std::cout << '\n';}
As you may expect, mySpan1
, created from the std::vector
(line 12), and mySpan2
, created from a pointer and a size ...