boostorg / boostorg/container

Feature request: Make `static_vector` "trivially relocatable" when possible

Open
#258 3 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
127
Forks
126
Avg merge
18h 53m
Merged PRs (30d)
1

Description

It was recently discussed on [the cpplang Slack](https://cpplang.slack.com/archives/C2PQKRWJU/p1699903321902899) 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](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1144r9.html#design-goals) my go-to example was `boost::movelib::unique_ptr`; but in the above discussion it was pointed out that `boost::container::static_vector` 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));
static_assert(!__is_trivially_relocatable(boost::container::static_vector,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++](https://godbolt.org/z/ExaKc7q35); but both levels of support are detectable via the preprocessor ([see Godbolt](https://godbolt.org/z/ExaKc7q35)).

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.