[libcxx-commits] [libcxx] e0adf7e - [libc++][NFC] Move incrementable_traits and indirectly_readable_traits into separate headers.

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 19 11:31:42 PDT 2021


Author: zoecarver
Date: 2021-04-19T14:31:30-04:00
New Revision: e0adf7e06a9e329327db2c5e9809e1cbf2e7208d

URL: https://github.com/llvm/llvm-project/commit/e0adf7e06a9e329327db2c5e9809e1cbf2e7208d
DIFF: https://github.com/llvm/llvm-project/commit/e0adf7e06a9e329327db2c5e9809e1cbf2e7208d.diff

LOG: [libc++][NFC] Move incrementable_traits and indirectly_readable_traits into separate headers.

Differential Revision: https://reviews.llvm.org/D100682

Added: 
    libcxx/include/__iterator/concepts.h
    libcxx/include/__iterator/incrementable_traits.h
    libcxx/include/__iterator/readable_traits.h

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/concepts
    libcxx/include/iterator

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 683f790c9a473..3014f21f44e44 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -11,6 +11,9 @@ set(files
   __functional_base
   __functional_base_03
   __hash_table
+  __iterator/concepts.h
+  __iterator/incrementable_traits.h
+  __iterator/readable_traits.h
   __libcpp_version
   __locale
   __memory/addressof.h

diff  --git a/libcxx/include/__iterator/concepts.h b/libcxx/include/__iterator/concepts.h
new file mode 100644
index 0000000000000..c02944f1a1f12
--- /dev/null
+++ b/libcxx/include/__iterator/concepts.h
@@ -0,0 +1,46 @@
+// -*- 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_CONCEPTS_H
+#define _LIBCPP___ITERATOR_CONCEPTS_H
+
+#include <__config>
+#include <concepts>
+
+#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_HAS_NO_RANGES)
+
+template<class _Tp>
+using __with_reference = _Tp&;
+
+template<class _Tp>
+concept __referenceable = requires {
+  typename __with_reference<_Tp>;
+};
+
+template<class _Tp>
+concept __dereferenceable = requires(_Tp& __t) {
+  { *__t } -> __referenceable; // not required to be equality-preserving
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ITERATOR_CONCEPTS_H

diff  --git a/libcxx/include/__iterator/incrementable_traits.h b/libcxx/include/__iterator/incrementable_traits.h
new file mode 100644
index 0000000000000..2a7dff8cea53f
--- /dev/null
+++ b/libcxx/include/__iterator/incrementable_traits.h
@@ -0,0 +1,65 @@
+// -*- 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_INCREMENTABLE_TRAITS_H
+#define _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H
+
+#include <__config>
+#include <__iterator/concepts.h>
+
+#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_HAS_NO_RANGES)
+
+// [incrementable.traits]
+template<class> struct incrementable_traits {};
+
+template<class _Tp>
+requires is_object_v<_Tp>
+struct incrementable_traits<_Tp*> {
+  using 
diff erence_type = ptr
diff _t;
+};
+
+template<class _Ip>
+struct incrementable_traits<const _Ip> : incrementable_traits<_Ip> {};
+
+template<class _Tp>
+concept __has_member_
diff erence_type = requires { typename _Tp::
diff erence_type; };
+
+template<__has_member_
diff erence_type _Tp>
+struct incrementable_traits<_Tp> {
+  using 
diff erence_type = typename _Tp::
diff erence_type;
+};
+
+template<class _Tp>
+concept __has_integral_minus =
+  requires(const _Tp& __x, const _Tp& __y) {
+    { __x - __y } -> integral;
+  };
+
+template<__has_integral_minus _Tp>
+requires (!__has_member_
diff erence_type<_Tp>)
+struct incrementable_traits<_Tp> {
+  using 
diff erence_type = make_signed_t<decltype(declval<_Tp>() - declval<_Tp>())>;
+};
+
+#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ITERATOR_INCREMENTABLE_TRAITS_H

diff  --git a/libcxx/include/__iterator/readable_traits.h b/libcxx/include/__iterator/readable_traits.h
new file mode 100644
index 0000000000000..c2a78e727c8df
--- /dev/null
+++ b/libcxx/include/__iterator/readable_traits.h
@@ -0,0 +1,79 @@
+// -*- 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_READABLE_TRAITS_H
+#define _LIBCPP___ITERATOR_READABLE_TRAITS_H
+
+#include <__config>
+#include <__iterator/concepts.h>
+
+#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_HAS_NO_RANGES)
+
+// [readable.traits]
+template<class> struct __cond_value_type {};
+
+template<class _Tp>
+requires is_object_v<_Tp>
+struct __cond_value_type<_Tp> { using value_type = remove_cv_t<_Tp>; };
+
+template<class _Tp>
+concept __has_member_value_type = requires { typename _Tp::value_type; };
+
+template<class _Tp>
+concept __has_member_element_type = requires { typename _Tp::element_type; };
+
+template<class> struct indirectly_readable_traits {};
+
+template<class _Ip>
+requires is_array_v<_Ip>
+struct indirectly_readable_traits<_Ip> {
+  using value_type = remove_cv_t<remove_extent_t<_Ip>>;
+};
+
+template<class _Ip>
+struct indirectly_readable_traits<const _Ip> : indirectly_readable_traits<_Ip> {};
+
+template<class _Tp>
+struct indirectly_readable_traits<_Tp*> : __cond_value_type<_Tp> {};
+
+template<__has_member_value_type _Tp>
+struct indirectly_readable_traits<_Tp>
+  : __cond_value_type<typename _Tp::value_type> {};
+
+template<__has_member_element_type _Tp>
+struct indirectly_readable_traits<_Tp>
+  : __cond_value_type<typename _Tp::element_type> {};
+
+// Pre-emptively applies LWG3541
+template<__has_member_value_type _Tp>
+requires __has_member_element_type<_Tp>
+struct indirectly_readable_traits<_Tp> {};
+template<__has_member_value_type _Tp>
+requires __has_member_element_type<_Tp> &&
+         same_as<remove_cv_t<typename _Tp::element_type>,
+                 remove_cv_t<typename _Tp::value_type>>
+struct indirectly_readable_traits<_Tp>
+  : __cond_value_type<typename _Tp::value_type> {};
+
+#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+_LIBCPP_POP_MACROS
+
+#endif // _LIBCPP___ITERATOR_READABLE_TRAITS_H

diff  --git a/libcxx/include/concepts b/libcxx/include/concepts
index 7127f289b7932..295733b82a84f 100644
--- a/libcxx/include/concepts
+++ b/libcxx/include/concepts
@@ -439,6 +439,7 @@ concept equivalence_relation = relation<_Rp, _Tp, _Up>;
 // [concept.strictweakorder]
 template<class _Rp, class _Tp, class _Up>
 concept strict_weak_order = relation<_Rp, _Tp, _Up>;
+
 #endif //_LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
 
 _LIBCPP_END_NAMESPACE_STD

diff  --git a/libcxx/include/iterator b/libcxx/include/iterator
index c94d275ae2765..3158cf0b51040 100644
--- a/libcxx/include/iterator
+++ b/libcxx/include/iterator
@@ -429,6 +429,8 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
 #include <concepts>
 #include <cstddef>
 #include <initializer_list>
+#include <__iterator/incrementable_traits.h>
+#include <__iterator/readable_traits.h>
 #include <__memory/addressof.h>
 #include <__memory/pointer_traits.h>
 #include <version>
@@ -443,99 +445,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if !defined(_LIBCPP_HAS_NO_RANGES)
 
-template<class _Tp>
-using __with_reference = _Tp&;
-
-template<class _Tp>
-concept __referenceable = requires {
-  typename __with_reference<_Tp>;
-};
-
-template<class _Tp>
-concept __dereferenceable = requires(_Tp& __t) {
-  { *__t } -> __referenceable; // not required to be equality-preserving
-};
-
-// [incrementable.traits]
-template<class> struct incrementable_traits {};
-
-template<class _Tp>
-requires is_object_v<_Tp>
-struct incrementable_traits<_Tp*> {
-  using 
diff erence_type = ptr
diff _t;
-};
-
-template<class _Ip>
-struct incrementable_traits<const _Ip> : incrementable_traits<_Ip> {};
-
-template<class _Tp>
-concept __has_member_
diff erence_type = requires { typename _Tp::
diff erence_type; };
-
-template<__has_member_
diff erence_type _Tp>
-struct incrementable_traits<_Tp> {
-  using 
diff erence_type = typename _Tp::
diff erence_type;
-};
-
-template<class _Tp>
-concept __has_integral_minus =
-  requires(const _Tp& __x, const _Tp& __y) {
-    { __x - __y } -> integral;
-  };
-
-template<__has_integral_minus _Tp>
-requires (!__has_member_
diff erence_type<_Tp>)
-struct incrementable_traits<_Tp> {
-  using 
diff erence_type = make_signed_t<decltype(declval<_Tp>() - declval<_Tp>())>;
-};
-
-// TODO(cjdb): add iter_
diff erence_t once iterator_traits is cleaned up.
-
-// [readable.traits]
-template<class> struct __cond_value_type {};
-
-template<class _Tp>
-requires is_object_v<_Tp>
-struct __cond_value_type<_Tp> { using value_type = remove_cv_t<_Tp>; };
-
-template<class _Tp>
-concept __has_member_value_type = requires { typename _Tp::value_type; };
-
-template<class _Tp>
-concept __has_member_element_type = requires { typename _Tp::element_type; };
-
-template<class> struct indirectly_readable_traits {};
-
-template<class _Ip>
-requires is_array_v<_Ip>
-struct indirectly_readable_traits<_Ip> {
-  using value_type = remove_cv_t<remove_extent_t<_Ip>>;
-};
-
-template<class _Ip>
-struct indirectly_readable_traits<const _Ip> : indirectly_readable_traits<_Ip> {};
-
-template<class _Tp>
-struct indirectly_readable_traits<_Tp*> : __cond_value_type<_Tp> {};
-
-template<__has_member_value_type _Tp>
-struct indirectly_readable_traits<_Tp>
-  : __cond_value_type<typename _Tp::value_type> {};
-
-template<__has_member_element_type _Tp>
-struct indirectly_readable_traits<_Tp>
-  : __cond_value_type<typename _Tp::element_type> {};
-
-// Pre-emptively applies LWG3541
-template<__has_member_value_type _Tp>
-requires __has_member_element_type<_Tp>
-struct indirectly_readable_traits<_Tp> {};
-template<__has_member_value_type _Tp>
-requires __has_member_element_type<_Tp> &&
-         same_as<remove_cv_t<typename _Tp::element_type>,
-                 remove_cv_t<typename _Tp::value_type>>
-struct indirectly_readable_traits<_Tp>
-  : __cond_value_type<typename _Tp::value_type> {};
-
 // [iterator.traits]
 template<__dereferenceable _Tp>
 using iter_reference_t = decltype(*declval<_Tp&>());


        


More information about the libcxx-commits mailing list