[libcxx-commits] [PATCH] D110198: [libc++] Fix __wrap_iter to be a proper contiguous iterator.
Arthur O'Dwyer via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 21 13:51:48 PDT 2021
Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, jloser, zoecarver, libc++.
Quuxplusone added a project: libc++.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.
//The latest installment in the ever-evolving saga of `__cpp17_contiguous_iterator`, `__wrap_iter`, and `__unwrap_iter`...//
Instead of overloading `__to_address`, let's specialize `pointer_traits`. Function overloads need to be in scope at the point where they're called, whereas template specializations do not. (User code can provide pointer_traits specializations to be used by already-included library code, so obviously `__wrap_iter` can do the same.)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D110198
Files:
libcxx/include/__iterator/wrap_iter.h
libcxx/test/std/utilities/memory/pointer.conversion/to_address_std_iterators.pass.cpp
Index: libcxx/test/std/utilities/memory/pointer.conversion/to_address_std_iterators.pass.cpp
===================================================================
--- libcxx/test/std/utilities/memory/pointer.conversion/to_address_std_iterators.pass.cpp
+++ libcxx/test/std/utilities/memory/pointer.conversion/to_address_std_iterators.pass.cpp
@@ -10,10 +10,6 @@
// UNSUPPORTED: c++03, c++11, c++14, c++17
-// TODO: We should enable this test in Debug mode once we fix __wrap_iter
-// to be a proper contiguous_iterator.
-// UNSUPPORTED: LIBCXX-DEBUG-FIXME
-
// template <class T> constexpr T* to_address(T* p) noexcept;
// template <class Ptr> constexpr auto to_address(const Ptr& p) noexcept;
Index: libcxx/include/__iterator/wrap_iter.h
===================================================================
--- libcxx/include/__iterator/wrap_iter.h
+++ libcxx/include/__iterator/wrap_iter.h
@@ -13,7 +13,7 @@
#include <__config>
#include <__debug>
#include <__iterator/iterator_traits.h>
-#include <__memory/pointer_traits.h> // __to_address
+#include <__memory/pointer_traits.h>
#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -283,12 +283,33 @@
struct __is_cpp17_contiguous_iterator<__wrap_iter<_It> > : true_type {};
#endif
-template <class _Iter>
-_LIBCPP_CONSTEXPR
-decltype(_VSTD::__to_address(declval<_Iter>()))
-__to_address(__wrap_iter<_Iter> __w) _NOEXCEPT {
- return _VSTD::__to_address(__w.base());
-}
+template <class _It>
+struct _LIBCPP_TEMPLATE_VIS pointer_traits<__wrap_iter<_It> >
+{
+ typedef __wrap_iter<_It> pointer;
+ typedef typename pointer_traits<_It>::element_type element_type;
+ typedef typename pointer_traits<_It>::difference_type difference_type;
+
+#ifndef _LIBCPP_CXX03_LANG
+ template <class _Up> using rebind = _Up*;
+#else
+ template <class _Up> struct rebind {typedef _Up* other;};
+#endif
+
+private:
+ struct __nat {};
+public:
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ static element_type *to_address(pointer __w) _NOEXCEPT {
+ return _VSTD::__to_address(__w.base());
+ }
+
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+ static pointer pointer_to(typename conditional<is_void<element_type>::value,
+ __nat, element_type>::type& __r) _NOEXCEPT {
+ return pointer_traits<_It>::pointer_to(__r);
+ }
+};
_LIBCPP_END_NAMESPACE_STD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110198.374024.patch
Type: text/x-patch
Size: 2420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210921/667b91d8/attachment.bin>
More information about the libcxx-commits
mailing list