I want to use std::span as a template template argument to a function.
gcc seems to accept the following code, but clang rejects.
#include <iostream>
#include <span>
#include <vector>
std::vector v{1,2,3,4,5,6};
template <template <typename> class S>
S<int> GetSpan()
{
return v;
}
int main()
{
auto x = GetSpan<std::span>();
return 0;
}
Can someone please explain why this is the case ?
https://godbolt.org/z/Ks9M5oqKc
>Solution :
You are missing the second template parameter, the extent:
template <template <typename, std::size_t> class S>
S<int, std::dynamic_extent> GetSpan()
{
return v;
}
To make it work with a custom span-like type as well as std::span you could possibly make it take a non-type parameter pack std::size_t... or auto....
template <template <typename, std::size_t...> class S>
auto GetSpan()
{
return S(v);
}