Skip to content

Commit

Permalink
[libc++] Granularize <vector>
Browse files Browse the repository at this point in the history
  • Loading branch information
philnik777 committed Oct 24, 2024
1 parent e78f53d commit 7198233
Show file tree
Hide file tree
Showing 33 changed files with 3,028 additions and 2,743 deletions.
8 changes: 8 additions & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,14 @@ set(files
__utility/to_underlying.h
__utility/unreachable.h
__variant/monostate.h
__vector/comparison.h
__vector/container_traits.h
__vector/erase.h
__vector/pmr.h
__vector/swap.h
__vector/vector.h
__vector/vector_bool.h
__vector/vector_bool_formatter.h
__verbose_abort
algorithm
any
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__chrono/tzdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
# include <__chrono/time_zone_link.h>
# include <__config>
# include <__memory/addressof.h>
# include <__vector/vector.h>
# include <stdexcept>
# include <string>
# include <string_view>
# include <vector>

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down
3 changes: 2 additions & 1 deletion libcxx/include/__functional/boyer_moore_searcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#include <__memory/shared_ptr.h>
#include <__type_traits/make_unsigned.h>
#include <__utility/pair.h>
#include <__vector/vector.h>
#include <array>
#include <limits>
#include <unordered_map>
#include <vector>

#if _LIBCPP_STD_VER >= 17

Expand Down
3 changes: 3 additions & 0 deletions libcxx/include/__fwd/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, class _Alloc = allocator<_Tp> >
class _LIBCPP_TEMPLATE_VIS vector;

template <class _Allocator>
class vector<bool, _Allocator>;

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___FWD_VECTOR_H
3 changes: 2 additions & 1 deletion libcxx/include/__random/discrete_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
#include <__config>
#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <__vector/vector.h>
#include <cstddef>
#include <initializer_list>
#include <iosfwd>
#include <numeric>
#include <vector>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down
3 changes: 2 additions & 1 deletion libcxx/include/__random/piecewise_constant_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include <__config>
#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <__vector/vector.h>
#include <initializer_list>
#include <iosfwd>
#include <numeric>
#include <vector>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down
4 changes: 3 additions & 1 deletion libcxx/include/__random/piecewise_linear_distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#include <__config>
#include <__random/is_valid.h>
#include <__random/uniform_real_distribution.h>
#include <__vector/comparison.h>
#include <__vector/vector.h>
#include <cmath>
#include <initializer_list>
#include <iosfwd>
#include <vector>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__random/seed_seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include <__type_traits/enable_if.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/is_unsigned.h>
#include <__vector/vector.h>
#include <cstdint>
#include <initializer_list>
#include <vector>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
Expand Down
71 changes: 71 additions & 0 deletions libcxx/include/__vector/comparison.h
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
39 changes: 39 additions & 0 deletions libcxx/include/__vector/container_traits.h
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
50 changes: 50 additions & 0 deletions libcxx/include/__vector/erase.h
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
33 changes: 33 additions & 0 deletions libcxx/include/__vector/pmr.h
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
29 changes: 29 additions & 0 deletions libcxx/include/__vector/swap.h
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
Loading

0 comments on commit 7198233

Please sign in to comment.