[libcxx-commits] [libcxx] [libc++] Implement `std::inplace_vector<T, N>` (PR #105981)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Aug 25 04:53:34 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff b6603e1bf11dee4761e49af6581c8b8f074b705d a4127b327df6b05af163d6a58f0f2c8956b1323c --extensions ,h,cpp -- libcxx/include/inplace_vector libcxx/test/std/containers/sequences/inplace.vector/access.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/compare.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/compare.three_way.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/constant_initialization.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/contiguous.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/empy_type.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/capacity.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/empty.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/empty.verify.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/max_size.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/reserve.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size_value.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/shrink_to_fit.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/size.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_copy.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_copy.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_initializer_list.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_iter_iter.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_move.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_move.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_size_value.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_default.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_from_range.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_iter_iter.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_size.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_size_value.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/copy.move_only.verify.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/copy.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/deduct.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/default.recursive.empty.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/default.recursive.fail.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/default_noexcept.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/dtor_noexcept.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/exceptions.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/initializer_list.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/move.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/move.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/move_assign_noexcept.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/move_noexcept.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/op_equal_initializer_list.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data_const.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/iterator_concept_conformance.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/iterators.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/range_concept_conformance.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/reverse_iterators.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/types.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.erasure/erase.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.erasure/erase_if.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/append_range.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/assert.push_back.invalidation.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/assign_range.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/clear.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/destroy_elements.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/emplace.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/emplace.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/emplace_back.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/emplace_extra.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/erase_iter.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/erase_iter.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/erase_iter_iter.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/erase_iter_iter.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_initializer_list.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_iter_iter.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_iter_iter.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_lvalue.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_rvalue.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_size_value.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_size_value.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_iter_value.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/insert_range.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/pop_back.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/push_back.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/push_back_exception_safety.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/push_back_rvalue.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/resize_not_move_insertable.verify.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/swap.addressof.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/swap.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/swap_noexcept.compile.pass.cpp libcxx/test/std/containers/sequences/inplace.vector/vector.special/swap.pass.cpp libcxx/test/std/language.support/support.limits/support.limits.general/inplace_vector.version.compile.pass.cpp libcxx/include/__configuration/abi.h libcxx/include/__iterator/wrap_iter.h libcxx/include/version libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/inplace_vector b/libcxx/include/inplace_vector
index 0667337119..11631fd540 100644
--- a/libcxx/include/inplace_vector
+++ b/libcxx/include/inplace_vector
@@ -208,11 +208,14 @@ class _LIBCPP_TEMPLATE_VIS inplace_vector;
template <size_t _RequiredAlign, size_t _Capacity>
_LIBCPP_HIDE_FROM_ABI auto __inplace_vector_size_type() {
- if constexpr (_Capacity <= static_cast<unsigned char>(-1) && alignof(unsigned char) >= _RequiredAlign && alignof(unsigned char) < alignof(size_t)) {
+ if constexpr (_Capacity <= static_cast<unsigned char>(-1) && alignof(unsigned char) >= _RequiredAlign &&
+ alignof(unsigned char) < alignof(size_t)) {
return static_cast<unsigned char>(0);
- } else if constexpr (_Capacity <= static_cast<unsigned short>(-1) && alignof(unsigned short) >= _RequiredAlign && alignof(unsigned char) < alignof(size_t)) {
+ } else if constexpr (_Capacity <= static_cast<unsigned short>(-1) && alignof(unsigned short) >= _RequiredAlign &&
+ alignof(unsigned char) < alignof(size_t)) {
return static_cast<unsigned short>(0);
- } else if constexpr (_Capacity <= static_cast<unsigned int>(-1) && alignof(unsigned int) >= _RequiredAlign && alignof(unsigned int) < alignof(size_t)) {
+ } else if constexpr (_Capacity <= static_cast<unsigned int>(-1) && alignof(unsigned int) >= _RequiredAlign &&
+ alignof(unsigned int) < alignof(size_t)) {
return static_cast<unsigned int>(0);
} else {
return static_cast<size_t>(0);
@@ -240,42 +243,58 @@ class _LIBCPP_TEMPLATE_VIS __inplace_vector_array {
static constexpr bool __constexpr = is_trivially_default_constructible_v<_Tp> && is_trivially_destructible_v<_Tp>;
static constexpr bool __trivial_copy_construct = is_trivially_copy_constructible_v<_Tp>;
static constexpr bool __trivial_move_construct = is_trivially_move_constructible_v<_Tp>;
- static constexpr bool __trivial_copy_assign = is_trivially_destructible_v<_Tp> && is_trivially_copy_constructible_v<_Tp> && is_trivially_copy_assignable_v<_Tp>;
- static constexpr bool __trivial_move_assign = is_trivially_destructible_v<_Tp> && is_trivially_move_constructible_v<_Tp> && is_trivially_move_assignable_v<_Tp>;
+ static constexpr bool __trivial_copy_assign =
+ is_trivially_destructible_v<_Tp> && is_trivially_copy_constructible_v<_Tp> && is_trivially_copy_assignable_v<_Tp>;
+ static constexpr bool __trivial_move_assign =
+ is_trivially_destructible_v<_Tp> && is_trivially_move_constructible_v<_Tp> && is_trivially_move_assignable_v<_Tp>;
constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array() noexcept : __sz_(0) {
if consteval {
- extern _LIBCPP_HIDE_FROM_ABI void __this_inplace_vector_cannot_be_used_in_a_constant_expression_because_the_type_is_not_trivial();
+ extern _LIBCPP_HIDE_FROM_ABI void
+ __this_inplace_vector_cannot_be_used_in_a_constant_expression_because_the_type_is_not_trivial();
__this_inplace_vector_cannot_be_used_in_a_constant_expression_because_the_type_is_not_trivial();
}
// Start the lifetime of the array without starting the lifetime
// of any of its elements
// TODO: When start_lifetime_as is implemented on all compilers, remove
// this conditional
-#ifdef __cpp_lib_start_lifetime_as
+# ifdef __cpp_lib_start_lifetime_as
std::start_lifetime_as<_Tp[_Capacity]>(__elems_);
-#else
+# else
::new (std::__voidify(__elems_)) unsigned char[sizeof(_Tp[_Capacity])];
-#endif
+# endif
}
- constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array() noexcept requires(__constexpr) : __elems_(), __sz_(0) {
+ constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array() noexcept
+ requires(__constexpr)
+ : __elems_(), __sz_(0) {
if !consteval {
std::destroy(__elems_, __elems_ + _Capacity);
}
}
- constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array(const __inplace_vector_array&) noexcept /* strengthened */ requires(__trivial_copy_construct) = default;
- constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array(__inplace_vector_array&&) noexcept /* strengthened */ requires(__trivial_move_construct) = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array(const __inplace_vector_array&) noexcept /* strengthened */
+ requires(__trivial_copy_construct)
+ = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array(__inplace_vector_array&&) noexcept /* strengthened */
+ requires(__trivial_move_construct)
+ = default;
constexpr _LIBCPP_HIDE_FROM_ABI ~__inplace_vector_array() {
__sz_ = 0;
std::destroy(__elems_, __elems_ + __sz_);
}
- constexpr _LIBCPP_HIDE_FROM_ABI ~__inplace_vector_array() requires(is_trivially_destructible_v<_Tp>) = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI ~__inplace_vector_array()
+ requires(is_trivially_destructible_v<_Tp>)
+ = default;
- constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array& operator=(const __inplace_vector_array&) noexcept requires(__trivial_copy_assign) = default;
- constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array& operator=(__inplace_vector_array&&) noexcept requires(__trivial_move_assign) = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array& operator=(const __inplace_vector_array&) noexcept
+ requires(__trivial_copy_assign)
+ = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array& operator=(__inplace_vector_array&&) noexcept
+ requires(__trivial_move_assign)
+ = default;
- using __trivially_relocatable = __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, inplace_vector<_Tp, _Capacity>, void>;
+ using __trivially_relocatable =
+ __conditional_t<__libcpp_is_trivially_relocatable<_Tp>::value, inplace_vector<_Tp, _Capacity>, void>;
};
template <class _Tp>
@@ -284,28 +303,28 @@ private:
friend inplace_vector<_Tp, 0>;
using __small_size_type = size_t;
- static constexpr bool __constexpr = true;
+ static constexpr bool __constexpr = true;
static constexpr bool __trivial_copy_construct = true;
static constexpr bool __trivial_move_construct = true;
- static constexpr bool __trivial_copy_assign = true;
- static constexpr bool __trivial_move_assign = true;
+ static constexpr bool __trivial_copy_assign = true;
+ static constexpr bool __trivial_move_assign = true;
- static_assert((static_cast<_Tp(*)[1]>(nullptr) == nullptr), "inplace_vector<T, 0> must still have a valid T");
- static constexpr _Tp* __elems_ = nullptr;
+ static_assert((static_cast<_Tp (*)[1]>(nullptr) == nullptr), "inplace_vector<T, 0> must still have a valid T");
+ static constexpr _Tp* __elems_ = nullptr;
static constexpr __small_size_type __sz_ = 0;
constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array() noexcept = default;
- constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array(const __inplace_vector_array&) noexcept /* strengthened */ = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array(const __inplace_vector_array&) noexcept /* strengthened */ =
+ default;
constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array(__inplace_vector_array&&) noexcept = default;
- constexpr _LIBCPP_HIDE_FROM_ABI ~__inplace_vector_array() = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI ~__inplace_vector_array() = default;
constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array& operator=(const __inplace_vector_array&) noexcept = default;
- constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array& operator=(__inplace_vector_array&&) noexcept = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI __inplace_vector_array& operator=(__inplace_vector_array&&) noexcept = default;
using __trivially_relocatable = inplace_vector<_Tp, 0>;
};
-
template <class _Tp, size_t _Capacity>
class _LIBCPP_TEMPLATE_VIS inplace_vector : private __inplace_vector_array<_Tp, _Capacity> {
using __base = __inplace_vector_array<_Tp, _Capacity>;
@@ -319,23 +338,24 @@ class _LIBCPP_TEMPLATE_VIS inplace_vector : private __inplace_vector_array<_Tp,
}
return true;
}
+
public:
// types
- using value_type = _Tp;
- using pointer = _Tp*;
- using const_pointer = const _Tp*;
- using reference = value_type&;
+ using value_type = _Tp;
+ using pointer = _Tp*;
+ using const_pointer = const _Tp*;
+ using reference = value_type&;
using const_reference = const value_type&;
- using size_type = size_t;
+ using size_type = size_t;
using difference_type = ptrdiff_t;
-#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
- using iterator = __bounded_iter<pointer>;
+# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
+ using iterator = __bounded_iter<pointer>;
using const_iterator = __bounded_iter<const_pointer>;
-#else
- using iterator = __wrap_iter<pointer>;
+# else
+ using iterator = __wrap_iter<pointer>;
using const_iterator = __wrap_iter<const_pointer>;
-#endif
- using reverse_iterator = std::reverse_iterator<iterator>;
+# endif
+ using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using __trivially_relocatable = __base::__trivially_relocatable;
@@ -365,7 +385,8 @@ public:
// NOTE: [sequence.reqmts]p(67.1) does not apply to this constructor but apply
// it anyways so the (size_type, const T&) constructor can never be ambiguous
- template<class _InputIterator> requires(__has_input_iterator_category<_InputIterator>::value)
+ template <class _InputIterator>
+ requires(__has_input_iterator_category<_InputIterator>::value)
constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(_InputIterator __first, _InputIterator __last) : inplace_vector() {
if constexpr (__has_forward_iterator_category<_InputIterator>::value) {
__append_with_size(__first, __last, std::distance(__first, __last));
@@ -373,33 +394,47 @@ public:
}
__append_with_sentinel(__first, __last);
}
- template<_ContainerCompatibleRange<_Tp> _R>
+ template <_ContainerCompatibleRange<_Tp> _R>
constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(from_range_t, _R&& __rg) : inplace_vector() {
append_range<true>(__rg);
}
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(const inplace_vector& __other) noexcept(is_nothrow_copy_constructible_v<_Tp>) /* strengthened */ : inplace_vector() {
+ constexpr _LIBCPP_HIDE_FROM_ABI
+ inplace_vector(const inplace_vector& __other) noexcept(is_nothrow_copy_constructible_v<_Tp>) /* strengthened */
+ : inplace_vector() {
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(this != std::addressof(__other), "inplace_vector self-assign");
__small_size_type __expected_size = __other.__sz_;
for (__small_size_type __i = 0; __i < __expected_size; ++__i) {
unchecked_push_back(__other.data()[__i]);
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__sz_ == __expected_size, "inplace_vector modified before it's lifetime began");
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__other.__sz_ == __expected_size, "inplace_vector modified while it's being copied from");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __sz_ == __expected_size, "inplace_vector modified before it's lifetime began");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __other.__sz_ == __expected_size, "inplace_vector modified while it's being copied from");
}
}
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(const inplace_vector&) noexcept /* strengthened */ requires(__base::__trivial_copy_construct) = default;
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(inplace_vector&& __other) noexcept(is_nothrow_move_constructible_v<_Tp>) /* strengthened */ : inplace_vector() {
+ constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(const inplace_vector&) noexcept /* strengthened */
+ requires(__base::__trivial_copy_construct)
+ = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI
+ inplace_vector(inplace_vector&& __other) noexcept(is_nothrow_move_constructible_v<_Tp>) /* strengthened */
+ : inplace_vector() {
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(this != std::addressof(__other), "inplace_vector self-assign");
__small_size_type __expected_size = __other.__sz_;
for (__small_size_type __i = 0; __i < __expected_size; ++__i) {
unchecked_push_back(std::move(__other.data()[__i]));
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__sz_ == __expected_size, "inplace_vector modified before it's lifetime began");
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__other.__sz_ == __expected_size, "inplace_vector modified while it's being copied from");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __sz_ == __expected_size, "inplace_vector modified before it's lifetime began");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __other.__sz_ == __expected_size, "inplace_vector modified while it's being copied from");
}
}
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(inplace_vector&&) noexcept /* strengthened */ requires(__base::__trivial_move_construct) = default;
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(initializer_list<_Tp> __il) : inplace_vector(__il.begin(), __il.end()) {}
+ constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(inplace_vector&&) noexcept /* strengthened */
+ requires(__base::__trivial_move_construct)
+ = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector(initializer_list<_Tp> __il)
+ : inplace_vector(__il.begin(), __il.end()) {}
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector& operator=(const inplace_vector& __other) noexcept(is_nothrow_copy_assignable_v<_Tp> && is_nothrow_copy_constructible_v<_Tp>) /* strengthened */ {
+ constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector& operator=(const inplace_vector& __other) noexcept(
+ is_nothrow_copy_assignable_v<_Tp> && is_nothrow_copy_constructible_v<_Tp>) /* strengthened */ {
static_assert(_Capacity != 0, "Should have picked the trivial operator");
if (this != std::addressof(__other)) [[likely]] {
__small_size_type __assign = std::min(size(), __other.size());
@@ -412,31 +447,38 @@ public:
}
return *this;
}
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector& operator=(const inplace_vector&) noexcept /* strengthened */ requires(__base::__trivial_copy_assign) = default;
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector& operator=(inplace_vector&& __other) noexcept(is_nothrow_move_assignable_v<_Tp> && is_nothrow_move_constructible_v<_Tp>) {
+ constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector& operator=(const inplace_vector&) noexcept /* strengthened */
+ requires(__base::__trivial_copy_assign)
+ = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector& operator=(inplace_vector&& __other) noexcept(
+ is_nothrow_move_assignable_v<_Tp> && is_nothrow_move_constructible_v<_Tp>) {
static_assert(_Capacity != 0, "Should have picked the trivial operator");
if (this != std::addressof(__other)) [[likely]] {
__small_size_type __assign = std::min(size(), __other.size());
std::move(__other.data(), __other.data() + __assign, data());
if (__other.size() > size()) {
- __append_with_size(std::make_move_iterator(__other.data() + __assign), std::make_move_iterator(__other.data() + __other.size()), __other.size() - __assign);
+ __append_with_size(std::make_move_iterator(__other.data() + __assign),
+ std::make_move_iterator(__other.data() + __other.size()),
+ __other.size() - __assign);
} else {
__resize_down(__other.size());
}
}
return *this;
}
- constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector& operator=(inplace_vector&&) noexcept /* strengthened */ requires(__base::__trivial_move_assign) = default;
+ constexpr _LIBCPP_HIDE_FROM_ABI inplace_vector& operator=(inplace_vector&&) noexcept /* strengthened */
+ requires(__base::__trivial_move_assign)
+ = default;
constexpr _LIBCPP_HIDE_FROM_ABI ~inplace_vector() = default;
private:
constexpr _LIBCPP_HIDE_FROM_ABI iterator __make_iter(pointer __p) const noexcept {
-#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
+# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
return std::__make_bounded_iter(__p, __elems_ + 0, __elems_ + __sz_);
-#else
+# else
return iterator(__p);
-#endif
+# endif
}
constexpr _LIBCPP_HIDE_FROM_ABI const_iterator __make_iter(const_pointer __p) const noexcept {
@@ -452,13 +494,14 @@ private:
__append_with_size(std::forward<_First>(__first), std::forward<_Sent>(__sent), __n);
return;
}
- const size_t __initial_size = size();
+ const size_t __initial_size = size();
const size_t __assigned_elems = std::min(__initial_size, __n);
- const size_t __remaining = __n - __assigned_elems;
+ const size_t __remaining = __n - __assigned_elems;
for (size_t __i = 0; __i < __assigned_elems; ++__i) {
data()[__i] = *__first;
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__first != __sent, "Iterators modified during assignment or size was wrong");
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(size() == __initial_size, "Iterator or assignment modified container size during assign");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ size() == __initial_size, "Iterator or assignment modified container size during assign");
++__first;
}
__append_with_size(std::forward<_First>(__first), std::forward<_Sent>(__sent), __remaining);
@@ -473,16 +516,20 @@ private:
}
size_t __existing = __sz_;
for (size_t __i = 0; __i < __existing; ++__i) {
- if (__first == __sent) return;
+ if (__first == __sent)
+ return;
data()[__i] = *__first;
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__first != __sent, "Iterators modified during assignment");
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__existing + __i == __sz_, "Iterator or assignment modified container size during assign");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __existing + __i == __sz_, "Iterator or assignment modified container size during assign");
++__first;
}
__append_with_sentinel(std::forward<_First>(__first), std::forward<_Sent>(__sent));
}
+
public:
- template <class _InputIterator> requires(__has_input_iterator_category<_InputIterator>::value)
+ template <class _InputIterator>
+ requires(__has_input_iterator_category<_InputIterator>::value)
constexpr _LIBCPP_HIDE_FROM_ABI void assign(_InputIterator __first, _InputIterator __last) {
if constexpr (__has_forward_iterator_category<_InputIterator>::value) {
__assign_with_size(__first, __last, std::distance(__first, __last));
@@ -507,7 +554,7 @@ public:
if constexpr (is_trivially_copyable_v<_Tp>) {
clear();
} else {
- const size_t __initial_size = size();
+ const size_t __initial_size = size();
const size_t __assigned_elems = std::min(__initial_size, __n);
for (size_t __i = 0; __i < __assigned_elems; ++__i) {
data()[__i] = __u;
@@ -517,39 +564,35 @@ public:
}
resize(__n, __u);
}
- constexpr _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<_Tp> __il) {
- assign(__il.begin(), __il.end());
- }
+ constexpr _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<_Tp> __il) { assign(__il.begin(), __il.end()); }
// iterators
- constexpr _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept { return __make_iter(data()); }
- constexpr _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return __make_iter(data()); }
- constexpr _LIBCPP_HIDE_FROM_ABI iterator end() noexcept { return __make_iter(data() + size()); }
- constexpr _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return __make_iter(data() + size()); }
- constexpr _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
- constexpr _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
- constexpr _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
- constexpr _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
-
- constexpr _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return begin(); }
- constexpr _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return end(); }
+ constexpr _LIBCPP_HIDE_FROM_ABI iterator begin() noexcept { return __make_iter(data()); }
+ constexpr _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return __make_iter(data()); }
+ constexpr _LIBCPP_HIDE_FROM_ABI iterator end() noexcept { return __make_iter(data() + size()); }
+ constexpr _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return __make_iter(data() + size()); }
+ constexpr _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
+ constexpr _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const noexcept {
+ return const_reverse_iterator(end());
+ }
+ constexpr _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
+ constexpr _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const noexcept {
+ return const_reverse_iterator(begin());
+ }
+
+ constexpr _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return begin(); }
+ constexpr _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return end(); }
constexpr _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const noexcept { return rbegin(); }
- constexpr _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept { return rend(); }
+ constexpr _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const noexcept { return rend(); }
// [inplace.vector.capacity] size/capacity
- _LIBCPP_NODISCARD constexpr _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept {
- return __sz_ == 0;
- }
+ _LIBCPP_NODISCARD constexpr _LIBCPP_HIDE_FROM_ABI bool empty() const noexcept { return __sz_ == 0; }
_LIBCPP_NODISCARD constexpr _LIBCPP_HIDE_FROM_ABI size_type size() const noexcept {
_LIBCPP_ASSERT_INTERNAL(__sz_ <= capacity(), "inplace_vector has impossible size");
return __sz_;
}
- _LIBCPP_NODISCARD static _LIBCPP_HIDE_FROM_ABI constexpr size_type max_size() noexcept {
- return _Capacity;
- }
- _LIBCPP_NODISCARD static _LIBCPP_HIDE_FROM_ABI constexpr size_type capacity() noexcept {
- return _Capacity;
- }
+ _LIBCPP_NODISCARD static _LIBCPP_HIDE_FROM_ABI constexpr size_type max_size() noexcept { return _Capacity; }
+ _LIBCPP_NODISCARD static _LIBCPP_HIDE_FROM_ABI constexpr size_type capacity() noexcept { return _Capacity; }
private:
constexpr _LIBCPP_HIDE_FROM_ABI void __resize_down(__small_size_type __n) noexcept {
@@ -573,20 +616,18 @@ private:
__resize_down(__n);
} else {
[[maybe_unused]] const pointer __current_end = __elems_ + __sz_;
- size_type __remaining = __n - __sz_;
+ size_type __remaining = __n - __sz_;
for (size_type __i = 0; __i < __remaining; ++__i) {
unchecked_emplace_back(__arg...);
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__current_end + __i == __elems_ + __sz_, "inplace_vector simultaneously modified during resize");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __current_end + __i == __elems_ + __sz_, "inplace_vector simultaneously modified during resize");
}
}
}
+
public:
- constexpr _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz) {
- __resize(__sz);
- }
- constexpr _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const _Tp& __u) {
- __resize(__sz, __u);
- }
+ constexpr _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz) { __resize(__sz); }
+ constexpr _LIBCPP_HIDE_FROM_ABI void resize(size_type __sz, const _Tp& __u) { __resize(__sz, __u); }
static constexpr _LIBCPP_HIDE_FROM_ABI void reserve(size_type __n) {
if (__n > capacity())
@@ -631,7 +672,7 @@ public:
}
// [inplace.vector.daa], data access
- constexpr _LIBCPP_HIDE_FROM_ABI _Tp* data() noexcept { return __elems_; }
+ constexpr _LIBCPP_HIDE_FROM_ABI _Tp* data() noexcept { return __elems_; }
constexpr _LIBCPP_HIDE_FROM_ABI const _Tp* data() const noexcept { return __elems_; }
private:
@@ -662,12 +703,12 @@ private:
return !noexcept(_Tp(*declval<_It>()));
}
- template<class _It, class _Sent>
- constexpr _LIBCPP_HIDE_FROM_ABI void __append_with_size(_It&& __first, [[maybe_unused]] _Sent&& __last, size_type __n) {
+ template <class _It, class _Sent>
+ constexpr _LIBCPP_HIDE_FROM_ABI void
+ __append_with_size(_It&& __first, [[maybe_unused]] _Sent&& __last, size_type __n) {
[[maybe_unused]] __small_size_type __expected_size = size();
while (__n--) {
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
- __first != __last, "Iterators modified during assignment or size was wrong");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__first != __last, "Iterators modified during assignment or size was wrong");
unchecked_emplace_back(*__first);
++__first;
@@ -677,11 +718,11 @@ private:
}
}
- template<bool _ThrowOnMissingCapacity = true, class _It, class _Sent>
+ template <bool _ThrowOnMissingCapacity = true, class _It, class _Sent>
constexpr _LIBCPP_HIDE_FROM_ABI void __append_with_sentinel(_It&& __it, _Sent&& __last) {
- const __small_size_type __initial_size = __sz_;
+ const __small_size_type __initial_size = __sz_;
[[maybe_unused]] __small_size_type __expected_size = __sz_;
- pointer __p = __elems_ + __initial_size;
+ pointer __p = __elems_ + __initial_size;
while (__p != __elems_ + capacity()) {
if (__it == __last)
return;
@@ -696,7 +737,8 @@ private:
__sz_ == __expected_size, "iterator operation modified container size during append");
}
if constexpr (_ThrowOnMissingCapacity) {
- if (__it == __last) return;
+ if (__it == __last)
+ return;
// Exception safety: container must not be changed afterwards
__resize_down(__initial_size);
@@ -754,32 +796,39 @@ public:
[[maybe_unused]] __small_size_type __expected_size = --__sz_;
if (__do_destroy())
std::destroy_at(__elems_ + __sz_ - 1);
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__sz_ == __expected_size, "inplace_vector modified during element destruction");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __sz_ == __expected_size, "inplace_vector modified during element destruction");
} else {
__libcpp_unreachable();
}
}
- template<class... _Args>
+ template <class... _Args>
constexpr _LIBCPP_HIDE_FROM_ABI pointer try_emplace_back(_Args&&... __args) noexcept /* strengthened */ {
if (size() == capacity())
return nullptr;
return std::addressof(unchecked_emplace_back(std::forward<_Args>(__args)...));
}
- constexpr _LIBCPP_HIDE_FROM_ABI pointer try_push_back(const _Tp& __x) noexcept /* strengthened */ { return try_emplace_back(__x); }
- constexpr _LIBCPP_HIDE_FROM_ABI pointer try_push_back(_Tp&& __x) noexcept /* strengthened */ { return try_emplace_back(std::move(__x)); }
- template<_ContainerCompatibleRange<_Tp> _R>
+ constexpr _LIBCPP_HIDE_FROM_ABI pointer try_push_back(const _Tp& __x) noexcept /* strengthened */ {
+ return try_emplace_back(__x);
+ }
+ constexpr _LIBCPP_HIDE_FROM_ABI pointer try_push_back(_Tp&& __x) noexcept /* strengthened */ {
+ return try_emplace_back(std::move(__x));
+ }
+ template <_ContainerCompatibleRange<_Tp> _R>
constexpr _LIBCPP_HIDE_FROM_ABI ranges::borrowed_iterator_t<_R> try_append_range(_R&& __rg) {
return __append_range<false>(std::forward<_R>(__rg));
}
template <class... _Args>
- constexpr _LIBCPP_HIDE_FROM_ABI reference unchecked_emplace_back(_Args&&... __args) noexcept(std::is_nothrow_constructible_v<_Tp, _Args...>) /* strengthened */ {
- _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(size() < capacity(), "unchecked_emplace_back() called on an at-capacity inplace_vector");
+ constexpr _LIBCPP_HIDE_FROM_ABI reference unchecked_emplace_back(_Args&&... __args) noexcept(
+ std::is_nothrow_constructible_v<_Tp, _Args...>) /* strengthened */ {
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
+ size() < capacity(), "unchecked_emplace_back() called on an at-capacity inplace_vector");
if constexpr (_Capacity == 0) {
__libcpp_unreachable();
}
- pointer __new = data() + size();
+ pointer __new = data() + size();
[[maybe_unused]] size_t __old_size = __sz_;
std::construct_at(__new, std::forward<_Args>(__args)...);
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__sz_ == __old_size, "inplace_vector modified during element construction");
@@ -788,8 +837,14 @@ public:
}
return *__new;
}
- constexpr _LIBCPP_HIDE_FROM_ABI reference unchecked_push_back(const _Tp& __x) noexcept(std::is_nothrow_copy_constructible_v<_Tp>) /* strengthened */ { return unchecked_emplace_back(__x); }
- constexpr _LIBCPP_HIDE_FROM_ABI reference unchecked_push_back(_Tp&& __x) noexcept(std::is_nothrow_move_constructible_v<_Tp>) /* strengthened */ { return unchecked_emplace_back(std::move(__x)); }
+ constexpr _LIBCPP_HIDE_FROM_ABI reference
+ unchecked_push_back(const _Tp& __x) noexcept(std::is_nothrow_copy_constructible_v<_Tp>) /* strengthened */ {
+ return unchecked_emplace_back(__x);
+ }
+ constexpr _LIBCPP_HIDE_FROM_ABI reference
+ unchecked_push_back(_Tp&& __x) noexcept(std::is_nothrow_move_constructible_v<_Tp>) /* strengthened */ {
+ return unchecked_emplace_back(std::move(__x));
+ }
private:
constexpr _LIBCPP_HIDE_FROM_ABI pointer __unwrap_iter(const_iterator __it) noexcept {
@@ -806,6 +861,7 @@ private:
}
return __p;
}
+
public:
template <class... _Args>
constexpr _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __position, _Args&&... __args) {
@@ -855,9 +911,11 @@ public:
}
return __make_iter(__p);
}
+
private:
template <class _Iterator, class _Sentinel, class _Size>
- constexpr _LIBCPP_HIDE_FROM_ABI iterator __insert_with_size(const_iterator __position, _Iterator&& __it, _Sentinel&& __sent, _Size __m) {
+ constexpr _LIBCPP_HIDE_FROM_ABI iterator
+ __insert_with_size(const_iterator __position, _Iterator&& __it, _Sentinel&& __sent, _Size __m) {
const pointer __p = __unwrap_iter(__position);
if (std::cmp_greater(__m, capacity() - size()))
__throw_bad_alloc();
@@ -887,7 +945,8 @@ private:
std::destroy_at(__p + __i);
__deref_construct_at(__p + __i, __it);
}
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__sz_ == __expected_size, "inplace_vector modified during element construction/destruction");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(
+ __sz_ == __expected_size, "inplace_vector modified during element construction/destruction");
++__it;
_LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__sz_ == __expected_size, "inplace_vector modified by iterator operation");
}
@@ -899,7 +958,8 @@ private:
}
template <class _Iterator, class _Sentinel>
- constexpr _LIBCPP_HIDE_FROM_ABI iterator __insert_with_sentinel(const_iterator __position, _Iterator&& __it, _Sentinel&& __sent) {
+ constexpr _LIBCPP_HIDE_FROM_ABI iterator
+ __insert_with_sentinel(const_iterator __position, _Iterator&& __it, _Sentinel&& __sent) {
const pointer __p = __unwrap_iter(__position);
if (__p == __elems_ + __sz_) {
@@ -911,9 +971,12 @@ private:
}
return __make_iter(__p);
}
+
public:
- template <class _InputIterator> requires(__has_input_iterator_category<_InputIterator>::value)
- constexpr _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
+ template <class _InputIterator>
+ requires(__has_input_iterator_category<_InputIterator>::value)
+ constexpr _LIBCPP_HIDE_FROM_ABI iterator
+ insert(const_iterator __position, _InputIterator __first, _InputIterator __last) {
if constexpr (__has_forward_iterator_category<_InputIterator>::value) {
return __insert_with_size(__position, __first, __last, std::distance(__first, __last));
}
@@ -947,22 +1010,24 @@ public:
__resize_down(__q - __elems_);
}
- constexpr _LIBCPP_HIDE_FROM_ABI void swap(inplace_vector& __x) noexcept(_Capacity == 0 || (is_nothrow_swappable_v<_Tp> &&
- is_nothrow_move_constructible_v<_Tp>)) {
- inplace_vector* __smaller = this;
- inplace_vector* __bigger = std::addressof(__x);
+ constexpr _LIBCPP_HIDE_FROM_ABI void swap(inplace_vector& __x) noexcept(
+ _Capacity == 0 || (is_nothrow_swappable_v<_Tp> && is_nothrow_move_constructible_v<_Tp>)) {
+ inplace_vector* __smaller = this;
+ inplace_vector* __bigger = std::addressof(__x);
__small_size_type __smaller_size = __smaller->__sz_;
- __small_size_type __bigger_size = __bigger->__sz_;
+ __small_size_type __bigger_size = __bigger->__sz_;
if (__smaller_size > __bigger_size) {
std::swap(__smaller, __bigger);
std::swap(__smaller_size, __bigger_size);
}
std::swap_ranges(+__smaller->__elems_, __smaller->__elems_ + __smaller_size, +__bigger->__elems_);
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__smaller->__sz_ == __smaller_size && __bigger->__sz_ == __bigger_size, "inplace_vector modified when swapping elements");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__smaller->__sz_ == __smaller_size && __bigger->__sz_ == __bigger_size,
+ "inplace_vector modified when swapping elements");
for (__small_size_type __i = __smaller_size; __i != __bigger_size; ++__i) {
unchecked_push_back(std::move(__bigger->data()[__i++]));
- _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__smaller->__sz_ == __i && __bigger->__sz_ == __bigger_size, "inplace_vector modified when swapping elements");
+ _LIBCPP_ASSERT_SEMANTIC_REQUIREMENT(__smaller->__sz_ == __i && __bigger->__sz_ == __bigger_size,
+ "inplace_vector modified when swapping elements");
}
__bigger->__resize_down(__smaller_size);
}
@@ -983,32 +1048,36 @@ public:
return std::equal(__x.data(), __x.data() + __sz, __y.data());
}
// Return type is a placeholder type because __synth_three_way_result<_Tp> is a hard error if the constraint isn't met
- friend constexpr _LIBCPP_HIDE_FROM_ABI auto operator<=>(const inplace_vector& __x, const inplace_vector& __y) requires(requires(const _Tp& __t) { __t < __t; }) {
- return std::lexicographical_compare_three_way(__x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size(), std::__synth_three_way);
+ friend constexpr _LIBCPP_HIDE_FROM_ABI auto operator<=>(const inplace_vector& __x, const inplace_vector& __y)
+ requires(requires(const _Tp& __t) { __t < __t; })
+ {
+ return std::lexicographical_compare_three_way(
+ __x.data(), __x.data() + __x.size(), __y.data(), __y.data() + __y.size(), std::__synth_three_way);
}
- constexpr friend _LIBCPP_HIDE_FROM_ABI void swap(inplace_vector& __x, inplace_vector& __y)
- noexcept(_Capacity == 0 || (is_nothrow_swappable_v<_Tp> &&
- is_nothrow_move_constructible_v<_Tp>))
- { __x.swap(__y); }
+ constexpr friend _LIBCPP_HIDE_FROM_ABI void swap(inplace_vector& __x, inplace_vector& __y) noexcept(
+ _Capacity == 0 || (is_nothrow_swappable_v<_Tp> && is_nothrow_move_constructible_v<_Tp>)) {
+ __x.swap(__y);
+ }
};
template <class _Tp, size_t _Capacity, class _Up>
constexpr _LIBCPP_HIDE_FROM_ABI size_t erase(inplace_vector<_Tp, _Capacity>& __c, const _Up& __value) noexcept(
- std::is_nothrow_move_assignable_v<_Tp> && noexcept(static_cast<bool>(__value == __value)) // strengthened
+ std::is_nothrow_move_assignable_v<_Tp> && noexcept(static_cast<bool>(__value == __value)) // strengthened
) {
auto __it = std::remove(__c.begin(), __c.end(), __value);
- auto __r = __c.end() - __it;
+ auto __r = __c.end() - __it;
__c.erase(__it, __c.end());
return __r;
}
template <class _Tp, size_t _Capacity, class _Predicate>
constexpr _LIBCPP_HIDE_FROM_ABI size_t erase_if(inplace_vector<_Tp, _Capacity>& __c, _Predicate __pred) noexcept(
- std::is_nothrow_move_assignable_v<_Tp> && noexcept(remove_cvref_t<_Predicate>(__pred)) && noexcept(static_cast<bool>(!declval<remove_cvref_t<_Predicate>&>()(declval<_Tp&>()))) // strengthened
+ std::is_nothrow_move_assignable_v<_Tp> && noexcept(remove_cvref_t<_Predicate>(__pred)) &&
+ noexcept(static_cast<bool>(!declval<remove_cvref_t<_Predicate>&>()(declval<_Tp&>()))) // strengthened
) {
auto __it = std::remove_if(__c.cbegin(), __c.cend(), __pred);
- auto __r = __c.end() - __it;
+ auto __r = __c.end() - __it;
__c.erase(__it, __c.end());
return __r;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/access.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/access.pass.cpp
index 0190008855..cca413104a 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/access.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/access.pass.cpp
@@ -46,14 +46,13 @@ TEST_CONSTEXPR_CXX20 void test_get_basic(Vector& c, int start_value) {
assert(c.at(i) == start_value + i);
#ifndef TEST_HAS_NO_EXCEPTIONS
- if
- !consteval {
- try {
- TEST_IGNORE_NODISCARD c.at(n);
- assert(false);
- } catch (const std::out_of_range&) {
- }
+ if !consteval {
+ try {
+ TEST_IGNORE_NODISCARD c.at(n);
+ assert(false);
+ } catch (const std::out_of_range&) {
}
+ }
#endif
assert(c.front() == start_value);
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/constant_initialization.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/constant_initialization.pass.cpp
index 96383c6203..5dc7020fa7 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/constant_initialization.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/constant_initialization.pass.cpp
@@ -20,35 +20,31 @@ struct NonTrivial {
constexpr bool tests() {
{
using V = std::inplace_vector<int, 0>;
- if
- !consteval {
- constinit static V v1;
- assert(v1.size() == 0);
- }
+ if !consteval {
+ constinit static V v1;
+ assert(v1.size() == 0);
+ }
constexpr static V v2;
static_assert(v2.size() == 0);
}
{
using V = std::inplace_vector<int, 10>;
- if
- !consteval {
- constinit static V v1;
- assert(v1.size() == 0);
- }
+ if !consteval {
+ constinit static V v1;
+ assert(v1.size() == 0);
+ }
constexpr static V v2;
static_assert(v2.size() == 0);
}
{
using V = std::inplace_vector<int, 10>;
- if
- !consteval {
- constinit static V v1{1, 2, 3};
- assert(v1.size() == 3);
- assert(v1[0] == 1 && v1[1] == 2 && v1[2] == 3);
- }
+ if !consteval {
+ constinit static V v1{1, 2, 3};
+ assert(v1.size() == 3);
+ assert(v1[0] == 1 && v1[1] == 2 && v1[2] == 3);
+ }
constexpr static V v2{1, 2, 3};
- constexpr static V v3 = [] consteval { return V{1, 2, 3}; }
- ();
+ constexpr static V v3 = [] consteval { return V{1, 2, 3}; }();
static_assert(v2.size() == 3);
static_assert(v3.size() == 3);
static_assert(v2[0] == 1 && v2[1] == 2 && v2[2] == 3);
@@ -56,21 +52,19 @@ constexpr bool tests() {
}
{
using V = std::inplace_vector<NonTrivial, 0>;
- if
- !consteval {
- constinit static V v1;
- assert(v1.size() == 0);
- }
+ if !consteval {
+ constinit static V v1;
+ assert(v1.size() == 0);
+ }
constexpr static V v2;
static_assert(v2.size() == 0);
}
- if
- !consteval {
- using V = std::inplace_vector<NonTrivial, 10>;
- static V v(3);
- assert(v.size() == 3);
- assert(!v[0].constant && !v[1].constant && !v[2].constant);
- }
+ if !consteval {
+ using V = std::inplace_vector<NonTrivial, 10>;
+ static V v(3);
+ assert(v.size() == 3);
+ assert(!v[0].constant && !v[1].constant && !v[2].constant);
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/capacity.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/capacity.pass.cpp
index dbda41ef85..5f00dd1fae 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/capacity.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/capacity.pass.cpp
@@ -34,8 +34,9 @@ constexpr bool tests() {
test<int, 10>();
test<int, 0>();
test<MoveOnly, 0>();
- if
- !consteval { test<MoveOnly, 10>(); }
+ if !consteval {
+ test<MoveOnly, 10>();
+ }
{
extern std::inplace_vector<MoveOnly, 10> v;
assert(v.capacity() == 10);
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/empty.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/empty.pass.cpp
index 8919b3720d..641519c62c 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/empty.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/empty.pass.cpp
@@ -46,17 +46,16 @@ constexpr bool tests() {
// See above
static_assert(v.empty());
}
- if
- !consteval {
- using V = std::inplace_vector<MoveOnly, 10>;
- V v;
- ASSERT_NOEXCEPT(v.empty());
- assert(v.empty());
- v.push_back(V::value_type(1));
- assert(!v.empty());
- v.clear();
- assert(v.empty());
- }
+ if !consteval {
+ using V = std::inplace_vector<MoveOnly, 10>;
+ V v;
+ ASSERT_NOEXCEPT(v.empty());
+ assert(v.empty());
+ v.push_back(V::value_type(1));
+ assert(!v.empty());
+ v.clear();
+ assert(v.empty());
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/max_size.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/max_size.pass.cpp
index 5c6355c1f7..b71210a225 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/max_size.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/max_size.pass.cpp
@@ -34,8 +34,9 @@ constexpr bool tests() {
test<int, 10>();
test<int, 0>();
test<MoveOnly, 0>();
- if
- !consteval { test<MoveOnly, 10>(); }
+ if !consteval {
+ test<MoveOnly, 10>();
+ }
{
extern std::inplace_vector<MoveOnly, 10> v;
assert(v.max_size() == 10);
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/reserve.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/reserve.pass.cpp
index c6b135503e..31081d4c6f 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/reserve.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/reserve.pass.cpp
@@ -26,25 +26,24 @@ constexpr bool tests() {
}
static_assert((v.reserve(0), v.reserve(1), v.reserve(2), v.reserve(8), v.reserve(9), v.reserve(10), true));
static_assert((V::reserve(0), V::reserve(1), V::reserve(2), V::reserve(8), V::reserve(9), V::reserve(10), true));
- if
- !consteval {
+ if !consteval {
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- V::reserve(11);
- assert(false);
- } catch (const std::bad_alloc&) {
- } catch (...) {
- assert(false);
- }
- try {
- V::reserve(-1);
- assert(false);
- } catch (const std::bad_alloc&) {
- } catch (...) {
- assert(false);
- }
-#endif
+ try {
+ V::reserve(11);
+ assert(false);
+ } catch (const std::bad_alloc&) {
+ } catch (...) {
+ assert(false);
+ }
+ try {
+ V::reserve(-1);
+ assert(false);
+ } catch (const std::bad_alloc&) {
+ } catch (...) {
+ assert(false);
}
+#endif
+ }
}
{
using V = std::inplace_vector<int, 0>;
@@ -52,25 +51,24 @@ constexpr bool tests() {
v.reserve(0);
static_assert((v.reserve(0), true));
static_assert((V::reserve(0), true));
- if
- !consteval {
+ if !consteval {
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- V::reserve(1);
- assert(false);
- } catch (const std::bad_alloc&) {
- } catch (...) {
- assert(false);
- }
- try {
- V::reserve(-1);
- assert(false);
- } catch (const std::bad_alloc&) {
- } catch (...) {
- assert(false);
- }
-#endif
+ try {
+ V::reserve(1);
+ assert(false);
+ } catch (const std::bad_alloc&) {
+ } catch (...) {
+ assert(false);
+ }
+ try {
+ V::reserve(-1);
+ assert(false);
+ } catch (const std::bad_alloc&) {
+ } catch (...) {
+ assert(false);
}
+#endif
+ }
}
return true;
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size.pass.cpp
index c0a18c7411..d67fe29862 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size.pass.cpp
@@ -31,14 +31,13 @@ constexpr bool tests() {
assert(i == 0);
}
}
- if
- !consteval {
- std::inplace_vector<MoveOnly, 400> v(100);
- v.resize(50);
- assert(v.size() == 50);
- v.resize(200);
- assert(v.size() == 200);
- }
+ if !consteval {
+ std::inplace_vector<MoveOnly, 400> v(100);
+ v.resize(50);
+ assert(v.size() == 50);
+ v.resize(200);
+ assert(v.size() == 200);
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size_value.pass.cpp
index bab46ec6cc..4cc65dd73c 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size_value.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/resize_size_value.pass.cpp
@@ -46,23 +46,22 @@ constexpr bool tests() {
assert(v[i] == 1);
}
}
- if
- !consteval {
- std::inplace_vector<NonTrivial, 400> v(100);
- v.resize(50, 1);
- assert(v.size() == 50);
- for (int i : v) {
- assert(i == 0);
- }
- v.resize(200, 1);
- assert(v.size() == 200);
- for (int i = 0; i < 50; ++i) {
- assert(v[i] == 0);
- }
- for (int i = 50; i < 200; ++i) {
- assert(v[i] == 1);
- }
+ if !consteval {
+ std::inplace_vector<NonTrivial, 400> v(100);
+ v.resize(50, 1);
+ assert(v.size() == 50);
+ for (int i : v) {
+ assert(i == 0);
}
+ v.resize(200, 1);
+ assert(v.size() == 200);
+ for (int i = 0; i < 50; ++i) {
+ assert(v[i] == 0);
+ }
+ for (int i = 50; i < 200; ++i) {
+ assert(v[i] == 1);
+ }
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/size.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/size.pass.cpp
index 68510865c4..30acc72fe6 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/size.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.capacity/size.pass.cpp
@@ -37,25 +37,24 @@ constexpr bool tests() {
v.erase(v.begin());
assert(v.size() == 0);
}
- if
- !consteval {
- using V = std::inplace_vector<MoveOnly, 10>;
- V v;
- ASSERT_NOEXCEPT(v.size());
- assert(v.size() == 0);
- v.push_back(2);
- assert(v.size() == 1);
- v.push_back(1);
- assert(v.size() == 2);
- v.push_back(3);
- assert(v.size() == 3);
- v.erase(v.begin());
- assert(v.size() == 2);
- v.erase(v.begin());
- assert(v.size() == 1);
- v.erase(v.begin());
- assert(v.size() == 0);
- }
+ if !consteval {
+ using V = std::inplace_vector<MoveOnly, 10>;
+ V v;
+ ASSERT_NOEXCEPT(v.size());
+ assert(v.size() == 0);
+ v.push_back(2);
+ assert(v.size() == 1);
+ v.push_back(1);
+ assert(v.size() == 2);
+ v.push_back(3);
+ assert(v.size() == 3);
+ v.erase(v.begin());
+ assert(v.size() == 2);
+ v.erase(v.begin());
+ assert(v.size() == 1);
+ v.erase(v.begin());
+ assert(v.size() == 0);
+ }
{
using V = std::inplace_vector<int, 0>;
V v;
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_iter_iter.pass.cpp
index c4ef0b537b..8319fccff4 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_iter_iter.pass.cpp
@@ -22,44 +22,42 @@
constexpr bool test() {
int arr1[] = {42};
int arr2[] = {1, 101, 42};
- if
- !consteval {
- using T = EmplaceConstructibleMoveableAndAssignable<int>;
- using It = forward_iterator<int*>;
- {
- std::inplace_vector<T, 10> v;
- v.assign(It(arr1), It(std::end(arr1)));
- assert(v[0].value == 42);
- }
- {
- std::inplace_vector<T, 10> v;
- v.assign(It(arr2), It(std::end(arr2)));
- assert(v[0].value == 1);
- assert(v[1].value == 101);
- assert(v[2].value == 42);
- }
+ if !consteval {
+ using T = EmplaceConstructibleMoveableAndAssignable<int>;
+ using It = forward_iterator<int*>;
+ {
+ std::inplace_vector<T, 10> v;
+ v.assign(It(arr1), It(std::end(arr1)));
+ assert(v[0].value == 42);
}
- if
- !consteval {
- using T = EmplaceConstructibleMoveableAndAssignable<int>;
- using It = cpp17_input_iterator<int*>;
- {
- std::inplace_vector<T, 10> v;
- v.assign(It(arr1), It(std::end(arr1)));
- assert(v[0].copied == 0);
- assert(v[0].value == 42);
- }
- {
- std::inplace_vector<T, 10> v;
- v.assign(It(arr2), It(std::end(arr2)));
- //assert(v[0].copied == 0);
- assert(v[0].value == 1);
- //assert(v[1].copied == 0);
- assert(v[1].value == 101);
- assert(v[2].copied == 0);
- assert(v[2].value == 42);
- }
+ {
+ std::inplace_vector<T, 10> v;
+ v.assign(It(arr2), It(std::end(arr2)));
+ assert(v[0].value == 1);
+ assert(v[1].value == 101);
+ assert(v[2].value == 42);
}
+ }
+ if !consteval {
+ using T = EmplaceConstructibleMoveableAndAssignable<int>;
+ using It = cpp17_input_iterator<int*>;
+ {
+ std::inplace_vector<T, 10> v;
+ v.assign(It(arr1), It(std::end(arr1)));
+ assert(v[0].copied == 0);
+ assert(v[0].value == 42);
+ }
+ {
+ std::inplace_vector<T, 10> v;
+ v.assign(It(arr2), It(std::end(arr2)));
+ //assert(v[0].copied == 0);
+ assert(v[0].value == 1);
+ //assert(v[1].copied == 0);
+ assert(v[1].value == 101);
+ assert(v[2].copied == 0);
+ assert(v[2].value == 42);
+ }
+ }
{
using T = int;
using It = forward_iterator<int*>;
@@ -93,24 +91,23 @@ constexpr bool test() {
}
}
- if
- !consteval {
+ if !consteval {
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- using It = forward_iterator<int*>;
+ try {
+ using It = forward_iterator<int*>;
- std::inplace_vector<int, 10> dst(10);
- int src[20]{};
+ std::inplace_vector<int, 10> dst(10);
+ int src[20]{};
- dst.assign(It(src + 0), It(src + 20));
- assert(false);
- } catch (const std::bad_alloc& e) {
- // OK
- } catch (...) {
- assert(false);
- }
-#endif
+ dst.assign(It(src + 0), It(src + 20));
+ assert(false);
+ } catch (const std::bad_alloc& e) {
+ // OK
+ } catch (...) {
+ assert(false);
}
+#endif
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_move.pass.cpp
index 89d9a7426f..e0f7640359 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_move.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/assign_move.pass.cpp
@@ -18,23 +18,22 @@
#include "MoveOnly.h"
constexpr bool tests() {
- if
- !consteval {
- std::inplace_vector<MoveOnly, 10> l;
- std::inplace_vector<MoveOnly, 10> lo;
- for (int i = 1; i <= 3; ++i) {
- l.push_back(i);
- lo.push_back(i);
- }
- std::inplace_vector<MoveOnly, 10> l2;
- l2 = std::move(l);
- assert(l2.size() == 3);
- assert(l2[0] == 1);
- assert(l2[1] == 2);
- assert(l2[2] == 3);
- assert(l2 == lo);
- // assert(l.size() == lo.size()); // l is left unspecified
+ if !consteval {
+ std::inplace_vector<MoveOnly, 10> l;
+ std::inplace_vector<MoveOnly, 10> lo;
+ for (int i = 1; i <= 3; ++i) {
+ l.push_back(i);
+ lo.push_back(i);
}
+ std::inplace_vector<MoveOnly, 10> l2;
+ l2 = std::move(l);
+ assert(l2.size() == 3);
+ assert(l2[0] == 1);
+ assert(l2[1] == 2);
+ assert(l2[2] == 3);
+ assert(l2 == lo);
+ // assert(l.size() == lo.size()); // l is left unspecified
+ }
{
std::inplace_vector<int, 10> l;
std::inplace_vector<int, 10> lo;
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_default.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_default.pass.cpp
index d57701306e..3573542f88 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_default.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_default.pass.cpp
@@ -21,7 +21,7 @@
template <class C>
constexpr void test0() {
- static_assert(noexcept(C{})&& noexcept(C()));
+ static_assert(noexcept(C{}) && noexcept(C()));
static_assert(std::is_trivially_default_constructible_v<C> == (C::capacity() == 0));
C c;
assert(c.empty());
@@ -50,16 +50,18 @@ constexpr bool tests() {
test0<V>();
constexpr V _;
}
- if
- !consteval { test0<std::inplace_vector<NotConstructible, 10>>(); }
+ if !consteval {
+ test0<std::inplace_vector<NotConstructible, 10>>();
+ }
{
using V = std::inplace_vector<NonTrivial, 0>;
test0<V>();
constexpr V _;
}
- if
- !consteval { test0<std::inplace_vector<NonTrivial, 10>>(); }
+ if !consteval {
+ test0<std::inplace_vector<NonTrivial, 10>>();
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_iter_iter.pass.cpp
index 8711b01f9d..fd02718316 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_iter_iter.pass.cpp
@@ -51,75 +51,71 @@ constexpr void basic_test_cases() {
V v2(forward_iterator<const int*>{}, {});
}
- if
- !consteval {
- volatile int src[] = {1, 2, 3};
- std::inplace_vector<int, 3> v(src, src + 3);
- assert(v[0] == 1);
- assert(v[1] == 2);
- assert(v[2] == 3);
- }
+ if !consteval {
+ volatile int src[] = {1, 2, 3};
+ std::inplace_vector<int, 3> v(src, src + 3);
+ assert(v[0] == 1);
+ assert(v[1] == 2);
+ assert(v[2] == 3);
+ }
}
constexpr void emplaceable_concept_tests() {
int arr1[] = {42};
int arr2[] = {1, 101, 42};
- if
- !consteval {
- using T = EmplaceConstructible<int>;
- using It = forward_iterator<int*>;
- {
- std::inplace_vector<T, 10> v(It(arr1), It(std::end(arr1)));
- assert(v[0].value == 42);
- }
- {
- std::inplace_vector<T, 10> v(It(arr2), It(std::end(arr2)));
- assert(v[0].value == 1);
- assert(v[1].value == 101);
- assert(v[2].value == 42);
- }
+ if !consteval {
+ using T = EmplaceConstructible<int>;
+ using It = forward_iterator<int*>;
+ {
+ std::inplace_vector<T, 10> v(It(arr1), It(std::end(arr1)));
+ assert(v[0].value == 42);
+ }
+ {
+ std::inplace_vector<T, 10> v(It(arr2), It(std::end(arr2)));
+ assert(v[0].value == 1);
+ assert(v[1].value == 101);
+ assert(v[2].value == 42);
}
+ }
- if
- !consteval {
- using T = EmplaceConstructibleAndMoveInsertable<int>;
- using It = cpp17_input_iterator<int*>;
- {
- std::inplace_vector<T, 10> v(It(arr1), It(std::end(arr1)));
- assert(v[0].copied == 0);
- assert(v[0].value == 42);
- }
- {
- std::inplace_vector<T, 10> v(It(arr2), It(std::end(arr2)));
- //assert(v[0].copied == 0);
- assert(v[0].value == 1);
- //assert(v[1].copied == 0);
- assert(v[1].value == 101);
- assert(v[2].copied == 0);
- assert(v[2].value == 42);
- }
+ if !consteval {
+ using T = EmplaceConstructibleAndMoveInsertable<int>;
+ using It = cpp17_input_iterator<int*>;
+ {
+ std::inplace_vector<T, 10> v(It(arr1), It(std::end(arr1)));
+ assert(v[0].copied == 0);
+ assert(v[0].value == 42);
+ }
+ {
+ std::inplace_vector<T, 10> v(It(arr2), It(std::end(arr2)));
+ //assert(v[0].copied == 0);
+ assert(v[0].value == 1);
+ //assert(v[1].copied == 0);
+ assert(v[1].value == 101);
+ assert(v[2].copied == 0);
+ assert(v[2].value == 42);
}
+ }
}
constexpr void overcapacity_tests() {
- if
- !consteval {
+ if !consteval {
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- using It = forward_iterator<int*>;
-
- std::inplace_vector<int, 10> dst(10);
- int src[20]{};
-
- dst.assign(It(src + 0), It(src + 20));
- assert(false);
- } catch (const std::bad_alloc& e) {
- // OK
- } catch (...) {
- assert(false);
- }
-#endif
+ try {
+ using It = forward_iterator<int*>;
+
+ std::inplace_vector<int, 10> dst(10);
+ int src[20]{};
+
+ dst.assign(It(src + 0), It(src + 20));
+ assert(false);
+ } catch (const std::bad_alloc& e) {
+ // OK
+ } catch (...) {
+ assert(false);
}
+#endif
+ }
}
struct B1 {
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_size_value.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_size_value.pass.cpp
index bfbb145e2b..60e4d9c880 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_size_value.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/construct_size_value.pass.cpp
@@ -29,28 +29,27 @@ constexpr bool tests() {
test<std::inplace_vector<int, 10>>(0, 3);
test<std::inplace_vector<int, 100>>(50, 3);
test<std::inplace_vector<int, 100>>(100, 3);
- if
- !consteval {
+ if !consteval {
#ifndef TEST_HAS_NO_EXCEPTIONS
- try {
- std::inplace_vector<int, 10>(50, 3);
- assert(false);
- } catch (const std::bad_alloc&) {
- // OK
- } catch (...) {
- assert(false);
- }
-
- try {
- std::inplace_vector<int, 0>(1, 3);
- assert(false);
- } catch (const std::bad_alloc&) {
- // OK
- } catch (...) {
- assert(false);
- }
-#endif
+ try {
+ std::inplace_vector<int, 10>(50, 3);
+ assert(false);
+ } catch (const std::bad_alloc&) {
+ // OK
+ } catch (...) {
+ assert(false);
+ }
+
+ try {
+ std::inplace_vector<int, 0>(1, 3);
+ assert(false);
+ } catch (const std::bad_alloc&) {
+ // OK
+ } catch (...) {
+ assert(false);
}
+#endif
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/move.pass.cpp
index 9b7c15f0c1..4d6fddacc6 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/move.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.cons/move.pass.cpp
@@ -18,22 +18,21 @@
#include "MoveOnly.h"
constexpr bool tests() {
- if
- !consteval {
- std::inplace_vector<MoveOnly, 10> l;
- std::inplace_vector<MoveOnly, 10> lo;
- for (int i = 1; i <= 3; ++i) {
- l.push_back(i);
- lo.push_back(i);
- }
- std::inplace_vector<MoveOnly, 10> l2 = std::move(l);
- assert(l2.size() == 3);
- assert(l2[0] == 1);
- assert(l2[1] == 2);
- assert(l2[2] == 3);
- assert(l2 == lo);
- // assert(l.size() == lo.size()); // l is left unspecified
+ if !consteval {
+ std::inplace_vector<MoveOnly, 10> l;
+ std::inplace_vector<MoveOnly, 10> lo;
+ for (int i = 1; i <= 3; ++i) {
+ l.push_back(i);
+ lo.push_back(i);
}
+ std::inplace_vector<MoveOnly, 10> l2 = std::move(l);
+ assert(l2.size() == 3);
+ assert(l2[0] == 1);
+ assert(l2[1] == 2);
+ assert(l2[2] == 3);
+ assert(l2 == lo);
+ // assert(l.size() == lo.size()); // l is left unspecified
+ }
{
std::inplace_vector<int, 10> l;
std::inplace_vector<int, 10> lo;
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data.pass.cpp
index 8c3351a82a..97e17f4df3 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data.pass.cpp
@@ -62,26 +62,24 @@ constexpr bool tests() {
assert(v.data() == nullptr);
static_assert(v.data() == nullptr);
}
- if
- !consteval {
- std::inplace_vector<Nasty, 10> v;
- ASSERT_NOEXCEPT(v.data());
- assert(v.data() == std::to_address(v.begin()));
- std::same_as<Nasty*> decltype(auto) data = v.data();
- v.push_back(4);
- assert(data == std::addressof(v.front()));
- assert(v.data() == data);
- assert(data[0].i_ == 4);
- data[0].i_ = 3;
- assert(v.front().i_ == 3);
- }
- if
- !consteval {
- static_assert(glob.data() != nullptr);
- assert(glob.data()[0].i_ == 123);
- glob.data()[0].i_ = 321;
- assert(glob.front().i_ == 321);
- }
+ if !consteval {
+ std::inplace_vector<Nasty, 10> v;
+ ASSERT_NOEXCEPT(v.data());
+ assert(v.data() == std::to_address(v.begin()));
+ std::same_as<Nasty*> decltype(auto) data = v.data();
+ v.push_back(4);
+ assert(data == std::addressof(v.front()));
+ assert(v.data() == data);
+ assert(data[0].i_ == 4);
+ data[0].i_ = 3;
+ assert(v.front().i_ == 3);
+ }
+ if !consteval {
+ static_assert(glob.data() != nullptr);
+ assert(glob.data()[0].i_ == 123);
+ glob.data()[0].i_ = 321;
+ assert(glob.front().i_ == 321);
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data_const.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data_const.pass.cpp
index 672a17f65f..cf1df0b3b3 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data_const.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/inplace.vector.data/data_const.pass.cpp
@@ -64,27 +64,25 @@ constexpr bool tests() {
assert(std::as_const(v).data() == nullptr);
static_assert(std::as_const(v).data() == nullptr);
}
- if
- !consteval {
- std::inplace_vector<Nasty, 10> v;
- ASSERT_NOEXCEPT(std::as_const(v).data());
- assert(std::as_const(v).data() == v.data());
- assert(std::as_const(v).data() == std::to_address(v.begin()));
- std::same_as<const Nasty*> decltype(auto) data = std::as_const(v).data();
- v.push_back(4);
- assert(data == std::addressof(v.front()));
- assert(std::as_const(v).data() == data);
- assert(data[0].i_ == 4);
- const_cast<Nasty*>(data)[0].i_ = 3;
- assert(v.front().i_ == 3);
- }
- if
- !consteval {
- static_assert(std::as_const(glob).data() != nullptr);
- assert(std::as_const(glob).data()[0].i_ == 123);
- const_cast<Nasty*>(std::as_const(glob).data())[0].i_ = 321;
- assert(glob.front().i_ == 321);
- }
+ if !consteval {
+ std::inplace_vector<Nasty, 10> v;
+ ASSERT_NOEXCEPT(std::as_const(v).data());
+ assert(std::as_const(v).data() == v.data());
+ assert(std::as_const(v).data() == std::to_address(v.begin()));
+ std::same_as<const Nasty*> decltype(auto) data = std::as_const(v).data();
+ v.push_back(4);
+ assert(data == std::addressof(v.front()));
+ assert(std::as_const(v).data() == data);
+ assert(data[0].i_ == 4);
+ const_cast<Nasty*>(data)[0].i_ = 3;
+ assert(v.front().i_ == 3);
+ }
+ if !consteval {
+ static_assert(std::as_const(glob).data() != nullptr);
+ assert(std::as_const(glob).data()[0].i_ == 123);
+ const_cast<Nasty*>(std::as_const(glob).data())[0].i_ = 321;
+ assert(glob.front().i_ == 321);
+ }
return true;
}
diff --git a/libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/erase_iter_iter.pass.cpp
index 1e57dd9150..80ed572e19 100644
--- a/libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/erase_iter_iter.pass.cpp
+++ b/libcxx/test/std/containers/sequences/inplace.vector/vector.modifiers/erase_iter_iter.pass.cpp
@@ -85,68 +85,69 @@ TEST_CONSTEXPR_CXX20 bool tests() {
assert(outer[1].size() == 1);
}
// Make sure vector::erase works with move-only types
- {// When non-trivial
- {std::vector<MoveOnly> v;
- v.emplace_back(1);
- v.emplace_back(2);
- v.emplace_back(3);
- v.erase(v.begin(), v.begin() + 2);
- assert(v.size() == 1);
- assert(v[0] == MoveOnly(3));
-}
-// When trivial
-{
- std::vector<TrivialMoveOnly> v;
- v.emplace_back(1);
- v.emplace_back(2);
- v.emplace_back(3);
- v.erase(v.begin(), v.begin() + 2);
- assert(v.size() == 1);
- assert(v[0] == TrivialMoveOnly(3));
-}
-}
+ { // When non-trivial
+ {
+ std::vector<MoveOnly> v;
+ v.emplace_back(1);
+ v.emplace_back(2);
+ v.emplace_back(3);
+ v.erase(v.begin(), v.begin() + 2);
+ assert(v.size() == 1);
+ assert(v[0] == MoveOnly(3));
+ }
+ // When trivial
+ {
+ std::vector<TrivialMoveOnly> v;
+ v.emplace_back(1);
+ v.emplace_back(2);
+ v.emplace_back(3);
+ v.erase(v.begin(), v.begin() + 2);
+ assert(v.size() == 1);
+ assert(v[0] == TrivialMoveOnly(3));
+ }
+ }
#if TEST_STD_VER >= 11
-{
- std::vector<int, min_allocator<int>> l1(a1, a1 + 3);
- std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l1.cbegin());
- assert(l1.size() == 3);
- assert(std::distance(l1.cbegin(), l1.cend()) == 3);
- assert(i == l1.begin());
-}
-{
- std::vector<int, min_allocator<int>> l1(a1, a1 + 3);
- std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin()));
- assert(l1.size() == 2);
- assert(std::distance(l1.cbegin(), l1.cend()) == 2);
- assert(i == l1.begin());
- assert((l1 == std::vector<int, min_allocator<int>>(a1 + 1, a1 + 3)));
-}
-{
- std::vector<int, min_allocator<int>> l1(a1, a1 + 3);
- std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin(), 2));
- assert(l1.size() == 1);
- assert(std::distance(l1.cbegin(), l1.cend()) == 1);
- assert(i == l1.begin());
- assert((l1 == std::vector<int, min_allocator<int>>(a1 + 2, a1 + 3)));
-}
-{
- std::vector<int, min_allocator<int>> l1(a1, a1 + 3);
- std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin(), 3));
- assert(l1.size() == 0);
- assert(std::distance(l1.cbegin(), l1.cend()) == 0);
- assert(i == l1.begin());
-}
-{
- std::vector<std::vector<int, min_allocator<int>>, min_allocator<std::vector<int, min_allocator<int>>>> outer(
- 2, std::vector<int, min_allocator<int>>(1));
- outer.erase(outer.begin(), outer.begin());
- assert(outer.size() == 2);
- assert(outer[0].size() == 1);
- assert(outer[1].size() == 1);
-}
+ {
+ std::vector<int, min_allocator<int>> l1(a1, a1 + 3);
+ std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l1.cbegin());
+ assert(l1.size() == 3);
+ assert(std::distance(l1.cbegin(), l1.cend()) == 3);
+ assert(i == l1.begin());
+ }
+ {
+ std::vector<int, min_allocator<int>> l1(a1, a1 + 3);
+ std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin()));
+ assert(l1.size() == 2);
+ assert(std::distance(l1.cbegin(), l1.cend()) == 2);
+ assert(i == l1.begin());
+ assert((l1 == std::vector<int, min_allocator<int>>(a1 + 1, a1 + 3)));
+ }
+ {
+ std::vector<int, min_allocator<int>> l1(a1, a1 + 3);
+ std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin(), 2));
+ assert(l1.size() == 1);
+ assert(std::distance(l1.cbegin(), l1.cend()) == 1);
+ assert(i == l1.begin());
+ assert((l1 == std::vector<int, min_allocator<int>>(a1 + 2, a1 + 3)));
+ }
+ {
+ std::vector<int, min_allocator<int>> l1(a1, a1 + 3);
+ std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), std::next(l1.cbegin(), 3));
+ assert(l1.size() == 0);
+ assert(std::distance(l1.cbegin(), l1.cend()) == 0);
+ assert(i == l1.begin());
+ }
+ {
+ std::vector<std::vector<int, min_allocator<int>>, min_allocator<std::vector<int, min_allocator<int>>>> outer(
+ 2, std::vector<int, min_allocator<int>>(1));
+ outer.erase(outer.begin(), outer.begin());
+ assert(outer.size() == 2);
+ assert(outer[0].size() == 1);
+ assert(outer[1].size() == 1);
+ }
#endif
-return true;
+ return true;
}
int main(int, char**) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/105981
More information about the libcxx-commits
mailing list