[libcxx-commits] [PATCH] D127418: [libc++] Use bounded iterators in std::span when the debug mode is enabled

Nikolas Klauser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 9 11:48:31 PDT 2022

philnik added a comment.

> This approach has the benefit that we don't need to modify the container (`std::span`) at all, unlike with the usual `__wrap_iter` and `__debug_insert_c()` methods. It doesn't use a global locking mechanism and the internal debug "database". As a result, `std::span` can stay trivially copyable and trivially destructible, which could be important for the correctness of user programs.

I wouldn't call `std::span` a container.

> On the downside, we also can't track any potential changes to the size of the container. Once an iterator is obtained, the bounds it considers will never change, even if the underlying container could potentially change its bounds. This is not a major issue for `std::span`, however it could potentially be an issue for other containers.

I think this approach is good for views like `std::span` and `std::string_view` and fixed-size containers like `std::array` which are normally (conditionally) trivially copyable. I don't think there is any resizable container which is trivially destructible or copyable, so there it isn't a huge problem that we have to add and remove them from the database. I don't see any problem with having two ways to do two related but still quite different things.

  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list