Implement n3607: 'equal', 'mismatch', and 'is_permutation'

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@181548 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow 2013-05-09 21:14:23 +00:00
parent 5328cd307c
commit b30abdd07a
7 changed files with 982 additions and 0 deletions

View File

@ -87,30 +87,63 @@ template <class InputIterator1, class InputIterator2>
pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
template <class InputIterator1, class InputIterator2>
pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2); // **C++14**
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate pred);
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
BinaryPredicate pred); // **C++14**
template <class InputIterator1, class InputIterator2>
bool
equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
template <class InputIterator1, class InputIterator2>
bool
equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2); // **C++14**
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
bool
equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate pred);
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
bool
equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
BinaryPredicate pred); // **C++14**
template<class ForwardIterator1, class ForwardIterator2>
bool
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
template<class ForwardIterator1, class ForwardIterator2>
bool
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
bool
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, BinaryPredicate pred);
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
bool
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred); // **C++14**
template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator1
search(ForwardIterator1 first1, ForwardIterator1 last1,
@ -1087,6 +1120,32 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>());
}
#if _LIBCPP_STD_VER > 11
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
inline _LIBCPP_INLINE_VISIBILITY
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2,
_BinaryPredicate __pred)
{
for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
if (!__pred(*__first1, *__first2))
break;
return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
}
template <class _InputIterator1, class _InputIterator2>
inline _LIBCPP_INLINE_VISIBILITY
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
{
typedef typename iterator_traits<_InputIterator1>::value_type __v1;
typedef typename iterator_traits<_InputIterator2>::value_type __v2;
return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
}
#endif
// equal
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
@ -1110,6 +1169,60 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>());
}
#if _LIBCPP_STD_VER > 11
template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2>
inline _LIBCPP_INLINE_VISIBILITY
bool
__equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred,
input_iterator_tag, input_iterator_tag )
{
for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
if (!__pred(*__first1, *__first2))
return false;
return __first1 == __last1 && __first2 == __last2;
}
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
inline _LIBCPP_INLINE_VISIBILITY
bool
__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
random_access_iterator_tag, random_access_iterator_tag )
{
if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
return false;
return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2,
typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __pred );
}
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
inline _LIBCPP_INLINE_VISIBILITY
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred )
{
return _VSTD::__equal<typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __last2, __pred,
typename iterator_traits<_InputIterator1>::iterator_category(),
typename iterator_traits<_InputIterator2>::iterator_category());
}
template <class _InputIterator1, class _InputIterator2>
inline _LIBCPP_INLINE_VISIBILITY
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
{
typedef typename iterator_traits<_InputIterator1>::value_type __v1;
typedef typename iterator_traits<_InputIterator2>::value_type __v2;
return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(),
typename iterator_traits<_InputIterator1>::iterator_category(),
typename iterator_traits<_InputIterator2>::iterator_category());
}
#endif
// is_permutation
template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
@ -1169,6 +1282,100 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
return _VSTD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>());
}
#if _LIBCPP_STD_VER > 11
template<class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
bool
__is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __pred,
forward_iterator_tag, forward_iterator_tag )
{
// shorten sequences as much as possible by lopping of any equal parts
for (; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
if (!__pred(*__first1, *__first2))
goto __not_done;
return __first1 == __last1 && __first2 == __last2;
__not_done:
// __first1 != __last1 && __first2 != __last2 && *__first1 != *__first2
typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1;
_D1 __l1 = _VSTD::distance(__first1, __last1);
typedef typename iterator_traits<_ForwardIterator2>::difference_type _D2;
_D1 __l2 = _VSTD::distance(__first2, __last2);
if (__l1 != __l2)
return false;
// For each element in [f1, l1) see if there are the same number of
// equal elements in [f2, l2)
for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
{
// Have we already counted the number of *__i in [f1, l1)?
for (_ForwardIterator1 __j = __first1; __j != __i; ++__j)
if (__pred(*__j, *__i))
goto __next_iter;
{
// Count number of *__i in [f2, l2)
_D1 __c2 = 0;
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
if (__pred(*__i, *__j))
++__c2;
if (__c2 == 0)
return false;
// Count number of *__i in [__i, l1) (we can start with 1)
_D1 __c1 = 1;
for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j)
if (__pred(*__i, *__j))
++__c1;
if (__c1 != __c2)
return false;
}
__next_iter:;
}
return true;
}
template<class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
bool
__is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1,
_RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2,
_BinaryPredicate __pred,
random_access_iterator_tag, random_access_iterator_tag )
{
if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
return false;
return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2,
typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __pred );
}
template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
inline _LIBCPP_INLINE_VISIBILITY
bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __pred )
{
return _VSTD::__is_permutation<typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __last2, __pred,
typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category());
}
template<class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY
bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
return _VSTD::__is_permutation(__first1, __last1, __first2, __last2,
__equal_to<__v1, __v2>(),
typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category());
}
#endif
// search
template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>

View File

@ -19,6 +19,10 @@
#include "test_iterators.h"
#if _LIBCPP_STD_VER > 11
#define HAS_FOUR_ITERATOR_VERSION
#endif
int main()
{
int ia[] = {0, 1, 2, 3, 4, 5};
@ -27,7 +31,36 @@ int main()
assert(std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ia)));
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s)));
assert(std::equal(random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s),
random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s)));
#endif
assert(!std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ib)));
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(!std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ib),
input_iterator<const int*>(ib+s)));
assert(!std::equal(random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s),
random_access_iterator<const int*>(ib),
random_access_iterator<const int*>(ib+s)));
assert(!std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s-1)));
assert(!std::equal(random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s),
random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s-1)));
#endif
}

View File

@ -21,6 +21,17 @@
#include "test_iterators.h"
#if _LIBCPP_STD_VER > 11
#define HAS_FOUR_ITERATOR_VERSION
#endif
int comparison_count = 0;
template <typename T>
bool counting_equals ( const T &a, const T &b ) {
++comparison_count;
return a == b;
}
int main()
{
int ia[] = {0, 1, 2, 3, 4, 5};
@ -30,8 +41,47 @@ int main()
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ia),
std::equal_to<int>()));
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
std::equal_to<int>()));
assert(std::equal(random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s),
random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s),
std::equal_to<int>()));
comparison_count = 0;
assert(!std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s-1),
counting_equals<int>));
assert(comparison_count > 0);
comparison_count = 0;
assert(!std::equal(random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s),
random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s-1),
counting_equals<int>));
assert(comparison_count == 0);
#endif
assert(!std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ib),
std::equal_to<int>()));
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(!std::equal(input_iterator<const int*>(ia),
input_iterator<const int*>(ia+s),
input_iterator<const int*>(ib),
input_iterator<const int*>(ib+s),
std::equal_to<int>()));
assert(!std::equal(random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia+s),
random_access_iterator<const int*>(ib),
random_access_iterator<const int*>(ib+s),
std::equal_to<int>()));
#endif
}

View File

@ -19,6 +19,10 @@
#include "test_iterators.h"
#if _LIBCPP_STD_VER > 11
#define HAS_FOUR_ITERATOR_VERSION
#endif
int main()
{
{
@ -28,9 +32,25 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + 0),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + 0),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + 0)) == true);
#endif
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0};
@ -39,6 +59,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
@ -48,6 +74,16 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 0};
@ -56,6 +92,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0};
@ -64,6 +106,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0};
@ -72,6 +120,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 1};
@ -80,6 +134,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 1};
@ -88,6 +148,16 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 1};
@ -96,6 +166,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
#endif
}
{
const int ia[] = {0, 1};
@ -104,6 +180,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {1, 0};
@ -112,6 +194,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {1, 0};
@ -120,6 +208,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
#endif
}
{
const int ia[] = {1, 0};
@ -128,6 +222,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
#endif
}
{
const int ia[] = {1, 0};
@ -136,6 +236,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {1, 1};
@ -144,6 +250,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {1, 1};
@ -152,6 +264,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {1, 1};
@ -160,6 +278,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {1, 1};
@ -168,6 +292,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
#endif
}
{
@ -177,6 +307,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -185,6 +321,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -193,6 +335,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -201,6 +349,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -209,6 +363,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -217,6 +377,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -225,6 +391,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -233,6 +405,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -241,6 +419,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 1};
@ -249,6 +433,16 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 0, 1};
@ -257,6 +451,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 1, 2};
@ -265,6 +465,16 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 1, 2};
@ -273,6 +483,16 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 1, 2};
@ -281,6 +501,16 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 1, 2};
@ -289,6 +519,16 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 0, 1};
@ -297,6 +537,12 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
{
const int ia[] = {0, 0, 1};
@ -305,6 +551,20 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib + 1),
forward_iterator<const int*>(ib + sa)) == false);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
@ -313,6 +573,20 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib + 1 ),
forward_iterator<const int*>(ib + sa)) == false);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1)) == false);
#endif
}
{
const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
@ -321,5 +595,11 @@ int main()
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib)) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa)) == false);
#endif
}
}

View File

