diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -130,27 +130,34 @@ __functional/unwrap_ref.h __functional/weak_result_type.h __hash_table + __iterator/access.h __iterator/advance.h __iterator/back_insert_iterator.h __iterator/concepts.h + __iterator/data.h __iterator/default_sentinel.h + __iterator/distance.h + __iterator/empty.h + __iterator/erase_if_container.h __iterator/front_insert_iterator.h __iterator/incrementable_traits.h __iterator/insert_iterator.h - __iterator/istream_iterator.h __iterator/istreambuf_iterator.h + __iterator/istream_iterator.h + __iterator/iterator.h + __iterator/iterator_traits.h __iterator/iter_move.h __iterator/iter_swap.h - __iterator/iterator_traits.h - __iterator/iterator.h __iterator/move_iterator.h __iterator/next.h - __iterator/ostream_iterator.h __iterator/ostreambuf_iterator.h + __iterator/ostream_iterator.h __iterator/prev.h __iterator/projected.h __iterator/readable_traits.h + __iterator/reverse_access.h __iterator/reverse_iterator.h + __iterator/size.h __iterator/wrap_iter.h __libcpp_version __locale diff --git a/libcxx/include/__iterator/access.h b/libcxx/include/__iterator/access.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/access.h @@ -0,0 +1,134 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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___ITERATOR_ACCESS_H +#define _LIBCPP___ITERATOR_ACCESS_H + +#include <__config> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp* +begin(_Tp (&__array)[_Np]) +{ + return __array; +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp* +end(_Tp (&__array)[_Np]) +{ + return __array + _Np; +} + +#if !defined(_LIBCPP_CXX03_LANG) + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +begin(_Cp& __c) -> decltype(__c.begin()) +{ + return __c.begin(); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +begin(const _Cp& __c) -> decltype(__c.begin()) +{ + return __c.begin(); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +end(_Cp& __c) -> decltype(__c.end()) +{ + return __c.end(); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto +end(const _Cp& __c) -> decltype(__c.end()) +{ + return __c.end(); +} + +#if _LIBCPP_STD_VER > 11 + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) +{ + return _VSTD::begin(__c); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) +{ + return _VSTD::end(__c); +} + +#endif + + +#else // defined(_LIBCPP_CXX03_LANG) + +template +_LIBCPP_INLINE_VISIBILITY +typename _Cp::iterator +begin(_Cp& __c) +{ + return __c.begin(); +} + +template +_LIBCPP_INLINE_VISIBILITY +typename _Cp::const_iterator +begin(const _Cp& __c) +{ + return __c.begin(); +} + +template +_LIBCPP_INLINE_VISIBILITY +typename _Cp::iterator +end(_Cp& __c) +{ + return __c.end(); +} + +template +_LIBCPP_INLINE_VISIBILITY +typename _Cp::const_iterator +end(const _Cp& __c) +{ + return __c.end(); +} + +#endif // !defined(_LIBCPP_CXX03_LANG) + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ITERATOR_ACCESS_H diff --git a/libcxx/include/__iterator/back_insert_iterator.h b/libcxx/include/__iterator/back_insert_iterator.h --- a/libcxx/include/__iterator/back_insert_iterator.h +++ b/libcxx/include/__iterator/back_insert_iterator.h @@ -11,11 +11,11 @@ #define _LIBCPP___ITERATOR_BACK_INSERT_ITERATOR_H #include <__config> -#include <__iterator/iterator_traits.h> #include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include <__memory/addressof.h> +#include <__utility/move.h> #include -#include // std::move #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__iterator/data.h b/libcxx/include/__iterator/data.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/data.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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___ITERATOR_DATA_H +#define _LIBCPP___ITERATOR_DATA_H + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template constexpr +_LIBCPP_INLINE_VISIBILITY +auto data(_Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } + +template constexpr +_LIBCPP_INLINE_VISIBILITY +auto data(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.data())) +-> decltype (__c.data()) +{ return __c.data(); } + +template +_LIBCPP_INLINE_VISIBILITY +constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } + +template +_LIBCPP_INLINE_VISIBILITY +constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } + +#endif + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ITERATOR_DATA_H diff --git a/libcxx/include/__iterator/distance.h b/libcxx/include/__iterator/distance.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/distance.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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___ITERATOR_DISTANCE_H +#define _LIBCPP___ITERATOR_DISTANCE_H + +#include <__config> +#include <__iterator/iterator_traits.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_InputIter>::difference_type +__distance(_InputIter __first, _InputIter __last, input_iterator_tag) +{ + typename iterator_traits<_InputIter>::difference_type __r(0); + for (; __first != __last; ++__first) + ++__r; + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_RandIter>::difference_type +__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) +{ + return __last - __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +typename iterator_traits<_InputIter>::difference_type +distance(_InputIter __first, _InputIter __last) +{ + return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ITERATOR_DISTANCE_H diff --git a/libcxx/include/__iterator/empty.h b/libcxx/include/__iterator/empty.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/empty.h @@ -0,0 +1,49 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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___ITERATOR_EMPTY_H +#define _LIBCPP___ITERATOR_EMPTY_H + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY +constexpr auto empty(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.empty())) +-> decltype (__c.empty()) +{ return __c.empty(); } + +template +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY +constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } + +template +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY +constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ITERATOR_EMPTY_H diff --git a/libcxx/include/__iterator/erase_if_container.h b/libcxx/include/__iterator/erase_if_container.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/erase_if_container.h @@ -0,0 +1,44 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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___ITERATOR_ERASE_IF_CONTAINER_H +#define _LIBCPP___ITERATOR_ERASE_IF_CONTAINER_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +typename _Container::size_type +__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { + typename _Container::size_type __old_size = __c.size(); + + const typename _Container::iterator __last = __c.end(); + for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { + if (__pred(*__iter)) + __iter = __c.erase(__iter); + else + ++__iter; + } + + return __old_size - __c.size(); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ITERATOR_ERASE_IF_CONTAINER_H diff --git a/libcxx/include/__iterator/front_insert_iterator.h b/libcxx/include/__iterator/front_insert_iterator.h --- a/libcxx/include/__iterator/front_insert_iterator.h +++ b/libcxx/include/__iterator/front_insert_iterator.h @@ -11,11 +11,11 @@ #define _LIBCPP___ITERATOR_FRONT_INSERT_ITERATOR_H #include <__config> -#include <__iterator/iterator_traits.h> #include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include <__memory/addressof.h> +#include <__utility/move.h> #include -#include // std::move #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__iterator/insert_iterator.h b/libcxx/include/__iterator/insert_iterator.h --- a/libcxx/include/__iterator/insert_iterator.h +++ b/libcxx/include/__iterator/insert_iterator.h @@ -11,11 +11,11 @@ #define _LIBCPP___ITERATOR_INSERT_ITERATOR_H #include <__config> -#include <__iterator/iterator_traits.h> #include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include <__memory/addressof.h> +#include <__utility/move.h> #include -#include // std::move #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header diff --git a/libcxx/include/__iterator/istream_iterator.h b/libcxx/include/__iterator/istream_iterator.h --- a/libcxx/include/__iterator/istream_iterator.h +++ b/libcxx/include/__iterator/istream_iterator.h @@ -11,10 +11,9 @@ #define _LIBCPP___ITERATOR_ISTREAM_ITERATOR_H #include <__config> -#include <__iterator/iterator_traits.h> #include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include <__memory/addressof.h> -#include #include // for forward declarations of char_traits and basic_istream #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__iterator/istreambuf_iterator.h b/libcxx/include/__iterator/istreambuf_iterator.h --- a/libcxx/include/__iterator/istreambuf_iterator.h +++ b/libcxx/include/__iterator/istreambuf_iterator.h @@ -11,8 +11,8 @@ #define _LIBCPP___ITERATOR_ISTREAMBUF_ITERATOR_H #include <__config> -#include <__iterator/iterator_traits.h> #include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include // for forward declaration of basic_streambuf #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__iterator/ostream_iterator.h b/libcxx/include/__iterator/ostream_iterator.h --- a/libcxx/include/__iterator/ostream_iterator.h +++ b/libcxx/include/__iterator/ostream_iterator.h @@ -11,10 +11,9 @@ #define _LIBCPP___ITERATOR_OSTREAM_ITERATOR_H #include <__config> -#include <__iterator/iterator_traits.h> #include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include <__memory/addressof.h> -#include #include // for forward declarations of char_traits and basic_ostream #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__iterator/ostreambuf_iterator.h b/libcxx/include/__iterator/ostreambuf_iterator.h --- a/libcxx/include/__iterator/ostreambuf_iterator.h +++ b/libcxx/include/__iterator/ostreambuf_iterator.h @@ -11,8 +11,8 @@ #define _LIBCPP___ITERATOR_OSTREAMBUF_ITERATOR_H #include <__config> -#include <__iterator/iterator_traits.h> #include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include // for forward declaration of basic_streambuf #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/libcxx/include/__iterator/reverse_access.h b/libcxx/include/__iterator/reverse_access.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/reverse_access.h @@ -0,0 +1,109 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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___ITERATOR_REVERSE_ACCESS_H +#define _LIBCPP___ITERATOR_REVERSE_ACCESS_H + +#include <__config> +#include <__iterator/reverse_iterator.h> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_CXX03_LANG) + +#if _LIBCPP_STD_VER > 11 + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) +{ + return reverse_iterator<_Tp*>(__array + _Np); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) +{ + return reverse_iterator<_Tp*>(__array); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator rbegin(initializer_list<_Ep> __il) +{ + return reverse_iterator(__il.end()); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +reverse_iterator rend(initializer_list<_Ep> __il) +{ + return reverse_iterator(__il.begin()); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) +{ + return __c.rbegin(); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) +{ + return __c.rbegin(); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto rend(_Cp& __c) -> decltype(__c.rend()) +{ + return __c.rend(); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto rend(const _Cp& __c) -> decltype(__c.rend()) +{ + return __c.rend(); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) +{ + return _VSTD::rbegin(__c); +} + +template +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) +{ + return _VSTD::rend(__c); +} + +#endif + +#endif // !defined(_LIBCPP_CXX03_LANG) + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ITERATOR_REVERSE_ACCESS_H diff --git a/libcxx/include/__iterator/reverse_iterator.h b/libcxx/include/__iterator/reverse_iterator.h --- a/libcxx/include/__iterator/reverse_iterator.h +++ b/libcxx/include/__iterator/reverse_iterator.h @@ -11,8 +11,8 @@ #define _LIBCPP___ITERATOR_REVERSE_ITERATOR_H #include <__config> -#include <__iterator/iterator_traits.h> #include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include <__memory/addressof.h> #include diff --git a/libcxx/include/__iterator/size.h b/libcxx/include/__iterator/size.h new file mode 100644 --- /dev/null +++ b/libcxx/include/__iterator/size.h @@ -0,0 +1,58 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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___ITERATOR_SIZE_H +#define _LIBCPP___ITERATOR_SIZE_H + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template +_LIBCPP_INLINE_VISIBILITY +constexpr auto size(const _Cont& __c) +_NOEXCEPT_(noexcept(__c.size())) +-> decltype (__c.size()) +{ return __c.size(); } + +template +_LIBCPP_INLINE_VISIBILITY +constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } + +#if _LIBCPP_STD_VER > 17 +template +_LIBCPP_INLINE_VISIBILITY +constexpr auto ssize(const _Cont& __c) +_NOEXCEPT_(noexcept(static_cast>>(__c.size()))) +-> common_type_t> +{ return static_cast>>(__c.size()); } + +template +_LIBCPP_INLINE_VISIBILITY +constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } +#endif + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___ITERATOR_SIZE_H diff --git a/libcxx/include/iterator b/libcxx/include/iterator --- a/libcxx/include/iterator +++ b/libcxx/include/iterator @@ -561,27 +561,34 @@ #include <__config> #include <__debug> #include <__functional_base> +#include <__iterator/access.h> #include <__iterator/advance.h> #include <__iterator/back_insert_iterator.h> #include <__iterator/concepts.h> +#include <__iterator/data.h> #include <__iterator/default_sentinel.h> +#include <__iterator/distance.h> +#include <__iterator/empty.h> +#include <__iterator/erase_if_container.h> #include <__iterator/front_insert_iterator.h> #include <__iterator/incrementable_traits.h> #include <__iterator/insert_iterator.h> -#include <__iterator/istream_iterator.h> #include <__iterator/istreambuf_iterator.h> +#include <__iterator/istream_iterator.h> +#include <__iterator/iterator.h> +#include <__iterator/iterator_traits.h> #include <__iterator/iter_move.h> #include <__iterator/iter_swap.h> -#include <__iterator/iterator_traits.h> -#include <__iterator/iterator.h> #include <__iterator/move_iterator.h> #include <__iterator/next.h> -#include <__iterator/ostream_iterator.h> #include <__iterator/ostreambuf_iterator.h> +#include <__iterator/ostream_iterator.h> #include <__iterator/prev.h> #include <__iterator/projected.h> #include <__iterator/readable_traits.h> +#include <__iterator/reverse_access.h> #include <__iterator/reverse_iterator.h> +#include <__iterator/size.h> #include <__iterator/wrap_iter.h> #include <__memory/addressof.h> #include <__memory/pointer_traits.h> @@ -597,304 +604,4 @@ #pragma GCC system_header #endif -_LIBCPP_BEGIN_NAMESPACE_STD - -template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -typename iterator_traits<_InputIter>::difference_type -__distance(_InputIter __first, _InputIter __last, input_iterator_tag) -{ - typename iterator_traits<_InputIter>::difference_type __r(0); - for (; __first != __last; ++__first) - ++__r; - return __r; -} - -template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -typename iterator_traits<_RandIter>::difference_type -__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag) -{ - return __last - __first; -} - -template -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -typename iterator_traits<_InputIter>::difference_type -distance(_InputIter __first, _InputIter __last) -{ - return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category()); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -_Tp* -begin(_Tp (&__array)[_Np]) -{ - return __array; -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -_Tp* -end(_Tp (&__array)[_Np]) -{ - return __array + _Np; -} - -#if !defined(_LIBCPP_CXX03_LANG) - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto -begin(_Cp& __c) -> decltype(__c.begin()) -{ - return __c.begin(); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto -begin(const _Cp& __c) -> decltype(__c.begin()) -{ - return __c.begin(); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto -end(_Cp& __c) -> decltype(__c.end()) -{ - return __c.end(); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto -end(const _Cp& __c) -> decltype(__c.end()) -{ - return __c.end(); -} - -#if _LIBCPP_STD_VER > 11 - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) -{ - return reverse_iterator<_Tp*>(__array + _Np); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) -{ - return reverse_iterator<_Tp*>(__array); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -reverse_iterator rbegin(initializer_list<_Ep> __il) -{ - return reverse_iterator(__il.end()); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -reverse_iterator rend(initializer_list<_Ep> __il) -{ - return reverse_iterator(__il.begin()); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) -{ - return _VSTD::begin(__c); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 -auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) -{ - return _VSTD::end(__c); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) -{ - return __c.rbegin(); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) -{ - return __c.rbegin(); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto rend(_Cp& __c) -> decltype(__c.rend()) -{ - return __c.rend(); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto rend(const _Cp& __c) -> decltype(__c.rend()) -{ - return __c.rend(); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) -{ - return _VSTD::rbegin(__c); -} - -template -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 -auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) -{ - return _VSTD::rend(__c); -} - -#endif - - -#else // defined(_LIBCPP_CXX03_LANG) - -template -_LIBCPP_INLINE_VISIBILITY -typename _Cp::iterator -begin(_Cp& __c) -{ - return __c.begin(); -} - -template -_LIBCPP_INLINE_VISIBILITY -typename _Cp::const_iterator -begin(const _Cp& __c) -{ - return __c.begin(); -} - -template -_LIBCPP_INLINE_VISIBILITY -typename _Cp::iterator -end(_Cp& __c) -{ - return __c.end(); -} - -template -_LIBCPP_INLINE_VISIBILITY -typename _Cp::const_iterator -end(const _Cp& __c) -{ - return __c.end(); -} - -#endif // !defined(_LIBCPP_CXX03_LANG) - -#if _LIBCPP_STD_VER > 14 - -// #if _LIBCPP_STD_VER > 11 -// template <> -// struct _LIBCPP_TEMPLATE_VIS plus -// { -// template -// _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -// auto operator()(_T1&& __t, _T2&& __u) const -// _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) -// -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) -// { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } -// typedef void is_transparent; -// }; -// #endif - -template -_LIBCPP_INLINE_VISIBILITY -constexpr auto size(const _Cont& __c) -_NOEXCEPT_(noexcept(__c.size())) --> decltype (__c.size()) -{ return __c.size(); } - -template -_LIBCPP_INLINE_VISIBILITY -constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } - -#if _LIBCPP_STD_VER > 17 -template -_LIBCPP_INLINE_VISIBILITY -constexpr auto ssize(const _Cont& __c) -_NOEXCEPT_(noexcept(static_cast>>(__c.size()))) --> common_type_t> -{ return static_cast>>(__c.size()); } - -template -_LIBCPP_INLINE_VISIBILITY -constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } -#endif - -template -_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY -constexpr auto empty(const _Cont& __c) -_NOEXCEPT_(noexcept(__c.empty())) --> decltype (__c.empty()) -{ return __c.empty(); } - -template -_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY -constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } - -template -_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY -constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } - -template constexpr -_LIBCPP_INLINE_VISIBILITY -auto data(_Cont& __c) -_NOEXCEPT_(noexcept(__c.data())) --> decltype (__c.data()) -{ return __c.data(); } - -template constexpr -_LIBCPP_INLINE_VISIBILITY -auto data(const _Cont& __c) -_NOEXCEPT_(noexcept(__c.data())) --> decltype (__c.data()) -{ return __c.data(); } - -template -_LIBCPP_INLINE_VISIBILITY -constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } - -template -_LIBCPP_INLINE_VISIBILITY -constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } -#endif - -template -typename _Container::size_type -__libcpp_erase_if_container(_Container& __c, _Predicate& __pred) { - typename _Container::size_type __old_size = __c.size(); - - const typename _Container::iterator __last = __c.end(); - for (typename _Container::iterator __iter = __c.begin(); __iter != __last;) { - if (__pred(*__iter)) - __iter = __c.erase(__iter); - else - ++__iter; - } - - return __old_size - __c.size(); -} - -_LIBCPP_END_NAMESPACE_STD - #endif // _LIBCPP_ITERATOR diff --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap --- a/libcxx/include/module.modulemap +++ b/libcxx/include/module.modulemap @@ -474,28 +474,35 @@ export * module __iterator { - module advance { header "__iterator/advance.h" } - module back_insert_iterator { header "__iterator/back_insert_iterator.h" } - module concepts { header "__iterator/concepts.h" } - module default_sentinel { header "__iterator/default_sentinel.h" } - module front_insert_iterator { header "__iterator/front_insert_iterator.h" } - module incrementable_traits { header "__iterator/incrementable_traits.h" } - module insert_iterator { header "__iterator/insert_iterator.h" } - module istream_iterator { header "__iterator/istream_iterator.h" } - module istreambuf_iterator { header "__iterator/istreambuf_iterator.h" } - module iter_move { header "__iterator/iter_move.h" } - module iter_swap { header "__iterator/iter_swap.h" } - module iterator { header "__iterator/iterator.h" } - module iterator_traits { header "__iterator/iterator_traits.h" } - module move_iterator { header "__iterator/move_iterator.h" } - module next { header "__iterator/next.h" } - module ostream_iterator { header "__iterator/ostream_iterator.h" } - module ostreambuf_iterator { header "__iterator/ostreambuf_iterator.h" } - module prev { header "__iterator/prev.h" } - module projected { header "__iterator/projected.h" } - module readable_traits { header "__iterator/readable_traits.h" } - module reverse_iterator { header "__iterator/reverse_iterator.h" } - module wrap_iter { header "__iterator/wrap_iter.h" } + module access { header "__iterator/access.h" } + module advance { header "__iterator/advance.h" } + module back_insert_iterator { header "__iterator/back_insert_iterator.h" } + module concepts { header "__iterator/concepts.h" } + module data { header "__iterator/data.h" } + module default_sentinel { header "__iterator/default_sentinel.h" } + module distance { header "__iterator/distance.h" } + module empty { header "__iterator/empty.h" } + module erase_if_container { header "__iterator/erase_if_container.h" } + module front_insert_iterator { header "__iterator/front_insert_iterator.h" } + module incrementable_traits { header "__iterator/incrementable_traits.h" } + module insert_iterator { header "__iterator/insert_iterator.h" } + module istreambuf_iterator { header "__iterator/istreambuf_iterator.h" } + module istream_iterator { header "__iterator/istream_iterator.h" } + module iterator { header "__iterator/iterator.h" } + module iterator_traits { header "__iterator/iterator_traits.h" } + module iter_move { header "__iterator/iter_move.h" } + module iter_swap { header "__iterator/iter_swap.h" } + module move_iterator { header "__iterator/move_iterator.h" } + module next { header "__iterator/next.h" } + module ostreambuf_iterator { header "__iterator/ostreambuf_iterator.h" } + module ostream_iterator { header "__iterator/ostream_iterator.h" } + module prev { header "__iterator/prev.h" } + module projected { header "__iterator/projected.h" } + module readable_traits { header "__iterator/readable_traits.h" } + module reverse_access { header "__iterator/reverse_access.h" } + module reverse_iterator { header "__iterator/reverse_iterator.h" } + module size { header "__iterator/size.h" } + module wrap_iter { header "__iterator/wrap_iter.h" } } } module latch { diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h --- a/libcxx/test/support/test_iterators.h +++ b/libcxx/test/support/test_iterators.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "test_macros.h"