Move test into test/std subdirectory.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// reverse_iterator();
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test()
|
||||
{
|
||||
std::reverse_iterator<It> r;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<bidirectional_iterator<const char*> >();
|
||||
test<random_access_iterator<char*> >();
|
||||
test<char*>();
|
||||
test<const char*>();
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// explicit reverse_iterator(Iter x);
|
||||
|
||||
// test explicit
|
||||
|
||||
#include <iterator>
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test(It i)
|
||||
{
|
||||
std::reverse_iterator<It> r = i;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char s[] = "123";
|
||||
test(s);
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// explicit reverse_iterator(Iter x);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test(It i)
|
||||
{
|
||||
std::reverse_iterator<It> r(i);
|
||||
assert(r.base() == i);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char s[] = "123";
|
||||
test(bidirectional_iterator<const char*>(s));
|
||||
test(random_access_iterator<const char*>(s));
|
||||
test(s);
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <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()
|
||||
{
|
||||
derived d;
|
||||
|
||||
test<base*>(&d);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <class U>
|
||||
// requires HasConstructor<Iter, const U&>
|
||||
// reverse_iterator(const reverse_iterator<U> &u);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It, class U>
|
||||
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()
|
||||
{
|
||||
Derived d;
|
||||
|
||||
test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d));
|
||||
test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d));
|
||||
test<Base*>(&d);
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <class Iterator> reverse_iterator<Iterator>
|
||||
// make_reverse_iterator(Iterator i);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test(It i)
|
||||
{
|
||||
const std::reverse_iterator<It> r = std::make_reverse_iterator(i);
|
||||
assert(r.base() == i);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char* s = "1234567890";
|
||||
random_access_iterator<const char*>b(s);
|
||||
random_access_iterator<const char*>e(s+10);
|
||||
while ( b != e )
|
||||
test ( b++ );
|
||||
}
|
||||
#else
|
||||
int main () {}
|
||||
#endif
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <BidirectionalIterator Iter1, BidirectionalIterator Iter2>
|
||||
// requires HasEqualTo<Iter1, Iter2>
|
||||
// bool
|
||||
// operator!=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
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);
|
||||
test(s, s, false);
|
||||
test(s, s+1, true);
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// reverse_iterator operator++(int);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// reverse_iterator& operator++();
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// requires RandomAccessIterator<Iter>
|
||||
// reverse_iterator operator+(difference_type n) const;
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
const char* s = "1234567890";
|
||||
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
|
||||
test(s+5, 5, s);
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// requires RandomAccessIterator<Iter>
|
||||
// reverse_iterator& operator+=(difference_type n);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
const char* s = "1234567890";
|
||||
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
|
||||
test(s+5, 5, s);
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// reverse_iterator operator--(int);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// reverse_iterator& operator--();
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// requires RandomAccessIterator<Iter>
|
||||
// reverse_iterator operator-(difference_type n) const;
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// requires RandomAccessIterator<Iter>
|
||||
// reverse_iterator& operator-=(difference_type n);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// reference operator*() const;
|
||||
|
||||
// Be sure to respect LWG 198:
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
|
||||
// LWG 198 was superseded by LWG 2360
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
A() : data_(1) {}
|
||||
~A() {data_ = -1;}
|
||||
|
||||
friend bool operator==(const A& x, const A& y)
|
||||
{return x.data_ == y.data_;}
|
||||
};
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test(It i, typename std::iterator_traits<It>::value_type x)
|
||||
{
|
||||
std::reverse_iterator<It> r(i);
|
||||
assert(*r == x);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
A a;
|
||||
test(&a+1, A());
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <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()
|
||||
{
|
||||
derived d;
|
||||
test<base*>(&d);
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <class U>
|
||||
// requires HasAssign<Iter, const U&>
|
||||
// reverse_iterator&
|
||||
// operator=(const reverse_iterator<U>& u);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It, class U>
|
||||
void
|
||||
test(U u)
|
||||
{
|
||||
const std::reverse_iterator<U> r2(u);
|
||||
std::reverse_iterator<It> r1;
|
||||
std::reverse_iterator<It>& rr = r1 = r2;
|
||||
assert(r1.base() == u);
|
||||
assert(&rr == &r1);
|
||||
}
|
||||
|
||||
struct Base {};
|
||||
struct Derived : Base {};
|
||||
|
||||
int main()
|
||||
{
|
||||
Derived d;
|
||||
|
||||
test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d));
|
||||
test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d));
|
||||
test<Base*>(&d);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <BidirectionalIterator Iter1, BidirectionalIterator Iter2>
|
||||
// requires HasEqualTo<Iter1, Iter2>
|
||||
// bool
|
||||
// operator==(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
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);
|
||||
test(s, s, true);
|
||||
test(s, s+1, false);
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
|
||||
// requires HasMinus<Iter2, Iter1>
|
||||
// auto operator-(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y)
|
||||
// -> decltype(y.base() - x.base());
|
||||
|
||||
#include <iterator>
|
||||
#include <cstddef>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It1, class It2>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
test(random_access_iterator<const char*>(s+1), random_access_iterator<char*>(s), -1);
|
||||
test(s, s, 0);
|
||||
test(s, s+1, 1);
|
||||
test(s+1, s, -1);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
|
||||
// requires HasGreater<Iter1, Iter2>
|
||||
// bool
|
||||
// operator>(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), false);
|
||||
test(s, s, false);
|
||||
test(s, s+1, true);
|
||||
test(s+1, s, false);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
|
||||
// requires HasGreater<Iter1, Iter2>
|
||||
// bool
|
||||
// operator>=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), false);
|
||||
test(s, s, true);
|
||||
test(s, s+1, true);
|
||||
test(s+1, s, false);
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// requires RandomAccessIterator<Iter>
|
||||
// unspecified operator[](difference_type n) const;
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#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)
|
||||
{
|
||||
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()
|
||||
{
|
||||
const char* s = "1234567890";
|
||||
test(random_access_iterator<const char*>(s+5), 4, '1');
|
||||
test(s+5, 4, '1');
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
|
||||
// requires HasGreater<Iter1, Iter2>
|
||||
// bool
|
||||
// operator<(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), true);
|
||||
test(s, s, false);
|
||||
test(s, s+1, false);
|
||||
test(s+1, s, true);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
|
||||
// requires HasGreater<Iter1, Iter2>
|
||||
// bool
|
||||
// operator<=(const reverse_iterator<Iter1>& x, const reverse_iterator<Iter2>& y);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
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);
|
||||
test(random_access_iterator<const char*>(s+1), random_access_iterator<const char*>(s), true);
|
||||
test(s, s, true);
|
||||
test(s, s+1, false);
|
||||
test(s+1, s, true);
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// pointer operator->() const;
|
||||
|
||||
// Be sure to respect LWG 198:
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#198
|
||||
// LWG 198 was superseded by LWG 2360
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2360
|
||||
|
||||
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
A() : data_(1) {}
|
||||
~A() {data_ = -1;}
|
||||
|
||||
int get() const {return data_;}
|
||||
|
||||
friend bool operator==(const A& x, const A& y)
|
||||
{return x.data_ == y.data_;}
|
||||
};
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test(It i, typename std::iterator_traits<It>::value_type x)
|
||||
{
|
||||
std::reverse_iterator<It> r(i);
|
||||
assert(r->get() == x.get());
|
||||
}
|
||||
|
||||
class B
|
||||
{
|
||||
int data_;
|
||||
public:
|
||||
B(int d=1) : data_(d) {}
|
||||
~B() {data_ = -1;}
|
||||
|
||||
int get() const {return data_;}
|
||||
|
||||
friend bool operator==(const B& x, const B& y)
|
||||
{return x.data_ == y.data_;}
|
||||
const B *operator&() const { return nullptr; }
|
||||
B *operator&() { return nullptr; }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
A a;
|
||||
test(&a+1, A());
|
||||
|
||||
{
|
||||
std::list<B> l;
|
||||
l.push_back(B(0));
|
||||
l.push_back(B(1));
|
||||
l.push_back(B(2));
|
||||
|
||||
{
|
||||
std::list<B>::const_iterator i = l.begin();
|
||||
assert ( i->get() == 0 ); ++i;
|
||||
assert ( i->get() == 1 ); ++i;
|
||||
assert ( i->get() == 2 ); ++i;
|
||||
assert ( i == l.end ());
|
||||
}
|
||||
|
||||
{
|
||||
std::list<B>::const_reverse_iterator ri = l.rbegin();
|
||||
assert ( ri->get() == 2 ); ++ri;
|
||||
assert ( ri->get() == 1 ); ++ri;
|
||||
assert ( ri->get() == 0 ); ++ri;
|
||||
assert ( ri == l.rend ());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// template <RandomAccessIterator Iterator>
|
||||
// reverse_iterator<Iter>
|
||||
// operator+(Iter::difference_type n, const reverse_iterator<Iter>& x);
|
||||
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
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()
|
||||
{
|
||||
const char* s = "1234567890";
|
||||
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s));
|
||||
test(s+5, 5, s);
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
int main()
|
||||
{
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <iterator>
|
||||
|
||||
// reverse_iterator
|
||||
|
||||
// Test nested types and data member:
|
||||
|
||||
// template <BidirectionalIterator Iter>
|
||||
// class reverse_iterator {
|
||||
// protected:
|
||||
// Iter current;
|
||||
// public:
|
||||
// iterator<typename iterator_traits<Iterator>::iterator_category,
|
||||
// typename iterator_traits<Iterator>::value_type,
|
||||
// typename iterator_traits<Iterator>::difference_type,
|
||||
// typename iterator_traits<Iterator>::pointer,
|
||||
// typename iterator_traits<Iterator>::reference> {
|
||||
// };
|
||||
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class It>
|
||||
struct find_current
|
||||
: private std::reverse_iterator<It>
|
||||
{
|
||||
void test() {++(this->current);}
|
||||
};
|
||||
|
||||
template <class It>
|
||||
void
|
||||
test()
|
||||
{
|
||||
typedef std::reverse_iterator<It> R;
|
||||
typedef std::iterator_traits<It> T;
|
||||
find_current<It> q;
|
||||
q.test();
|
||||
static_assert((std::is_same<typename R::iterator_type, It>::value), "");
|
||||
static_assert((std::is_same<typename R::value_type, typename T::value_type>::value), "");
|
||||
static_assert((std::is_same<typename R::difference_type, typename T::difference_type>::value), "");
|
||||
static_assert((std::is_same<typename R::reference, typename T::reference>::value), "");
|
||||
static_assert((std::is_same<typename R::pointer, typename std::iterator_traits<It>::pointer>::value), "");
|
||||
static_assert((std::is_same<typename R::iterator_category, typename T::iterator_category>::value), "");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<bidirectional_iterator<char*> >();
|
||||
test<random_access_iterator<char*> >();
|
||||
test<char*>();
|
||||
}
|
Reference in New Issue
Block a user