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

0 commit comments

Comments
 (0)