Skip to content

Feature request: Make static_vector "trivially relocatable" when possible #258

Open
@Quuxplusone

Description

@Quuxplusone

It was recently discussed on the cpplang Slack that Boost implements a lot of class types that are "Platonically trivially relocatable" without being known to the compiler to be trivially relocatable.
In P1144R9 my go-to example was boost::movelib::unique_ptr<int>; but in the above discussion it was pointed out that boost::container::static_vector<int,10> would be a less archaic example, so P1144R10 might switch to that.

Executive summary: Wouldn't it be cool if we could write—

static_assert(__is_trivially_relocatable(boost::container::static_vector<int,10>));
static_assert(!__is_trivially_relocatable(boost::container::static_vector<std::list<int>,10>));

The __is_trivially_relocatable is available only on Clang so far, and the necessary std::is_trivially_relocatable_v/[[trivially_relocatable]] trait/attribute are available only in my fork of Clang/libc++; but both levels of support are detectable via the preprocessor (see Godbolt).

I propose to add an #ifdef so that static_vector and perhaps other containers will be recognized as trivially relocatable whenever the compiler/STL support that notion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions