I am working on the following piece of code, where I am trying to pass a vector of gsl::byte as a span of gsl::byte to the function test_func.
#include<iostream>
#include <array>
#include <vector>
#include <gsl/span>
template <typename T, std::size_t Extent = gsl::dynamic_extent>
using span = gsl::span<T, Extent>;
using byte = gsl::byte;
void test_func(span<byte> arg)
{
// Some tasks here
}
int main()
{
test_func(std::vector<byte>{byte(0)});
return 0;
}
Unfortunately I am getting the following error during compilation:
error: could not convert 'std::vector<std::byte>(std::initializer_list<std::byte>{((const std::byte*)(& const std::byte [1]{(std::byte)0})), 1}, std::allocator<std::byte>())' from 'std::vector<std::byte>' to 'span<std::byte>' {aka 'gsl::span<std::byte, 18446744073709551615>'}
Any suggestion on this? I thought there is an automatic conversion from vector to span but it seems not the actual scenario. Thanks a million in advance.