[libcxx-commits] [libcxx] [libc++] Granularize <vector> (PR #99705)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 23 07:02:37 PDT 2024
================
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___VECTOR_CONTAINER_TRAITS_H
+#define _LIBCPP___VECTOR_CONTAINER_TRAITS_H
+
+#include <__config>
+#include <__fwd/vector.h>
+#include <__memory/allocator_traits.h>
+#include <__type_traits/container_traits.h>
+#include <__type_traits/disjunction.h>
+#include <__type_traits/is_nothrow_constructible.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, class _Allocator>
+struct __container_traits<vector<_Tp, _Allocator> > {
----------------
ldionne wrote:
I am a bit concerned about putting this here separately. Right now, I don't think this gets included anywhere. So if we want to check for `__container_traits<_SomeContainer>` in a generic context (such as from `flat_map`, which is where this trait originated from), we'd currently never get a specialization for `std::vector` AFAICT.
It's kind of weird, but in a certain way I'd imagine that `__vector/vector.h` should perhaps do something like this:
```c++
namespace std {
// define std::vector
}
#include <__vector/swap.h>
#include <__vector/comparison.h>
#include <__vector/container_traits.h>
// etc.
```
And `<__vector/vector_bool.h>` would do similarly:
```
namespace std {
// define std::vector<bool>
}
#include <__vector/swap.h>
#include <__vector/comparison.h>
#include <__vector/container_traits.h>
// etc.
```
That way, you'd be certain to have all the associated operations when you include `<__vector/vector.h>`. I think we have the same issue for `swap`, except it might be more subtle. If you have the wrong includes, you might end up calling the generic `std::swap` which is probably going to compile but is also less efficient.
https://github.com/llvm/llvm-project/pull/99705
More information about the libcxx-commits
mailing list