Skip to content

Commit a40207a

Browse files
Address review comments
- Drop uses of `is_constructible`. - Generalize to `__static_bounded_iter`. - Improve conditional compilation in test.
1 parent 2780880 commit a40207a

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

libcxx/include/__iterator/bounded_iter.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <__type_traits/disjunction.h>
2121
#include <__type_traits/enable_if.h>
2222
#include <__type_traits/integral_constant.h>
23-
#include <__type_traits/is_constructible.h>
2423
#include <__type_traits/is_convertible.h>
2524
#include <__type_traits/is_same.h>
2625
#include <__type_traits/make_const_lvalue_ref.h>
@@ -77,10 +76,9 @@ struct __bounded_iter {
7776

7877
template < class _OtherIterator,
7978
__enable_if_t<
80-
_And<is_constructible<_Iterator, const _OtherIterator&>,
81-
is_convertible<const _OtherIterator&, _Iterator>,
82-
_Or<is_same<reference, __iter_reference<_OtherIterator> >,
83-
is_same<reference, __make_const_lvalue_ref<__iter_reference<_OtherIterator> > > > >::value,
79+
_And< is_convertible<const _OtherIterator&, _Iterator>,
80+
_Or<is_same<reference, __iter_reference<_OtherIterator> >,
81+
is_same<reference, __make_const_lvalue_ref<__iter_reference<_OtherIterator> > > > >::value,
8482
int> = 0>
8583
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __bounded_iter(__bounded_iter<_OtherIterator> const& __other) _NOEXCEPT
8684
: __current_(__other.__current_),

libcxx/include/__iterator/static_bounded_iter.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
#include <__cstddef/size_t.h>
1818
#include <__iterator/iterator_traits.h>
1919
#include <__memory/pointer_traits.h>
20+
#include <__type_traits/conjunction.h>
21+
#include <__type_traits/disjunction.h>
2022
#include <__type_traits/enable_if.h>
2123
#include <__type_traits/integral_constant.h>
2224
#include <__type_traits/is_convertible.h>
25+
#include <__type_traits/is_same.h>
26+
#include <__type_traits/make_const_lvalue_ref.h>
2327
#include <__utility/move.h>
2428

2529
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -93,7 +97,12 @@ struct __static_bounded_iter {
9397
_LIBCPP_HIDE_FROM_ABI __static_bounded_iter(__static_bounded_iter const&) = default;
9498
_LIBCPP_HIDE_FROM_ABI __static_bounded_iter(__static_bounded_iter&&) = default;
9599

96-
template <class _OtherIterator, __enable_if_t<is_convertible<_OtherIterator, _Iterator>::value, int> = 0>
100+
template <class _OtherIterator,
101+
__enable_if_t<
102+
_And< is_convertible<const _OtherIterator&, _Iterator>,
103+
_Or<is_same<reference, __iter_reference<_OtherIterator> >,
104+
is_same<reference, __make_const_lvalue_ref<__iter_reference<_OtherIterator> > > > >::value,
105+
int> = 0>
97106
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
98107
__static_bounded_iter(__static_bounded_iter<_OtherIterator, _Size> const& __other) _NOEXCEPT
99108
: __storage_(__other.__storage_.__current(), __other.__storage_.__begin()) {}

libcxx/include/__iterator/wrap_iter.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <__type_traits/disjunction.h>
2222
#include <__type_traits/enable_if.h>
2323
#include <__type_traits/integral_constant.h>
24-
#include <__type_traits/is_constructible.h>
2524
#include <__type_traits/is_convertible.h>
2625
#include <__type_traits/is_same.h>
2726
#include <__type_traits/make_const_lvalue_ref.h>
@@ -52,10 +51,9 @@ class __wrap_iter {
5251
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter() _NOEXCEPT : __i_() {}
5352
template <
5453
class _OtherIter,
55-
__enable_if_t< _And<is_constructible<_Iter, const _OtherIter&>,
56-
is_convertible<const _OtherIter&, _Iter>,
57-
_Or<is_same<reference, __iter_reference<_OtherIter> >,
58-
is_same<reference, __make_const_lvalue_ref<__iter_reference<_OtherIter> > > > >::value,
54+
__enable_if_t< _And< is_convertible<const _OtherIter&, _Iter>,
55+
_Or<is_same<reference, __iter_reference<_OtherIter> >,
56+
is_same<reference, __make_const_lvalue_ref<__iter_reference<_OtherIter> > > > >::value,
5957
int> = 0>
6058
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __wrap_iter(const __wrap_iter<_OtherIter>& __u) _NOEXCEPT
6159
: __i_(__u.__i_) {}

libcxx/test/libcxx/iterators/wrap.bounded.iter.conv.compile.pass.cpp renamed to libcxx/test/libcxx/iterators/contiguous_iterators.conv.compile.pass.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,40 @@
1010
// <iterator>
1111

1212
// __bounded_iter<_Iter>
13+
// __static_bounded_iter<_Iter>
1314
// __wrap_iter<_Iter>
1415

1516
// Verify that libc++-wrapped iterators do not permit slicing conversion or construction.
1617

1718
#include <array>
18-
#include <vector>
1919
#include <span>
2020
#include <type_traits>
21+
#include <vector>
2122

2223
#include "test_macros.h"
2324

2425
struct Base {};
2526
struct Derived : Base {};
2627

27-
#ifdef _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
28-
static_assert(!std::is_convertible<std::array<Derived, 1>::iterator, std::array<Base, 1>::iterator>::value, "");
29-
static_assert(!std::is_convertible<std::array<Derived, 1>::iterator, std::array<Base, 1>::const_iterator>::value, "");
30-
static_assert(!std::is_convertible<std::array<Derived, 1>::const_iterator, std::array<Base, 1>::const_iterator>::value,
31-
"");
32-
static_assert(!std::is_constructible<std::array<Base, 1>::iterator, std::array<Derived, 1>::iterator>::value, "");
33-
static_assert(!std::is_constructible<std::array<Base, 1>::const_iterator, std::array<Derived, 1>::iterator>::value, "");
34-
static_assert(
35-
!std::is_constructible<std::array<Base, 1>::const_iterator, std::array<Derived, 1>::const_iterator>::value, "");
36-
#endif
28+
template <class B, class D, bool = std::is_pointer<typename std::array<B, 1>::iterator>::value>
29+
struct test_array_helper : std::true_type {
30+
typedef typename std::array<B, 1>::iterator BaseIter;
31+
typedef typename std::array<D, 1>::iterator DerivedIter;
32+
typedef typename std::array<B, 1>::const_iterator BaseConstIter;
33+
typedef typename std::array<D, 1>::const_iterator DerivedConstIter;
34+
35+
static_assert(!std::is_convertible<DerivedIter, BaseIter>::value, "");
36+
static_assert(!std::is_convertible<DerivedIter, BaseConstIter>::value, "");
37+
static_assert(!std::is_convertible<DerivedConstIter, BaseConstIter>::value, "");
38+
static_assert(!std::is_constructible<BaseIter, DerivedIter>::value, "");
39+
static_assert(!std::is_constructible<BaseConstIter, DerivedIter>::value, "");
40+
static_assert(!std::is_constructible<BaseConstIter, DerivedConstIter>::value, "");
41+
};
42+
43+
template <class B, class D>
44+
struct test_array_helper<B, D, true> : std::true_type {};
45+
46+
static_assert(test_array_helper<Base, Derived>::value, "");
3747

3848
static_assert(!std::is_convertible<std::vector<Derived>::iterator, std::vector<Base>::iterator>::value, "");
3949
static_assert(!std::is_convertible<std::vector<Derived>::iterator, std::vector<Base>::const_iterator>::value, "");

0 commit comments

Comments
 (0)