forked from OSchip/llvm-project
[libc++] Use __is_exactly_{input, forward}_iterator
Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D128646
This commit is contained in:
parent
b69c75d53f
commit
00927334df
|
@ -475,6 +475,12 @@ struct __is_exactly_cpp17_input_iterator
|
|||
__has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
|
||||
!__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __is_exactly_cpp17_forward_iterator
|
||||
: public integral_constant<bool,
|
||||
__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value &&
|
||||
!__has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag>::value> {};
|
||||
|
||||
template<class _InputIterator>
|
||||
using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
void __construct_at_end(size_type __n);
|
||||
void __construct_at_end(size_type __n, const_reference __x);
|
||||
template <class _InputIter>
|
||||
__enable_if_t<__is_cpp17_input_iterator<_InputIter>::value && !__is_cpp17_forward_iterator<_InputIter>::value>
|
||||
__enable_if_t<__is_exactly_cpp17_input_iterator<_InputIter>::value>
|
||||
__construct_at_end(_InputIter __first, _InputIter __last);
|
||||
template <class _ForwardIterator>
|
||||
__enable_if_t<__is_cpp17_forward_iterator<_ForwardIterator>::value>
|
||||
|
|
|
@ -1464,12 +1464,10 @@ public:
|
|||
iterator insert(const_iterator __p, size_type __n, const value_type& __v);
|
||||
template <class _InputIter>
|
||||
iterator insert(const_iterator __p, _InputIter __f, _InputIter __l,
|
||||
typename enable_if<__is_cpp17_input_iterator<_InputIter>::value
|
||||
&&!__is_cpp17_forward_iterator<_InputIter>::value>::type* = 0);
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIter>::value>::type* = 0);
|
||||
template <class _ForwardIterator>
|
||||
iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
|
||||
typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value
|
||||
&&!__is_cpp17_bidirectional_iterator<_ForwardIterator>::value>::type* = 0);
|
||||
typename enable_if<__is_exactly_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
|
||||
template <class _BiIter>
|
||||
iterator insert(const_iterator __p, _BiIter __f, _BiIter __l,
|
||||
typename enable_if<__is_cpp17_bidirectional_iterator<_BiIter>::value>::type* = 0);
|
||||
|
@ -1556,8 +1554,7 @@ public:
|
|||
|
||||
template <class _InpIter>
|
||||
void __append(_InpIter __f, _InpIter __l,
|
||||
typename enable_if<__is_cpp17_input_iterator<_InpIter>::value &&
|
||||
!__is_cpp17_forward_iterator<_InpIter>::value>::type* = 0);
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InpIter>::value>::type* = 0);
|
||||
template <class _ForIter>
|
||||
void __append(_ForIter __f, _ForIter __l,
|
||||
typename enable_if<__is_cpp17_forward_iterator<_ForIter>::value>::type* = 0);
|
||||
|
@ -2266,8 +2263,7 @@ template <class _Tp, class _Allocator>
|
|||
template <class _InputIter>
|
||||
typename deque<_Tp, _Allocator>::iterator
|
||||
deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l,
|
||||
typename enable_if<__is_cpp17_input_iterator<_InputIter>::value
|
||||
&&!__is_cpp17_forward_iterator<_InputIter>::value>::type*)
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIter>::value>::type*)
|
||||
{
|
||||
__split_buffer<value_type, allocator_type&> __buf(__base::__alloc());
|
||||
__buf.__construct_at_end(__f, __l);
|
||||
|
@ -2279,8 +2275,7 @@ template <class _Tp, class _Allocator>
|
|||
template <class _ForwardIterator>
|
||||
typename deque<_Tp, _Allocator>::iterator
|
||||
deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
|
||||
typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value
|
||||
&&!__is_cpp17_bidirectional_iterator<_ForwardIterator>::value>::type*)
|
||||
typename enable_if<__is_exactly_cpp17_forward_iterator<_ForwardIterator>::value>::type*)
|
||||
{
|
||||
size_type __n = _VSTD::distance(__f, __l);
|
||||
__split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc());
|
||||
|
@ -2362,8 +2357,7 @@ template <class _Tp, class _Allocator>
|
|||
template <class _InpIter>
|
||||
void
|
||||
deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l,
|
||||
typename enable_if<__is_cpp17_input_iterator<_InpIter>::value &&
|
||||
!__is_cpp17_forward_iterator<_InpIter>::value>::type*)
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InpIter>::value>::type*)
|
||||
{
|
||||
for (; __f != __l; ++__f)
|
||||
#ifdef _LIBCPP_CXX03_LANG
|
||||
|
|
|
@ -2748,12 +2748,7 @@ public:
|
|||
|
||||
template <class _InputIterator>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value,
|
||||
basic_regex&
|
||||
>::type
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value, basic_regex&>::type
|
||||
assign(_InputIterator __first, _InputIterator __last,
|
||||
flag_type __f = regex_constants::ECMAScript)
|
||||
{
|
||||
|
|
|
@ -393,16 +393,14 @@ public:
|
|||
|
||||
template <class _InputIterator>
|
||||
vector(_InputIterator __first,
|
||||
typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value &&
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
|
||||
is_constructible<
|
||||
value_type,
|
||||
typename iterator_traits<_InputIterator>::reference>::value,
|
||||
_InputIterator>::type __last);
|
||||
template <class _InputIterator>
|
||||
vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
|
||||
typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value &&
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
|
||||
is_constructible<
|
||||
value_type,
|
||||
typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
|
||||
|
@ -465,10 +463,7 @@ public:
|
|||
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
|
||||
|
||||
template <class _InputIterator>
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value &&
|
||||
typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
|
||||
is_constructible<
|
||||
value_type,
|
||||
typename iterator_traits<_InputIterator>::reference>::value,
|
||||
|
@ -598,10 +593,7 @@ public:
|
|||
|
||||
iterator insert(const_iterator __position, size_type __n, const_reference __x);
|
||||
template <class _InputIterator>
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value &&
|
||||
typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
|
||||
is_constructible<
|
||||
value_type,
|
||||
typename iterator_traits<_InputIterator>::reference>::value,
|
||||
|
@ -1090,8 +1082,7 @@ vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
|
|||
template <class _Tp, class _Allocator>
|
||||
template <class _InputIterator>
|
||||
vector<_Tp, _Allocator>::vector(_InputIterator __first,
|
||||
typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value &&
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
|
||||
is_constructible<
|
||||
value_type,
|
||||
typename iterator_traits<_InputIterator>::reference>::value,
|
||||
|
@ -1105,8 +1096,7 @@ vector<_Tp, _Allocator>::vector(_InputIterator __first,
|
|||
template <class _Tp, class _Allocator>
|
||||
template <class _InputIterator>
|
||||
vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
|
||||
typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value &&
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
|
||||
is_constructible<
|
||||
value_type,
|
||||
typename iterator_traits<_InputIterator>::reference>::value>::type*)
|
||||
|
@ -1301,10 +1291,7 @@ vector<_Tp, _Allocator>::operator=(const vector& __x)
|
|||
|
||||
template <class _Tp, class _Allocator>
|
||||
template <class _InputIterator>
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value &&
|
||||
typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
|
||||
is_constructible<
|
||||
_Tp,
|
||||
typename iterator_traits<_InputIterator>::reference>::value,
|
||||
|
@ -1751,10 +1738,7 @@ vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_
|
|||
|
||||
template <class _Tp, class _Allocator>
|
||||
template <class _InputIterator>
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value &&
|
||||
typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value &&
|
||||
is_constructible<
|
||||
_Tp,
|
||||
typename iterator_traits<_InputIterator>::reference>::value,
|
||||
|
@ -2057,12 +2041,10 @@ public:
|
|||
vector(size_type __n, const value_type& __v, const allocator_type& __a);
|
||||
template <class _InputIterator>
|
||||
vector(_InputIterator __first, _InputIterator __last,
|
||||
typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0);
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
|
||||
template <class _InputIterator>
|
||||
vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
|
||||
typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0);
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type* = 0);
|
||||
template <class _ForwardIterator>
|
||||
vector(_ForwardIterator __first, _ForwardIterator __last,
|
||||
typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0);
|
||||
|
@ -2097,10 +2079,7 @@ public:
|
|||
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
|
||||
|
||||
template <class _InputIterator>
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator<_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value,
|
||||
typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
|
||||
void
|
||||
>::type
|
||||
assign(_InputIterator __first, _InputIterator __last);
|
||||
|
@ -2212,10 +2191,7 @@ public:
|
|||
iterator insert(const_iterator __position, const value_type& __x);
|
||||
iterator insert(const_iterator __position, size_type __n, const value_type& __x);
|
||||
template <class _InputIterator>
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value,
|
||||
typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
|
||||
iterator
|
||||
>::type
|
||||
insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
|
||||
|
@ -2522,8 +2498,7 @@ vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const all
|
|||
template <class _Allocator>
|
||||
template <class _InputIterator>
|
||||
vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
|
||||
typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value>::type*)
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
|
||||
: __begin_(nullptr),
|
||||
__size_(0),
|
||||
__cap_alloc_(0, __default_init_tag())
|
||||
|
@ -2549,8 +2524,7 @@ vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
|
|||
template <class _Allocator>
|
||||
template <class _InputIterator>
|
||||
vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
|
||||
typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value>::type*)
|
||||
typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value>::type*)
|
||||
: __begin_(nullptr),
|
||||
__size_(0),
|
||||
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
|
||||
|
@ -2787,10 +2761,7 @@ vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
|
|||
|
||||
template <class _Allocator>
|
||||
template <class _InputIterator>
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator<_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value,
|
||||
typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
|
||||
void
|
||||
>::type
|
||||
vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
|
||||
|
@ -2941,10 +2912,7 @@ vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const
|
|||
|
||||
template <class _Allocator>
|
||||
template <class _InputIterator>
|
||||
typename enable_if
|
||||
<
|
||||
__is_cpp17_input_iterator <_InputIterator>::value &&
|
||||
!__is_cpp17_forward_iterator<_InputIterator>::value,
|
||||
typename enable_if <__is_exactly_cpp17_input_iterator<_InputIterator>::value,
|
||||
typename vector<bool, _Allocator>::iterator
|
||||
>::type
|
||||
vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
|
||||
|
|
|
@ -106,13 +106,13 @@ void basic_test()
|
|||
#endif
|
||||
}
|
||||
|
||||
template <class It>
|
||||
void test_emplacable_concept() {
|
||||
#if TEST_STD_VER >= 11
|
||||
int arr1[] = {42};
|
||||
int arr2[] = {1, 101, 42};
|
||||
{
|
||||
using T = EmplaceConstructibleMoveableAndAssignable<int>;
|
||||
using It = random_access_iterator<int*>;
|
||||
{
|
||||
std::deque<T> v;
|
||||
v.assign(It(arr1), It(std::end(arr1)));
|
||||
|
@ -126,32 +126,22 @@ void test_emplacable_concept() {
|
|||
assert(v[2].value == 42);
|
||||
}
|
||||
}
|
||||
{
|
||||
using T = EmplaceConstructibleMoveableAndAssignable<int>;
|
||||
using It = cpp17_input_iterator<int*>;
|
||||
{
|
||||
std::deque<T> v;
|
||||
v.assign(It(arr1), It(std::end(arr1)));
|
||||
assert(v[0].copied == 0);
|
||||
assert(v[0].value == 42);
|
||||
}
|
||||
{
|
||||
std::deque<T> v;
|
||||
v.assign(It(arr2), It(std::end(arr2)));
|
||||
//assert(v[0].copied == 0);
|
||||
assert(v[0].value == 1);
|
||||
//assert(v[1].copied == 0);
|
||||
assert(v[1].value == 101);
|
||||
assert(v[2].copied == 0);
|
||||
assert(v[2].value == 42);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_iterators() {
|
||||
test_emplacable_concept<cpp17_input_iterator<int*> >();
|
||||
test_emplacable_concept<forward_iterator<int*> >();
|
||||
test_emplacable_concept<bidirectional_iterator<int*> >();
|
||||
test_emplacable_concept<random_access_iterator<int*> >();
|
||||
#if TEST_STD_VER > 17
|
||||
test_emplacable_concept<contiguous_iterator<int*> >();
|
||||
#endif
|
||||
test_emplacable_concept<int*>();
|
||||
}
|
||||
|
||||
int main(int, char**) {
|
||||
basic_test();
|
||||
test_emplacable_concept();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue