Skip to content

Literal Type, when empty #30

@mccann

Description

@mccann

I wanted to drop this in to replace std::vector, but unfortunately I am unable to.

With std::vector, I am able to use an empty/default constructed instance as a 'literal value' ie, the following static_assert can be evaluated at compile time:

    constexpr auto foo = std::vector<uint8_t>{};
    static_assert(foo.empty());

Looking at the source, I see that the code specifically handles consteval contexts and (if I am reading correctly) always uses allocator. This explains the error about an empty constexpr small_vector<> containing heap allocations, and I imagine/guess that this is to avoid difficulty in switching between "heap" and "inline" storage in a consteval context.

Anyway, not sure if this is something that should even be supported, but I don't see a technical reason why small_vector couldn't be literal when contents fit inline, or at least when empty. And it would be one more way it is compatible with std::vector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions