No viable conversion from ‘const VertexAttrib [2]’ to ‘std::span<VertexAttrib>’

  c++, c++20

I thought std::span was basically built to accepts arrays or vectors, so I don’t know why my function won’t accept this array.

The function signature is:

void init(size_t size, const void *data, GLenum usage, std::span<VertexAttrib> attribs) const

Called with:

_vertices.init(4 * sizeof(ImageTexture2D),
                     vertices ? vertices->data() : nullptr,
                     vertices ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW,
               TexturedVertex2D::attribs);

Where TexturedVertex2D::attribs is:

struct VertexAttrib {
    /** Number of components per generic vertex attribute */
    uint8_t dim;
    /** Data type of each component in the array */
    VertexAttribType type;
};

struct TexturedVertex2D {
    glm::vec2 pos;
    glm::vec2 tex;

    static constexpr VertexAttrib attribs[]{{2,VertexAttribType::Float}, {2,VertexAttribType::Float}};
};

The error from the compiler is:

error C2664: ‘void VertexArrayObject::init(size_t,const void *,GLenum,std::span<VertexAttrib,18446744073709551615>) const’: cannot convert argument 4 from ‘const VertexAttrib [2]’ to ‘std::span<VertexAttrib,18446744073709551615>’

How can I allow init to take contexpr arrays or inline-constructed arrays like that?

Source: Windows Questions C++

LEAVE A COMMENT