次の関数を考えると、読み取り専用のfloat スパン (動的または任意の静的サイズのいずれか):
template <long N> void foobar(gsl::span<const float, N> x);
私が持っているとしましょうvector<float>
。それを引数として渡すことは機能しませんが、使用することもできませんgsl::as_span
:
std::vector<float> v = {1, 2, 3};
foobar(gsl::as_span(v));
上記はコンパイルされません。どうやらgsl::as_span()
a を返しますgsl::span<float>
。暗黙のキャストが不可能な理由を理解してgsl::span<const float>
いないことに加えて、読み取り専用スパンを強制的gsl::as_span()
に返す方法はありますか?