@ -20,6 +20,18 @@
#include "test_iterators.h"
#if _LIBCPP_STD_VER > 11
#define HAS_FOUR_ITERATOR_VERSION
#endif
int comparison_count = 0;
template <typename T>
bool counting_equals ( const T &a, const T &b ) {
++comparison_count;
return a == b;
}
int main()
{
{
@ -34,6 +46,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0};
@ -43,6 +67,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
@ -53,6 +84,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0};
@ -62,6 +105,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0};
@ -71,6 +121,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0};
@ -80,6 +137,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1};
@ -89,6 +153,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1};
@ -98,6 +169,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1};
@ -107,6 +190,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1};
@ -116,6 +211,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {1, 0};
@ -125,6 +227,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {1, 0};
@ -134,6 +243,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {1, 0};
@ -143,6 +264,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {1, 0};
@ -152,6 +285,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {1, 1};
@ -161,6 +301,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {1, 1};
@ -170,6 +317,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {1, 1};
@ -179,6 +333,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {1, 1};
@ -188,6 +349,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
@ -198,6 +371,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -207,6 +387,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -216,6 +403,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -225,6 +419,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -234,6 +435,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -243,6 +451,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -252,6 +467,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -261,6 +483,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 0};
@ -270,6 +499,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 1};
@ -279,6 +515,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 1};
@ -288,6 +536,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1, 2};
@ -297,6 +552,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1, 2};
@ -306,6 +573,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1, 2};
@ -315,6 +594,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1, 2};
@ -324,6 +615,18 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 1};
@ -333,6 +636,13 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 0, 1};
@ -342,6 +652,23 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib + 1),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
#endif
}
{
const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
@ -351,6 +678,37 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == true);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == true);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib + 1),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
std::equal_to<const int>()) == false);
comparison_count = 0;
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa - 1),
counting_equals<const int>) == false);
assert ( comparison_count > 0 );
comparison_count = 0;
assert(std::is_permutation(random_access_iterator<const int*>(ia),
random_access_iterator<const int*>(ia + sa),
random_access_iterator<const int*>(ib),
random_access_iterator<const int*>(ib + sa - 1),
counting_equals<const int>) == false);
assert ( comparison_count == 0 );
#endif
}
{
const int ia[] = {0, 1, 2, 3, 0, 5, 6, 2, 4, 4};
@ -360,5 +718,12 @@ int main()
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
std::equal_to<const int>()) == false);
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::is_permutation(forward_iterator<const int*>(ia),
forward_iterator<const int*>(ia + sa),
forward_iterator<const int*>(ib),
forward_iterator<const int*>(ib + sa),
std::equal_to<const int>()) == false);
#endif
}
}

View File

@ -19,6 +19,10 @@
#include "test_iterators.h"
#if _LIBCPP_STD_VER > 11
#define HAS_FOUR_ITERATOR_VERSION
#endif
int main()
{
int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
@ -31,4 +35,24 @@ int main()
input_iterator<const int*> >(
input_iterator<const int*>(ia+3),
input_iterator<const int*>(ib+3))));
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::mismatch(input_iterator<const int*>(ia),
input_iterator<const int*>(ia + sa),
input_iterator<const int*>(ib),
input_iterator<const int*>(ib + sa)) ==
(std::pair<input_iterator<const int*>,
input_iterator<const int*> >(
input_iterator<const int*>(ia+3),
input_iterator<const int*>(ib+3))));
assert(std::mismatch(input_iterator<const int*>(ia),
input_iterator<const int*>(ia + sa),
input_iterator<const int*>(ib),
input_iterator<const int*>(ib + 2)) ==
(std::pair<input_iterator<const int*>,
input_iterator<const int*> >(
input_iterator<const int*>(ia+2),
input_iterator<const int*>(ib+2))));
#endif
}

View File

@ -21,6 +21,11 @@
#include "test_iterators.h"
#if _LIBCPP_STD_VER > 11
#define HAS_FOUR_ITERATOR_VERSION
#endif
int main()
{
int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
@ -34,6 +39,24 @@ int main()
input_iterator<const int*> >(
input_iterator<const int*>(ia+3),
input_iterator<const int*>(ib+3))));
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::mismatch(input_iterator<const int*>(ia),
input_iterator<const int*>(ia + sa),
input_iterator<const int*>(ib),
input_iterator<const int*>(ib + sa),
std::equal_to<int>()) ==
(std::pair<input_iterator<const int*>,
input_iterator<const int*> >(
input_iterator<const int*>(ia+3),
input_iterator<const int*>(ib+3))));
#endif
assert(std::mismatch(ia, ia + sa, ib, std::equal_to<int>()) ==
(std::pair<int*,int*>(ia+3,ib+3)));
#ifdef HAS_FOUR_ITERATOR_VERSION
assert(std::mismatch(ia, ia + sa, ib, ib + sa, std::equal_to<int>()) ==
(std::pair<int*,int*>(ia+3,ib+3)));
assert(std::mismatch(ia, ia + sa, ib, ib + 2, std::equal_to<int>()) ==
(std::pair<int*,int*>(ia+2,ib+2)));
#endif
}