[libcxx-commits] [libcxx] 8517a26 - [libcxx][modularisation] splices `<iterator>` into individual headers
Christopher Di Bella via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 6 10:59:40 PDT 2021
Author: Christopher Di Bella
Date: 2021-07-06T17:59:21Z
New Revision: 8517a26d442fa1b3d01e52a83ae76023ba7c9784
URL: https://github.com/llvm/llvm-project/commit/8517a26d442fa1b3d01e52a83ae76023ba7c9784
DIFF: https://github.com/llvm/llvm-project/commit/8517a26d442fa1b3d01e52a83ae76023ba7c9784.diff
LOG: [libcxx][modularisation] splices `<iterator>` into individual headers
Differential Revision: https://reviews.llvm.org/D105076
Added:
libcxx/include/__iterator/access.h
libcxx/include/__iterator/data.h
libcxx/include/__iterator/distance.h
libcxx/include/__iterator/empty.h
libcxx/include/__iterator/erase_if_container.h
libcxx/include/__iterator/reverse_access.h
libcxx/include/__iterator/size.h
Modified:
libcxx/include/CMakeLists.txt
libcxx/include/__iterator/back_insert_iterator.h
libcxx/include/__iterator/front_insert_iterator.h
libcxx/include/__iterator/insert_iterator.h
libcxx/include/__iterator/istream_iterator.h
libcxx/include/__iterator/istreambuf_iterator.h
libcxx/include/__iterator/ostream_iterator.h
libcxx/include/__iterator/ostreambuf_iterator.h
libcxx/include/__iterator/reverse_iterator.h
libcxx/include/iterator
libcxx/include/module.modulemap
libcxx/test/support/test_iterators.h
Removed:
################################################################################
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 0db5c47c4fb84..cde0604b1a71d 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -130,27 +130,34 @@ set(files
__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
index 0000000000000..c0576b45902bb
--- /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 <cstddef>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp, size_t _Np>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_Tp*
+begin(_Tp (&__array)[_Np])
+{
+ return __array;
+}
+
+template <class _Tp, size_t _Np>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+_Tp*
+end(_Tp (&__array)[_Np])
+{
+ return __array + _Np;
+}
+
+#if !defined(_LIBCPP_CXX03_LANG)
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto
+begin(_Cp& __c) -> decltype(__c.begin())
+{
+ return __c.begin();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto
+begin(const _Cp& __c) -> decltype(__c.begin())
+{
+ return __c.begin();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto
+end(_Cp& __c) -> decltype(__c.end())
+{
+ return __c.end();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto
+end(const _Cp& __c) -> decltype(__c.end())
+{
+ return __c.end();
+}
+
+#if _LIBCPP_STD_VER > 11
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
+auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
+{
+ return _VSTD::begin(__c);
+}
+
+template <class _Cp>
+_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 <class _Cp>
+_LIBCPP_INLINE_VISIBILITY
+typename _Cp::iterator
+begin(_Cp& __c)
+{
+ return __c.begin();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY
+typename _Cp::const_iterator
+begin(const _Cp& __c)
+{
+ return __c.begin();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY
+typename _Cp::iterator
+end(_Cp& __c)
+{
+ return __c.end();
+}
+
+template <class _Cp>
+_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
index 61ac90dfffcac..f34cb863bc09d 100644
--- 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 <cstddef>
-#include <utility> // 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
index 0000000000000..cd8e37b96b6e4
--- /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 <cstddef>
+#include <initializer_list>
+
+#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 <class _Cont> constexpr
+_LIBCPP_INLINE_VISIBILITY
+auto data(_Cont& __c)
+_NOEXCEPT_(noexcept(__c.data()))
+-> decltype (__c.data())
+{ return __c.data(); }
+
+template <class _Cont> constexpr
+_LIBCPP_INLINE_VISIBILITY
+auto data(const _Cont& __c)
+_NOEXCEPT_(noexcept(__c.data()))
+-> decltype (__c.data())
+{ return __c.data(); }
+
+template <class _Tp, size_t _Sz>
+_LIBCPP_INLINE_VISIBILITY
+constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
+
+template <class _Ep>
+_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
index 0000000000000..33e4af84d36e3
--- /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 <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+typename iterator_traits<_InputIter>::
diff erence_type
+__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
+{
+ typename iterator_traits<_InputIter>::
diff erence_type __r(0);
+ for (; __first != __last; ++__first)
+ ++__r;
+ return __r;
+}
+
+template <class _RandIter>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+typename iterator_traits<_RandIter>::
diff erence_type
+__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
+{
+ return __last - __first;
+}
+
+template <class _InputIter>
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+typename iterator_traits<_InputIter>::
diff erence_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
index 0000000000000..4dd59f5cccbd1
--- /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 <cstddef>
+#include <initializer_list>
+
+#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 <class _Cont>
+_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
+constexpr auto empty(const _Cont& __c)
+_NOEXCEPT_(noexcept(__c.empty()))
+-> decltype (__c.empty())
+{ return __c.empty(); }
+
+template <class _Tp, size_t _Sz>
+_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
+constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
+
+template <class _Ep>
+_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
index 0000000000000..d31f12a211373
--- /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 <class _Container, class _Predicate>
+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
index d5d86f51849cb..0421dd5c4b21f 100644
--- 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 <cstddef>
-#include <utility> // 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
index 40555a4c9d349..265814182475f 100644
--- 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 <cstddef>
-#include <utility> // 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
index 1dd57f0d49cfd..f39faa6d590b9 100644
--- 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 <cstddef>
#include <iosfwd> // 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
index 910d57efc3ba9..119698d54ce92 100644
--- 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 <iosfwd> // 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
index 2615b21b059fd..5b4466c863993 100644
--- 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 <cstddef>
#include <iosfwd> // 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
index 4676fc70ffbeb..90309dacd4298 100644
--- 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 <iosfwd> // 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
index 0000000000000..66cc3568c1c18
--- /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 <cstddef>
+#include <initializer_list>
+
+#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 <class _Tp, size_t _Np>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
+{
+ return reverse_iterator<_Tp*>(__array + _Np);
+}
+
+template <class _Tp, size_t _Np>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
+{
+ return reverse_iterator<_Tp*>(__array);
+}
+
+template <class _Ep>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
+{
+ return reverse_iterator<const _Ep*>(__il.end());
+}
+
+template <class _Ep>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
+{
+ return reverse_iterator<const _Ep*>(__il.begin());
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
+{
+ return __c.rbegin();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
+{
+ return __c.rbegin();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto rend(_Cp& __c) -> decltype(__c.rend())
+{
+ return __c.rend();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto rend(const _Cp& __c) -> decltype(__c.rend())
+{
+ return __c.rend();
+}
+
+template <class _Cp>
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
+{
+ return _VSTD::rbegin(__c);
+}
+
+template <class _Cp>
+_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
index 77f7143b43057..76424a89a19c1 100644
--- 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 <type_traits>
diff --git a/libcxx/include/__iterator/size.h b/libcxx/include/__iterator/size.h
new file mode 100644
index 0000000000000..259424f1d314f
--- /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 <cstddef>
+#include <type_traits>
+
+#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 <class _Cont>
+_LIBCPP_INLINE_VISIBILITY
+constexpr auto size(const _Cont& __c)
+_NOEXCEPT_(noexcept(__c.size()))
+-> decltype (__c.size())
+{ return __c.size(); }
+
+template <class _Tp, size_t _Sz>
+_LIBCPP_INLINE_VISIBILITY
+constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
+
+#if _LIBCPP_STD_VER > 17
+template <class _Cont>
+_LIBCPP_INLINE_VISIBILITY
+constexpr auto ssize(const _Cont& __c)
+_NOEXCEPT_(noexcept(static_cast<common_type_t<ptr
diff _t, make_signed_t<decltype(__c.size())>>>(__c.size())))
+-> common_type_t<ptr
diff _t, make_signed_t<decltype(__c.size())>>
+{ return static_cast<common_type_t<ptr
diff _t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
+
+template <class _Tp, ptr
diff _t _Sz>
+_LIBCPP_INLINE_VISIBILITY
+constexpr ptr
diff _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
index f6b0d2ae0a963..52b04e4cc779c 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -561,27 +561,34 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
#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 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
#pragma GCC system_header
#endif
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-template <class _InputIter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-typename iterator_traits<_InputIter>::
diff erence_type
-__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
-{
- typename iterator_traits<_InputIter>::
diff erence_type __r(0);
- for (; __first != __last; ++__first)
- ++__r;
- return __r;
-}
-
-template <class _RandIter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-typename iterator_traits<_RandIter>::
diff erence_type
-__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
-{
- return __last - __first;
-}
-
-template <class _InputIter>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-typename iterator_traits<_InputIter>::
diff erence_type
-distance(_InputIter __first, _InputIter __last)
-{
- return _VSTD::__distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
-}
-
-template <class _Tp, size_t _Np>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-_Tp*
-begin(_Tp (&__array)[_Np])
-{
- return __array;
-}
-
-template <class _Tp, size_t _Np>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-_Tp*
-end(_Tp (&__array)[_Np])
-{
- return __array + _Np;
-}
-
-#if !defined(_LIBCPP_CXX03_LANG)
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto
-begin(_Cp& __c) -> decltype(__c.begin())
-{
- return __c.begin();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto
-begin(const _Cp& __c) -> decltype(__c.begin())
-{
- return __c.begin();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto
-end(_Cp& __c) -> decltype(__c.end())
-{
- return __c.end();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto
-end(const _Cp& __c) -> decltype(__c.end())
-{
- return __c.end();
-}
-
-#if _LIBCPP_STD_VER > 11
-
-template <class _Tp, size_t _Np>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
-{
- return reverse_iterator<_Tp*>(__array + _Np);
-}
-
-template <class _Tp, size_t _Np>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
-{
- return reverse_iterator<_Tp*>(__array);
-}
-
-template <class _Ep>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
-{
- return reverse_iterator<const _Ep*>(__il.end());
-}
-
-template <class _Ep>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
-{
- return reverse_iterator<const _Ep*>(__il.begin());
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
-{
- return _VSTD::begin(__c);
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
-{
- return _VSTD::end(__c);
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
-{
- return __c.rbegin();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
-{
- return __c.rbegin();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto rend(_Cp& __c) -> decltype(__c.rend())
-{
- return __c.rend();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto rend(const _Cp& __c) -> decltype(__c.rend())
-{
- return __c.rend();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
-auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
-{
- return _VSTD::rbegin(__c);
-}
-
-template <class _Cp>
-_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 <class _Cp>
-_LIBCPP_INLINE_VISIBILITY
-typename _Cp::iterator
-begin(_Cp& __c)
-{
- return __c.begin();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY
-typename _Cp::const_iterator
-begin(const _Cp& __c)
-{
- return __c.begin();
-}
-
-template <class _Cp>
-_LIBCPP_INLINE_VISIBILITY
-typename _Cp::iterator
-end(_Cp& __c)
-{
- return __c.end();
-}
-
-template <class _Cp>
-_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<void>
-// {
-// template <class _T1, class _T2>
-// _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 <class _Cont>
-_LIBCPP_INLINE_VISIBILITY
-constexpr auto size(const _Cont& __c)
-_NOEXCEPT_(noexcept(__c.size()))
--> decltype (__c.size())
-{ return __c.size(); }
-
-template <class _Tp, size_t _Sz>
-_LIBCPP_INLINE_VISIBILITY
-constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
-
-#if _LIBCPP_STD_VER > 17
-template <class _Cont>
-_LIBCPP_INLINE_VISIBILITY
-constexpr auto ssize(const _Cont& __c)
-_NOEXCEPT_(noexcept(static_cast<common_type_t<ptr
diff _t, make_signed_t<decltype(__c.size())>>>(__c.size())))
--> common_type_t<ptr
diff _t, make_signed_t<decltype(__c.size())>>
-{ return static_cast<common_type_t<ptr
diff _t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
-
-template <class _Tp, ptr
diff _t _Sz>
-_LIBCPP_INLINE_VISIBILITY
-constexpr ptr
diff _t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
-#endif
-
-template <class _Cont>
-_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
-constexpr auto empty(const _Cont& __c)
-_NOEXCEPT_(noexcept(__c.empty()))
--> decltype (__c.empty())
-{ return __c.empty(); }
-
-template <class _Tp, size_t _Sz>
-_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
-constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
-
-template <class _Ep>
-_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
-constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
-
-template <class _Cont> constexpr
-_LIBCPP_INLINE_VISIBILITY
-auto data(_Cont& __c)
-_NOEXCEPT_(noexcept(__c.data()))
--> decltype (__c.data())
-{ return __c.data(); }
-
-template <class _Cont> constexpr
-_LIBCPP_INLINE_VISIBILITY
-auto data(const _Cont& __c)
-_NOEXCEPT_(noexcept(__c.data()))
--> decltype (__c.data())
-{ return __c.data(); }
-
-template <class _Tp, size_t _Sz>
-_LIBCPP_INLINE_VISIBILITY
-constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
-
-template <class _Ep>
-_LIBCPP_INLINE_VISIBILITY
-constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
-#endif
-
-template <class _Container, class _Predicate>
-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
index 78d28890517ea..5c0b0f9bd2b9e 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -474,28 +474,35 @@ module std [system] {
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
index 51627178e6d32..6e6480f17b0d9 100644
--- a/libcxx/test/support/test_iterators.h
+++ b/libcxx/test/support/test_iterators.h
@@ -13,6 +13,7 @@
#include <stdexcept>
#include <cstddef>
#include <cassert>
+#include <utility>
#include "test_macros.h"
More information about the libcxx-commits
mailing list