mclow.lists created this revision.
`__wrap_iter` is an internal libc++ class that is used as an iterator type when
(for some reason) we don't want to use raw pointers as an iterator. It is the
iterator type for `vector` and `string` (but not `array` - not sure why). If we
used pointers, all the operations on the iterators would be constexpr. With
this patch, the corresponding operations on `__wrap_iter` are constexpr as well.
We'll have to do this when
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#2938 is adopted.
No tests, because all the interesting constructors of `__wrap_iter` are
private, and only accessed through friend functions.
I have written tests (after making the appropriate ctors public) and they seem
to work.
https://reviews.llvm.org/D33550
Files:
include/algorithm
include/iterator
Index: include/iterator
===
--- include/iterator
+++ include/iterator
@@ -1199,32 +1199,32 @@
template class __wrap_iter;
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
@@ -1236,13 +1236,13 @@
-> decltype(__x.base() - __y.base());
#else
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename __wrap_iter<_Iter1>::difference_type
operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG;
#endif
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__wrap_iter<_Iter>
operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG;
@@ -1254,7 +1254,7 @@
#if _LIBCPP_DEBUG_LEVEL < 2
template
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
@@ -1265,7 +1265,7 @@
#else
template
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
@@ -1288,7 +1288,8 @@
private:
iterator_type __i;
public:
-_LIBCPP_INLINE_VISIBILITY __wrap_iter() _NOEXCEPT_DEBUG
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+__wrap_iter() _NOEXCEPT_DEBUG
#if _LIBCPP_STD_VER > 11
: __i{}
#endif
@@ -1297,7 +1298,8 @@
__get_db()->__insert_i(this);
#endif
}
-template _LIBCPP_INLINE_VISIBILITY __wrap_iter(const __wrap_iter<_Up>& __u,
+template _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+ __wrap_iter(const __wrap_iter<_Up>& __u,
typename enable_if::value>::type* = 0) _NOEXCEPT_DEBUG
: __i(__u.base())
{
@@ -1306,13 +1308,13 @@
#endif
}
#if _LIBCPP_DEBUG_LEVEL >= 2
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__wrap_iter(const __wrap_iter& __x)
: __i(__x.base())
{
__get_db()->__iterator_copy(this, &__x);
}
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__wrap_iter& operator=(const __wrap_iter& __x)
{
if (this != &__x)
@@ -1328,7 +1330,8 @@
__get_db()->__erase_i(this);
}
#endif
-_LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT_DEBUG
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+reference operator*() const _NOEXCEPT_DEBUG
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
@@ -1336,7 +1339,8 @@
#endif
return *__i;
}
-_LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT_DEBUG
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+pointer operator->() const _NOEXCEPT_DEBUG
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
@@ -1344,7 +1348,8 @@