Skip to content

Commit 5f35f6c

Browse files
committed
[libc++] Granularize <vector>
1 parent ac5a201 commit 5f35f6c

File tree

33 files changed

+3024
-2743
lines changed

33 files changed

+3024
-2743
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,14 @@ set(files
882882
__utility/to_underlying.h
883883
__utility/unreachable.h
884884
__variant/monostate.h
885+
__vector/comparison.h
886+
__vector/container_traits.h
887+
__vector/erase.h
888+
__vector/formatter.h
889+
__vector/pmr.h
890+
__vector/swap.h
891+
__vector/vector.h
892+
__vector/vector_bool.h
885893
__verbose_abort
886894
algorithm
887895
any

libcxx/include/__chrono/tzdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
# include <__chrono/time_zone_link.h>
2323
# include <__config>
2424
# include <__memory/addressof.h>
25+
# include <__vector/vector.h>
2526
# include <stdexcept>
2627
# include <string>
2728
# include <string_view>
28-
# include <vector>
2929

3030
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
3131
# pragma GCC system_header

libcxx/include/__functional/boyer_moore_searcher.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
#include <__memory/shared_ptr.h>
2323
#include <__type_traits/make_unsigned.h>
2424
#include <__utility/pair.h>
25+
#include <__vector/vector.h>
2526
#include <array>
27+
#include <limits>
2628
#include <unordered_map>
27-
#include <vector>
2829

2930
#if _LIBCPP_STD_VER >= 17
3031

libcxx/include/__fwd/vector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121
template <class _Tp, class _Alloc = allocator<_Tp> >
2222
class _LIBCPP_TEMPLATE_VIS vector;
2323

24+
template <class _Allocator>
25+
class vector<bool, _Allocator>;
26+
2427
_LIBCPP_END_NAMESPACE_STD
2528

2629
#endif // _LIBCPP___FWD_VECTOR_H

libcxx/include/__random/discrete_distribution.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
#include <__config>
1414
#include <__random/is_valid.h>
1515
#include <__random/uniform_real_distribution.h>
16+
#include <__vector/vector.h>
1617
#include <cstddef>
18+
#include <initializer_list>
1719
#include <iosfwd>
1820
#include <numeric>
19-
#include <vector>
2021

2122
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2223
# pragma GCC system_header

libcxx/include/__random/piecewise_constant_distribution.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
#include <__config>
1414
#include <__random/is_valid.h>
1515
#include <__random/uniform_real_distribution.h>
16+
#include <__vector/vector.h>
17+
#include <initializer_list>
1618
#include <iosfwd>
1719
#include <numeric>
18-
#include <vector>
1920

2021
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2122
# pragma GCC system_header

libcxx/include/__random/piecewise_linear_distribution.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
#include <__config>
1414
#include <__random/is_valid.h>
1515
#include <__random/uniform_real_distribution.h>
16+
#include <__vector/comparison.h>
17+
#include <__vector/vector.h>
1618
#include <cmath>
19+
#include <initializer_list>
1720
#include <iosfwd>
18-
#include <vector>
1921

2022
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2123
# pragma GCC system_header

libcxx/include/__random/seed_seq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include <__type_traits/enable_if.h>
1818
#include <__type_traits/is_integral.h>
1919
#include <__type_traits/is_unsigned.h>
20+
#include <__vector/vector.h>
2021
#include <cstdint>
2122
#include <initializer_list>
22-
#include <vector>
2323

2424
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2525
# pragma GCC system_header

libcxx/include/__vector/comparison.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___VECTOR_COMPARISON_H
10+
#define _LIBCPP___VECTOR_COMPARISON_H
11+
12+
#include <__algorithm/equal.h>
13+
#include <__algorithm/lexicographical_compare.h>
14+
#include <__algorithm/lexicographical_compare_three_way.h>
15+
#include <__compare/synth_three_way.h>
16+
#include <__config>
17+
#include <__fwd/vector.h>
18+
19+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20+
# pragma GCC system_header
21+
#endif
22+
23+
_LIBCPP_BEGIN_NAMESPACE_STD
24+
25+
template <class _Tp, class _Allocator>
26+
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool
27+
operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
28+
const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
29+
return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
30+
}
31+
32+
#if _LIBCPP_STD_VER <= 17
33+
34+
template <class _Tp, class _Allocator>
35+
inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
36+
return !(__x == __y);
37+
}
38+
39+
template <class _Tp, class _Allocator>
40+
inline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
41+
return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
42+
}
43+
44+
template <class _Tp, class _Allocator>
45+
inline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
46+
return __y < __x;
47+
}
48+
49+
template <class _Tp, class _Allocator>
50+
inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
51+
return !(__x < __y);
52+
}
53+
54+
template <class _Tp, class _Allocator>
55+
inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
56+
return !(__y < __x);
57+
}
58+
59+
#else // _LIBCPP_STD_VER <= 17
60+
61+
template <class _Tp, class _Allocator>
62+
_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp>
63+
operator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) {
64+
return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
65+
}
66+
67+
#endif // _LIBCPP_STD_VER <= 17
68+
69+
_LIBCPP_END_NAMESPACE_STD
70+
71+
#endif // _LIBCPP___VECTOR_COMPARISON_H
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___VECTOR_CONTAINER_TRAITS_H
10+
#define _LIBCPP___VECTOR_CONTAINER_TRAITS_H
11+
12+
#include <__config>
13+
#include <__fwd/vector.h>
14+
#include <__memory/allocator_traits.h>
15+
#include <__type_traits/container_traits.h>
16+
#include <__type_traits/disjunction.h>
17+
#include <__type_traits/is_nothrow_constructible.h>
18+
19+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20+
# pragma GCC system_header
21+
#endif
22+
23+
_LIBCPP_BEGIN_NAMESPACE_STD
24+
25+
template <class _Tp, class _Allocator>
26+
struct __container_traits<vector<_Tp, _Allocator> > {
27+
// http://eel.is/c++draft/vector.modifiers#2
28+
// If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move
29+
// assignment operator of T or by any InputIterator operation, there are no effects. If an exception is thrown while
30+
// inserting a single element at the end and T is Cpp17CopyInsertable or is_nothrow_move_constructible_v<T> is true,
31+
// there are no effects. Otherwise, if an exception is thrown by the move constructor of a non-Cpp17CopyInsertable T,
32+
// the effects are unspecified.
33+
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee =
34+
_Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value;
35+
};
36+
37+
_LIBCPP_END_NAMESPACE_STD
38+
39+
#endif // _LIBCPP___VECTOR_CONTAINER_TRAITS_H

