[libc++] NFC: Tidy up the reverse_iterator tests

Incidentally, that fixes an error with the modules build.
This commit is contained in:
Louis Dionne 2021-06-03 14:56:51 -04:00
parent 90344499ae
commit 10d3869952
32 changed files with 325 additions and 626 deletions

View File

@ -17,7 +17,7 @@
#include "test_iterators.h"
template<class I1>
[[nodiscard]] consteval bool common_reverse_iterator_checks() {
constexpr bool common_reverse_iterator_checks() {
static_assert(std::indirectly_writable<I1, int>);
static_assert(std::sentinel_for<I1, I1>);
static_assert(std::sentinel_for<I1, std::reverse_iterator<float*>>);

View File

@ -12,10 +12,7 @@
// template <BidirectionalIterator Iter1, BidirectionalIterator Iter2>
// requires HasEqualTo<Iter1, Iter2>
// constexpr bool
// operator==(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
//
// constexpr in C++17
// bool operator==(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y); // constexpr since C++17
#include <iterator>
#include <cassert>
@ -24,16 +21,13 @@
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
TEST_CONSTEXPR_CXX17 void test(It l, It r, bool x) {
const std::reverse_iterator<It> r1(l);
const std::reverse_iterator<It> r2(r);
assert((r1 == r2) == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s), true);
test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1), false);
@ -41,19 +35,13 @@ int main(int, char**)
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), false);
test(s, s, true);
test(s, s+1, false);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p);
constexpr RI it3 = std::make_reverse_iterator(p+1);
static_assert( (it1 == it2), "");
static_assert(!(it1 == it3), "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -12,10 +12,7 @@
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasGreater<Iter1, Iter2>
// constexpr bool
// operator>=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
//
// constexpr in C++17
// bool operator>=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y); // constexpr since C++17
#include <iterator>
#include <cassert>
@ -24,16 +21,13 @@
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
TEST_CONSTEXPR_CXX17 void test(It l, It r, bool x) {
const std::reverse_iterator<It> r1(l);
const std::reverse_iterator<It> r2(r);
assert((r1 >= r2) == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), true);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), true);
@ -41,18 +35,13 @@ int main(int, char**)
test(s, s, true);
test(s, s+1, true);
test(s+1, s, false);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p);
constexpr RI it3 = std::make_reverse_iterator(p+1);
static_assert( (it1 >= it2), "");
static_assert( (it1 >= it3), "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -12,10 +12,7 @@
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasGreater<Iter1, Iter2>
// constexpr bool
// operator>(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
//
// constexpr in C++17
// bool operator>(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -24,16 +21,13 @@
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
TEST_CONSTEXPR_CXX17 void test(It l, It r, bool x) {
const std::reverse_iterator<It> r1(l);
const std::reverse_iterator<It> r2(r);
assert((r1 > r2) == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), false);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), true);
@ -41,18 +35,13 @@ int main(int, char**)
test(s, s, false);
test(s, s+1, true);
test(s+1, s, false);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p);
constexpr RI it3 = std::make_reverse_iterator(p+1);
static_assert(!(it1 > it2), "");
static_assert( (it1 > it3), "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -12,10 +12,7 @@
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasGreater<Iter1, Iter2>
// constexpr bool
// operator<=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
//
// constexpr in C++17
// bool operator<=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -24,16 +21,13 @@
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
TEST_CONSTEXPR_CXX17 void test(It l, It r, bool x) {
const std::reverse_iterator<It> r1(l);
const std::reverse_iterator<It> r2(r);
assert((r1 <= r2) == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), true);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), false);
@ -41,18 +35,13 @@ int main(int, char**)
test(s, s, true);
test(s, s+1, false);
test(s+1, s, true);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p);
constexpr RI it3 = std::make_reverse_iterator(p+1);
static_assert( (it1 <= it2), "");
static_assert(!(it1 <= it3), "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -12,10 +12,7 @@
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasGreater<Iter1, Iter2>
// constexpr bool
// operator<(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
//
// constexpr in C++17
// bool operator<(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -24,16 +21,13 @@
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
TEST_CONSTEXPR_CXX17 void test(It l, It r, bool x) {
const std::reverse_iterator<It> r1(l);
const std::reverse_iterator<It> r2(r);
assert((r1 < r2) == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s), false);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), false);
@ -41,18 +35,13 @@ int main(int, char**)
test(s, s, false);
test(s, s+1, false);
test(s+1, s, true);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p);
constexpr RI it3 = std::make_reverse_iterator(p+1);
static_assert(!(it1 < it2), "");
static_assert(!(it1 < it3), "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -12,10 +12,7 @@
// template <BidirectionalIterator Iter1, BidirectionalIterator Iter2>
// requires HasEqualTo<Iter1, Iter2>
// constexpr bool
// operator!=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
//
// constexpr in C++17
// bool operator!=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -24,16 +21,13 @@
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
TEST_CONSTEXPR_CXX17 void test(It l, It r, bool x) {
const std::reverse_iterator<It> r1(l);
const std::reverse_iterator<It> r2(r);
assert((r1 != r2) == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s), false);
test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1), true);
@ -41,18 +35,13 @@ int main(int, char**)
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1), true);
test(s, s, false);
test(s, s+1, true);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p);
constexpr RI it3 = std::make_reverse_iterator(p+1);
static_assert(!(it1 != it2), "");
static_assert( (it1 != it3), "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -11,11 +11,7 @@
// reverse_iterator
// template <class U>
// requires HasAssign<Iter, const U&>
// constexpr reverse_iterator&
// operator=(const reverse_iterator<U>& u);
//
// constexpr in C++17
// reverse_iterator& operator=(const reverse_iterator<U>& u); // constexpr since C++17
#include <iterator>
#include <cassert>
@ -24,9 +20,7 @@
#include "test_iterators.h"
template <class It, class U>
void
test(U u)
{
TEST_CONSTEXPR_CXX17 void test(U u) {
const std::reverse_iterator<U> r2(u);
std::reverse_iterator<It> r1;
std::reverse_iterator<It>& rr = r1 = r2;
@ -34,27 +28,21 @@ test(U u)
assert(&rr == &r1);
}
struct Base {};
struct Derived : Base {};
struct Base { };
struct Derived : Base { };
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
Derived d;
test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d));
test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d));
test<Base*>(&d);
#if TEST_STD_VER > 14
{
using BaseIter = std::reverse_iterator<const Base *>;
using DerivedIter = std::reverse_iterator<const Derived *>;
constexpr const Derived *p = nullptr;
constexpr DerivedIter it1 = std::make_reverse_iterator(p);
constexpr BaseIter it2 = (BaseIter{nullptr} = it1);
static_assert(it2.base() == p, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -10,9 +10,7 @@
// reverse_iterator
// constexpr reverse_iterator();
//
// constexpr in C++17
// reverse_iterator(); // constexpr since C++17
#include <iterator>
@ -20,26 +18,23 @@
#include "test_iterators.h"
template <class It>
void
test()
{
TEST_CONSTEXPR_CXX17 void test() {
std::reverse_iterator<It> r;
(void)r;
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
test<bidirectional_iterator<const char*> >();
test<random_access_iterator<char*> >();
test<char*>();
test<const char*>();
#if TEST_STD_VER > 14
{
constexpr std::reverse_iterator<const char *> it;
(void)it;
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -6,30 +6,18 @@
//
//===----------------------------------------------------------------------===//
// GCC 5 does not evaluate static assertions dependent on a template parameter.
// UNSUPPORTED: gcc-5
// <iterator>
// reverse_iterator
// explicit reverse_iterator(Iter x);
// test explicit
// test explicitness
#include <iterator>
template <class It>
void
test(It i)
{
std::reverse_iterator<It> r = i;
}
int main(int, char**)
{
const char s[] = "123";
test(s);
return 0;
int main(int, char**) {
char const* it = "";
std::reverse_iterator<char const*> r = it; // expected-error{{no viable conversion from 'const char *' to 'std::reverse_iterator<const char *>'}}
return 0;
}

View File

@ -10,9 +10,7 @@
// reverse_iterator
// explicit constexpr reverse_iterator(Iter x);
//
// constexpr in C++17
// explicit reverse_iterator(Iter x); // constexpr since C++17
#include <iterator>
#include <cassert>
@ -21,27 +19,23 @@
#include "test_iterators.h"
template <class It>
void
test(It i)
{
TEST_CONSTEXPR_CXX17 void test(It i) {
std::reverse_iterator<It> r(i);
assert(r.base() == i);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char s[] = "123";
test(bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s));
test(s);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
constexpr std::reverse_iterator<const char *> it(p);
static_assert(it.base() == p);
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -11,10 +11,7 @@
// reverse_iterator
// template <class U>
// requires HasConstructor<Iter, const U&>
// constexpr reverse_iterator(const reverse_iterator<U> &u);
//
// constexpr in C++17
// reverse_iterator(const reverse_iterator<U> &u); // constexpr since C++17
#include <iterator>
#include <cassert>
@ -22,34 +19,28 @@
#include "test_macros.h"
#include "test_iterators.h"
struct Base { };
struct Derived : Base { };
template <class It, class U>
void
test(U u)
{
TEST_CONSTEXPR_CXX17 void test(U u) {
const std::reverse_iterator<U> r2(u);
std::reverse_iterator<It> r1 = r2;
assert(r1.base() == u);
}
struct Base {};
struct Derived : Base {};
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
Derived d;
test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d));
test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d));
test<Base*>(&d);
#if TEST_STD_VER > 14
{
constexpr const Derived *p = nullptr;
constexpr std::reverse_iterator<const Derived *> it1 = std::make_reverse_iterator(p);
constexpr std::reverse_iterator<const Base *> it2(it1);
static_assert(it2.base() == p);
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <iterator>
// reverse_iterator
// iterator_type base() const; // constexpr since C++17
#include <iterator>
#include <cassert>
#include "test_macros.h"
#include "test_iterators.h"
TEST_CONSTEXPR_CXX17 bool test() {
typedef bidirectional_iterator<int*> Iter;
int i = 0;
Iter iter(&i);
std::reverse_iterator<Iter> const reverse(iter);
std::reverse_iterator<Iter>::iterator_type base = reverse.base();
assert(base == Iter(&i));
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER > 14
static_assert(test(), "");
#endif
return 0;
}

View File

@ -10,9 +10,7 @@
// reverse_iterator
// constexpr pointer operator->() const;
//
// constexpr in C++17
// pointer operator->() const; // constexpr in C++17
// Be sure to respect LWG 198:
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198

View File

@ -11,7 +11,7 @@
// reverse_iterator
// requires RandomAccessIterator<Iter>
// unspecified operator[](difference_type n) const;
// unspecified operator[](difference_type n) const; // constexpr since C++17
#include <iterator>
#include <cassert>
@ -20,31 +20,28 @@
#include "test_iterators.h"
template <class It>
void
test(It i, typename std::iterator_traits<It>::difference_type n,
typename std::iterator_traits<It>::value_type x)
{
TEST_CONSTEXPR_CXX17 void test(It i,
typename std::iterator_traits<It>::difference_type n,
typename std::iterator_traits<It>::value_type x) {
typedef typename std::iterator_traits<It>::value_type value_type;
const std::reverse_iterator<It> r(i);
value_type rr = r[n];
assert(rr == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 4, '1');
test(random_access_iterator<const char*>(s+5), 0, '5');
test(s+5, 4, '1');
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p + 5);
static_assert(it1[0] == '5', "");
static_assert(it1[4] == '1', "");
}
#endif
return 0;
test(s+5, 0, '5');
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -10,9 +10,7 @@
// reverse_iterator
// constexpr reference operator*() const;
//
// constexpr in C++17
// reference operator*() const; // constexpr in C++17
// Be sure to respect LWG 198:
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198

View File

@ -11,9 +11,7 @@
// reverse_iterator
// requires RandomAccessIterator<Iter>
// constexpr reverse_iterator& operator-=(difference_type n);
//
// constexpr in C++17
// reverse_iterator& operator-=(difference_type n); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -22,29 +20,24 @@
#include "test_iterators.h"
template <class It>
void
test(It i, typename std::iterator_traits<It>::difference_type n, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::difference_type n, It x) {
std::reverse_iterator<It> r(i);
std::reverse_iterator<It>& rr = r -= n;
assert(r.base() == x);
assert(&rr == &r);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s+10));
test(s+5, 5, s+10);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
constexpr auto it1 = std::make_reverse_iterator(p+5);
constexpr auto it2 = std::make_reverse_iterator(p) -= 5;
static_assert(it1 == it2, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -11,9 +11,7 @@
// reverse_iterator
// requires RandomAccessIterator<Iter>
// constexpr reverse_iterator& operator+=(difference_type n);
//
// constexpr in C++17
// reverse_iterator& operator+=(difference_type n); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -22,29 +20,24 @@
#include "test_iterators.h"
template <class It>
void
test(It i, typename std::iterator_traits<It>::difference_type n, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::difference_type n, It x) {
std::reverse_iterator<It> r(i);
std::reverse_iterator<It>& rr = r += n;
assert(r.base() == x);
assert(&rr == &r);
}
int main(int, char**)
{
const char* s = "1234567890";
TEST_CONSTEXPR_CXX17 bool tests() {
char const* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
test(s+5, 5, s);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
constexpr auto it1 = std::make_reverse_iterator(p);
constexpr auto it2 = std::make_reverse_iterator(p+5) += 5;
static_assert(it1 == it2, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -11,9 +11,7 @@
// reverse_iterator
// requires RandomAccessIterator<Iter>
// constexpr reverse_iterator operator-(difference_type n) const;
//
// constexpr in C++17
// reverse_iterator operator-(difference_type n) const; // constexpr in C++17
#include <iterator>
#include <cassert>
@ -22,32 +20,23 @@
#include "test_iterators.h"
template <class It>
void
test(It i, typename std::iterator_traits<It>::difference_type n, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::difference_type n, It x) {
const std::reverse_iterator<It> r(i);
std::reverse_iterator<It> rr = r - n;
assert(rr.base() == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s+10));
test(s+5, 5, s+10);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p + 5);
constexpr RI it3 = it1 - 5;
static_assert(it1 != it2, "");
static_assert(it1 != it3, "");
static_assert(it2 == it3, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -11,9 +11,7 @@
// reverse_iterator
// requires RandomAccessIterator<Iter>
// constexpr reverse_iterator operator+(difference_type n) const;
//
// constexpr in C++17
// reverse_iterator operator+(difference_type n) const; // constexpr in C++17
#include <iterator>
#include <cassert>
@ -22,32 +20,23 @@
#include "test_iterators.h"
template <class It>
void
test(It i, typename std::iterator_traits<It>::difference_type n, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::difference_type n, It x) {
const std::reverse_iterator<It> r(i);
std::reverse_iterator<It> rr = r + n;
assert(rr.base() == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
test(s+5, 5, s);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p + 5);
constexpr RI it3 = it2 + 5;
static_assert(it1 != it2, "");
static_assert(it1 == it3, "");
static_assert(it2 != it3, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -10,9 +10,7 @@
// reverse_iterator
// constexpr reverse_iterator operator--(int);
//
// constexpr in C++17
// reverse_iterator operator--(int); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -21,34 +19,25 @@
#include "test_iterators.h"
template <class It>
void
test(It i, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, It x) {
std::reverse_iterator<It> r(i);
std::reverse_iterator<It> rr = r--;
assert(r.base() == x);
assert(rr.base() == i);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "123";
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s+2));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s+2));
test(s+1, s+2);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p+1);
static_assert(it1 != it2, "");
constexpr RI it3 = std::make_reverse_iterator(p) --;
static_assert(it1 == it3, "");
static_assert(it2 != it3, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -10,9 +10,7 @@
// reverse_iterator
// constexpr reverse_iterator operator++(int);
//
// constexpr in C++17
// reverse_iterator operator++(int); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -21,34 +19,25 @@
#include "test_iterators.h"
template <class It>
void
test(It i, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, It x) {
std::reverse_iterator<It> r(i);
std::reverse_iterator<It> rr = r++;
assert(r.base() == x);
assert(rr.base() == i);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "123";
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s));
test(s+1, s);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p+1);
static_assert(it1 != it2, "");
constexpr RI it3 = std::make_reverse_iterator(p+1) ++;
static_assert(it1 != it3, "");
static_assert(it2 == it3, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -10,9 +10,7 @@
// reverse_iterator
// constexpr reverse_iterator& operator--();
//
// constexpr in C++17
// reverse_iterator& operator--(); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -21,35 +19,25 @@
#include "test_iterators.h"
template <class It>
void
test(It i, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, It x) {
std::reverse_iterator<It> r(i);
std::reverse_iterator<It>& rr = --r;
assert(r.base() == x);
assert(&rr == &r);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "123";
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s+2));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s+2));
test(s+1, s+2);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p+1);
static_assert(it1 != it2, "");
constexpr RI it3 = -- std::make_reverse_iterator(p);
static_assert(it1 != it3, "");
static_assert(it2 == it3, "");
static_assert(*(--std::make_reverse_iterator(p)) == '1', "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -10,9 +10,7 @@
// reverse_iterator
// constexpr reverse_iterator& operator++();
//
// constexpr in C++17
// reverse_iterator& operator++(); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -21,35 +19,25 @@
#include "test_iterators.h"
template <class It>
void
test(It i, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, It x) {
std::reverse_iterator<It> r(i);
std::reverse_iterator<It>& rr = ++r;
assert(r.base() == x);
assert(&rr == &r);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "123";
test(bidirectional_iterator<const char*>(s+1), bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s));
test(s+1, s);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p+1);
static_assert(it1 != it2, "");
constexpr RI it3 = ++ std::make_reverse_iterator(p+1);
static_assert(it1 == it3, "");
static_assert(it2 != it3, "");
static_assert(*(++std::make_reverse_iterator(p+2)) == '1', "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -7,15 +7,13 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11
// <iterator>
// reverse_iterator
// template <class Iterator>
// constexpr reverse_iterator<Iterator>
// make_reverse_iterator(Iterator i);
//
// constexpr in C++17
// reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -24,28 +22,24 @@
#include "test_iterators.h"
template <class It>
void
test(It i)
{
TEST_CONSTEXPR_CXX17 void test(It i) {
const std::reverse_iterator<It> r = std::make_reverse_iterator(i);
assert(r.base() == i);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
random_access_iterator<const char*>b(s);
random_access_iterator<const char*>e(s+10);
while ( b != e )
test ( b++ );
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
constexpr auto it1 = std::make_reverse_iterator(p);
static_assert(it1.base() == p, "");
}
#endif
return 0;
random_access_iterator<const char*> b(s);
random_access_iterator<const char*> e(s+10);
while (b != e)
test (b++);
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -12,10 +12,8 @@
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasMinus<Iter2, Iter1>
// constexpr auto operator-(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y)
// -> decltype(y.base() - x.base());
//
// constexpr in C++17
// auto operator-(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y) // constexpr in C++17
// -> decltype(y.base() - x.base());
#include <iterator>
#include <cstddef>
@ -25,16 +23,13 @@
#include "test_iterators.h"
template <class It1, class It2>
void
test(It1 l, It2 r, std::ptrdiff_t x)
{
TEST_CONSTEXPR_CXX17 void test(It1 l, It2 r, std::ptrdiff_t x) {
const std::reverse_iterator<It1> r1(l);
const std::reverse_iterator<It2> r2(r);
assert((r1 - r2) == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
char s[3] = {0};
test(random_access_iterator<const char*>(s), random_access_iterator<char*>(s), 0);
test(random_access_iterator<char*>(s), random_access_iterator<const char*>(s+1), 1);
@ -42,17 +37,13 @@ int main(int, char**)
test(s, s, 0);
test(s, s+1, 1);
test(s+1, s, -1);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p+1);
static_assert( it1 - it2 == 1, "");
static_assert( it2 - it1 == -1, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -11,10 +11,7 @@
// reverse_iterator
// template <RandomAccessIterator Iterator>
// constexpr reverse_iterator<Iter>
// operator+(Iter::difference_type n, const reverse_iterator<Iter>& x);
//
// constexpr in C++17
// reverse_iterator<Iter> operator+(Iter::difference_type n, const reverse_iterator<Iter>& x); // constexpr in C++17
#include <iterator>
#include <cassert>
@ -23,32 +20,23 @@
#include "test_iterators.h"
template <class It>
void
test(It i, typename std::iterator_traits<It>::difference_type n, It x)
{
TEST_CONSTEXPR_CXX17 void test(It i, typename std::iterator_traits<It>::difference_type n, It x) {
const std::reverse_iterator<It> r(i);
std::reverse_iterator<It> rr = n + r;
assert(rr.base() == x);
}
int main(int, char**)
{
TEST_CONSTEXPR_CXX17 bool tests() {
const char* s = "1234567890";
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
test(s+5, 5, s);
#if TEST_STD_VER > 14
{
constexpr const char *p = "123456789";
typedef std::reverse_iterator<const char *> RI;
constexpr RI it1 = std::make_reverse_iterator(p);
constexpr RI it2 = std::make_reverse_iterator(p + 5);
constexpr RI it3 = 5 + it2;
static_assert(it1 != it2, "");
static_assert(it1 == it3, "");
static_assert(it2 != it3, "");
}
#endif
return 0;
return true;
}
int main(int, char**) {
tests();
#if TEST_STD_VER > 14
static_assert(tests(), "");
#endif
return 0;
}

View File

@ -1,42 +0,0 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// GCC 5 does not evaluate static assertions dependent on a template parameter.
// UNSUPPORTED: gcc-5
// <iterator>
// reverse_iterator
// template <class U>
// requires HasConstructor<Iter, const U&>
// reverse_iterator(const reverse_iterator<U> &u);
// test requires
#include <iterator>
template <class It, class U>
void
test(U u)
{
std::reverse_iterator<U> r2(u);
std::reverse_iterator<It> r1 = r2;
}
struct base {};
struct derived {};
int main(int, char**)
{
derived d;
test<base*>(&d);
return 0;
}

View File

@ -1,13 +0,0 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
int main(int, char**)
{
return 0;
}

View File

@ -1,43 +0,0 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// GCC 5 does not evaluate static assertions dependent on a template parameter.
// UNSUPPORTED: gcc-5
// <iterator>
// reverse_iterator
// template <class U>
// requires HasAssign<Iter, const U&>
// reverse_iterator&
// operator=(const reverse_iterator<U>& u);
// test requires
#include <iterator>
template <class It, class U>
void
test(U u)
{
const std::reverse_iterator<U> r2(u);
std::reverse_iterator<It> r1;
r1 = r2;
}
struct base {};
struct derived {};
int main(int, char**)
{
derived d;
test<base*>(&d);
return 0;
}

View File

@ -1,13 +0,0 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
int main(int, char**)
{
return 0;
}