-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc++] Granularize <vector> #99705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___VECTOR_COMPARISON_H | ||
#define _LIBCPP___VECTOR_COMPARISON_H | ||
|
||
#include <__algorithm/equal.h> | ||
#include <__algorithm/lexicographical_compare.h> | ||
#include <__algorithm/lexicographical_compare_three_way.h> | ||
#include <__compare/synth_three_way.h> | ||
#include <__config> | ||
#include <__fwd/vector.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <class _Tp, class _Allocator> | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI bool | ||
operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { | ||
const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); | ||
return __sz == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin()); | ||
} | ||
|
||
#if _LIBCPP_STD_VER <= 17 | ||
|
||
template <class _Tp, class _Allocator> | ||
inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { | ||
return !(__x == __y); | ||
} | ||
|
||
template <class _Tp, class _Allocator> | ||
inline _LIBCPP_HIDE_FROM_ABI bool operator<(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { | ||
return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); | ||
} | ||
|
||
template <class _Tp, class _Allocator> | ||
inline _LIBCPP_HIDE_FROM_ABI bool operator>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { | ||
return __y < __x; | ||
} | ||
|
||
template <class _Tp, class _Allocator> | ||
inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { | ||
return !(__x < __y); | ||
} | ||
|
||
template <class _Tp, class _Allocator> | ||
inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { | ||
return !(__y < __x); | ||
} | ||
|
||
#else // _LIBCPP_STD_VER <= 17 | ||
|
||
template <class _Tp, class _Allocator> | ||
_LIBCPP_HIDE_FROM_ABI constexpr __synth_three_way_result<_Tp> | ||
operator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) { | ||
return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way); | ||
} | ||
|
||
#endif // _LIBCPP_STD_VER <= 17 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___VECTOR_COMPARISON_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___VECTOR_CONTAINER_TRAITS_H | ||
#define _LIBCPP___VECTOR_CONTAINER_TRAITS_H | ||
|
||
#include <__config> | ||
#include <__fwd/vector.h> | ||
#include <__memory/allocator_traits.h> | ||
#include <__type_traits/container_traits.h> | ||
#include <__type_traits/disjunction.h> | ||
#include <__type_traits/is_nothrow_constructible.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <class _Tp, class _Allocator> | ||
struct __container_traits<vector<_Tp, _Allocator> > { | ||
// http://eel.is/c++draft/vector.modifiers#2 | ||
// If an exception is thrown other than by the copy constructor, move constructor, assignment operator, or move | ||
// assignment operator of T or by any InputIterator operation, there are no effects. If an exception is thrown while | ||
// inserting a single element at the end and T is Cpp17CopyInsertable or is_nothrow_move_constructible_v<T> is true, | ||
// there are no effects. Otherwise, if an exception is thrown by the move constructor of a non-Cpp17CopyInsertable T, | ||
// the effects are unspecified. | ||
static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = | ||
_Or<is_nothrow_move_constructible<_Tp>, __is_cpp17_copy_insertable<_Allocator> >::value; | ||
}; | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___VECTOR_CONTAINER_TRAITS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___VECTOR_ERASE_H | ||
#define _LIBCPP___VECTOR_ERASE_H | ||
|
||
#include <__algorithm/remove.h> | ||
#include <__algorithm/remove_if.h> | ||
#include <__config> | ||
#include <__fwd/vector.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_PUSH_MACROS | ||
#include <__undef_macros> | ||
|
||
#if _LIBCPP_STD_VER >= 20 | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <class _Tp, class _Allocator, class _Up> | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type | ||
erase(vector<_Tp, _Allocator>& __c, const _Up& __v) { | ||
auto __old_size = __c.size(); | ||
__c.erase(std::remove(__c.begin(), __c.end(), __v), __c.end()); | ||
return __old_size - __c.size(); | ||
} | ||
|
||
template <class _Tp, class _Allocator, class _Predicate> | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::size_type | ||
erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { | ||
auto __old_size = __c.size(); | ||
__c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end()); | ||
return __old_size - __c.size(); | ||
} | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP_STD_VER >= 20 | ||
|
||
_LIBCPP_POP_MACROS | ||
|
||
#endif // _LIBCPP___VECTOR_ERASE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___VECTOR_PMR_H | ||
#define _LIBCPP___VECTOR_PMR_H | ||
|
||
#include <__config> | ||
#include <__fwd/vector.h> | ||
#include <__memory_resource/polymorphic_allocator.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
#if _LIBCPP_STD_VER >= 17 | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
namespace pmr { | ||
template <class _ValueT> | ||
using vector _LIBCPP_AVAILABILITY_PMR = std::vector<_ValueT, polymorphic_allocator<_ValueT>>; | ||
} // namespace pmr | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif | ||
|
||
#endif // _LIBCPP___VECTOR_PMR_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCPP___VECTOR_SWAP_H | ||
#define _LIBCPP___VECTOR_SWAP_H | ||
|
||
#include <__config> | ||
#include <__fwd/vector.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
template <class _Tp, class _Allocator> | ||
_LIBCPP_CONSTEXPR_SINCE_CXX20 inline _LIBCPP_HIDE_FROM_ABI void | ||
swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) { | ||
__x.swap(__y); | ||
} | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP___VECTOR_SWAP_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.