Search code examples
c++stdstdvectorstd-span

Simplest way to assign std::span to std::vector


I wanted to do this

#include <vector>
#include <span>

struct S
{
    std::vector<int> v;
    void set(std::span<int> _v)
    {
        v = _v;
    }
};

But it does not compile. What are the alternatives?


Solution

  • v.assign(_v.begin(), _v.end());