libcxx/include/__vector/erase.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___VECTOR_ERASE_H
10+
#define _LIBCPP___VECTOR_ERASE_H
11+
12+
#include <__algorithm/remove.h>
13+
#include <__algorithm/remove_if.h>
14+
#include <__config>
15+
#include <__fwd/vector.h>
16+
17+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18+
# pragma GCC system_header
19+
#endif
20+
21+
_LIBCPP_PUSH_MACROS
22+
#include <__undef_macros>
23+
24+
#if _LIBCPP_STD_VER >= 20
25+
26+
_LIBCPP_BEGIN_NAMESPACE_STD
27+
28+
template <class _Tp, class _Allocator, class _Up>
29+
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
30+
erase(vector<_Tp, _Allocator>& __c, const _Up& __v) {
31+
auto __old_size = __c.size();
32+
__c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end());
33+
return __old_size - __c.size();
34+
}
35+
36+
template <class _Tp, class _Allocator, class _Predicate>
37+
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type
38+
erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) {
39+
auto __old_size = __c.size();
40+
__c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
41+
return __old_size - __c.size();
42+
}
43+
44+
_LIBCPP_END_NAMESPACE_STD
45+
46+
#endif // _LIBCPP_STD_VER >= 20
47+
48+
_LIBCPP_POP_MACROS
49+
50+
#endif // _LIBCPP___VECTOR_ERASE_H

libcxx/include/__vector/formatter.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___VECTOR_FORMATTER_H
10+
#define _LIBCPP___VECTOR_FORMATTER_H
11+
12+
#include <__concepts/same_as.h>
13+
#include <__config>
14+
#include <__format/formatter.h>
15+
#include <__format/formatter_bool.h>
16+
#include <__fwd/vector.h>
17+
18+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19+
# pragma GCC system_header
20+
#endif
21+
22+
#if _LIBCPP_STD_VER >= 23
23+
24+
_LIBCPP_BEGIN_NAMESPACE_STD
25+
26+
template <class _Tp, class _CharT>
27+
// Since is-vector-bool-reference is only used once it's inlined here.
28+
requires same_as<typename _Tp::__container, vector<bool, typename _Tp::__container::allocator_type>>
29+
struct _LIBCPP_TEMPLATE_VIS formatter<_Tp, _CharT> {
30+
private:
31+
formatter<bool, _CharT> __underlying_;
32+
33+
public:
34+
template <class _ParseContext>
35+
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
36+
return __underlying_.parse(__ctx);
37+
}
38+
39+
template <class _FormatContext>
40+
_LIBCPP_HIDE_FROM_ABI typename _FormatContext::iterator format(const _Tp& __ref, _FormatContext& __ctx) const {
41+
return __underlying_.format(__ref, __ctx);
42+
}
43+
};
44+
45+
_LIBCPP_END_NAMESPACE_STD
46+
47+
#endif // _LIBCPP_STD_VER >= 23
48+
49+
#endif // _LIBCPP___VECTOR_FORMATTER_H

libcxx/include/__vector/pmr.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___VECTOR_PMR_H
10+
#define _LIBCPP___VECTOR_PMR_H
11+
12+
#include <__config>
13+
#include <__fwd/vector.h>
14+
#include <__memory_resource/polymorphic_allocator.h>
15+
16+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17+
# pragma GCC system_header
18+
#endif
19+
20+
#if _LIBCPP_STD_VER >= 17
21+
22+
_LIBCPP_BEGIN_NAMESPACE_STD
23+
24+
namespace pmr {
25+
template <class _ValueT>
26+
using vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>;
27+
} // namespace pmr
28+
29+
_LIBCPP_END_NAMESPACE_STD
30+
31+
#endif
32+
33+
#endif // _LIBCPP___VECTOR_PMR_H

libcxx/include/__vector/swap.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _LIBCPP___VECTOR_SWAP_H
10+
#define _LIBCPP___VECTOR_SWAP_H
11+
12+
#include <__config>
13+
#include <__fwd/vector.h>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
template <class _Tp, class _Allocator>
22+
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void
23+
swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
24+
__x.swap(__y);
25+
}
26+
27+
_LIBCPP_END_NAMESPACE_STD
28+
29+
#endif // _LIBCPP___VECTOR_SWAP_H

0 commit comments

Comments
 (0)