[libcxx-commits] [libcxx] [libc++] Slightly simplify max_size and add new tests for vector (PR #119990)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jan 30 06:12:43 PST 2025
================
@@ -0,0 +1,106 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <vector>
+
+// size_type max_size() const;
+
+#include <algorithm>
+#include <cassert>
+#include <climits>
+#include <cstdint>
+#include <limits>
+#include <memory>
+#include <type_traits>
+#include <vector>
+
+#include "min_allocator.h"
+#include "sized_allocator.h"
+#include "test_allocator.h"
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 11
+
+template <typename Alloc>
+TEST_CONSTEXPR_CXX20 void test(const std::vector<bool, Alloc>& v) {
+ using Vector = std::vector<bool, Alloc>;
+ using size_type = typename Vector::size_type;
+ using difference_type = typename Vector::difference_type;
+ using storage_type = typename Vector::__storage_type;
----------------
winner245 wrote:
Another reason why this test is not fully portable to other standard implementations is that libc++, libstdc++, and MSVC-STL all use different word types for vector<bool> underlying storage:
| Compiler | Size Type |
|------------|--------------------------------|
| MSVC | `unsigned int` (fixed) |
| libstdc++ | `unsigned long` (fixed) |
| libc++ | `alloc_traits::size_type` (configurable through custom allocator) |
https://github.com/llvm/llvm-project/pull/119990
More information about the libcxx-commits
mailing list