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:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
// template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
// template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
// template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
#if __cplusplus <= 201402L
int main () {}
#else
#include <__config>
#include <iterator>
#include <cassert>
#include <vector>
#include <array>
#include <initializer_list>
template<typename C>
void test_const_container( const C& c )
{
assert ( std::data(c) == c.data());
}
template<typename T>
void test_const_container( const std::initializer_list<T>& c )
{
assert ( std::data(c) == c.begin());
}
template<typename C>
void test_container( C& c )
{
assert ( std::data(c) == c.data());
}
template<typename T>
void test_container( std::initializer_list<T>& c)
{
assert ( std::data(c) == c.begin());
}
template<typename T, size_t Sz>
void test_const_array( const T (&array)[Sz] )
{
assert ( std::data(array) == &array[0]);
}
int main()
{
std::vector<int> v; v.push_back(1);
std::array<int, 1> a; a[0] = 3;
std::initializer_list<int> il = { 4 };
test_container ( v );
test_container ( a );
test_container ( il );
test_const_container ( v );
test_const_container ( a );
test_const_container ( il );
static constexpr int arrA [] { 1, 2, 3 };
test_const_array ( arrA );
}
#endif

View File

@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
// template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
// template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
#if __cplusplus <= 201402L
int main () {}
#else
#include <__config>
#include <iterator>
#include <cassert>
#include <vector>
#include <array>
#include <list>
#include <initializer_list>
template<typename C>
void test_const_container( const C& c )
{
assert ( std::empty(c) == c.empty());
}
template<typename T>
void test_const_container( const std::initializer_list<T>& c )
{
assert ( std::empty(c) == (c.size() == 0));
}
template<typename C>
void test_container( C& c )
{
assert ( std::empty(c) == c.empty());
}
template<typename T>
void test_container( std::initializer_list<T>& c )
{
assert ( std::empty(c) == (c.size() == 0));
}
template<typename T, size_t Sz>
void test_const_array( const T (&array)[Sz] )
{
assert (!std::empty(array));
}
int main()
{
std::vector<int> v; v.push_back(1);
std::list<int> l; l.push_back(2);
std::array<int, 1> a; a[0] = 3;
std::initializer_list<int> il = { 4 };
test_container ( v );
test_container ( l );
test_container ( a );
test_container ( il );
test_const_container ( v );
test_const_container ( l );
test_const_container ( a );
test_const_container ( il );
static constexpr int arrA [] { 1, 2, 3 };
test_const_array ( arrA );
}
#endif

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
// template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
#if __cplusplus <= 201402L
int main () {}
#else
#include <__config>
#include <iterator>
#include <cassert>
#include <vector>
#include <array>
#include <list>
#include <initializer_list>
template<typename C>
void test_const_container( const C& c )
{
assert ( std::size(c) == c.size());
}
template<typename T>
void test_const_container( const std::initializer_list<T>& c)
{
assert ( std::size(c) == c.size());
}
template<typename C>
void test_container( C& c)
{
assert ( std::size(c) == c.size());
}
template<typename T>
void test_container( std::initializer_list<T>& c )
{
assert ( std::size(c) == c.size());
}
template<typename T, size_t Sz>
void test_const_array( const T (&array)[Sz] )
{
assert ( std::size(array) == Sz );
}
int main()
{
std::vector<int> v; v.push_back(1);
std::list<int> l; l.push_back(2);
std::array<int, 1> a; a[0] = 3;
std::initializer_list<int> il = { 4 };
test_container ( v );
test_container ( l );
test_container ( a );
test_container ( il );
test_const_container ( v );
test_const_container ( l );
test_const_container ( a );
test_const_container ( il );
static constexpr int arrA [] { 1, 2, 3 };
test_const_array ( arrA );
}
#endif

View File

@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template<class Category, class T, class Distance = ptrdiff_t,
// class Pointer = T*, class Reference = T&>
// struct iterator
// {
// typedef T value_type;
// typedef Distance difference_type;
// typedef Pointer pointer;
// typedef Reference reference;
// typedef Category iterator_category;
// };
#include <iterator>
#include <type_traits>
struct A {};
template <class T>
void
test2()
{
typedef std::iterator<std::forward_iterator_tag, T> It;
static_assert((std::is_same<typename It::value_type, T>::value), "");
static_assert((std::is_same<typename It::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<typename It::pointer, T*>::value), "");
static_assert((std::is_same<typename It::reference, T&>::value), "");
static_assert((std::is_same<typename It::iterator_category, std::forward_iterator_tag>::value), "");
}
template <class T>
void
test3()
{
typedef std::iterator<std::bidirectional_iterator_tag, T, short> It;
static_assert((std::is_same<typename It::value_type, T>::value), "");
static_assert((std::is_same<typename It::difference_type, short>::value), "");
static_assert((std::is_same<typename It::pointer, T*>::value), "");
static_assert((std::is_same<typename It::reference, T&>::value), "");
static_assert((std::is_same<typename It::iterator_category, std::bidirectional_iterator_tag>::value), "");
}
template <class T>
void
test4()
{
typedef std::iterator<std::random_access_iterator_tag, T, int, const T*> It;
static_assert((std::is_same<typename It::value_type, T>::value), "");
static_assert((std::is_same<typename It::difference_type, int>::value), "");
static_assert((std::is_same<typename It::pointer, const T*>::value), "");
static_assert((std::is_same<typename It::reference, T&>::value), "");
static_assert((std::is_same<typename It::iterator_category, std::random_access_iterator_tag>::value), "");
}
template <class T>
void
test5()
{
typedef std::iterator<std::input_iterator_tag, T, long, const T*, const T&> It;
static_assert((std::is_same<typename It::value_type, T>::value), "");
static_assert((std::is_same<typename It::difference_type, long>::value), "");
static_assert((std::is_same<typename It::pointer, const T*>::value), "");
static_assert((std::is_same<typename It::reference, const T&>::value), "");
static_assert((std::is_same<typename It::iterator_category, std::input_iterator_tag>::value), "");
}
int main()
{
test2<A>();
test3<A>();
test4<A>();
test5<A>();
}

View File

@@ -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>
// template <InputIterator Iter>
// void advance(Iter& i, Iter::difference_type n);
//
// template <BidirectionalIterator Iter>
// void advance(Iter& i, Iter::difference_type n);
//
// template <RandomAccessIterator Iter>
// void advance(Iter& i, Iter::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::advance(i, n);
assert(i == x);
}
int main()
{
const char* s = "1234567890";
test(input_iterator<const char*>(s), 10, input_iterator<const char*>(s+10));
test(forward_iterator<const char*>(s), 10, forward_iterator<const char*>(s+10));
test(bidirectional_iterator<const char*>(s+5), 5, bidirectional_iterator<const char*>(s+10));
test(bidirectional_iterator<const char*>(s+5), -5, bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s+5), 5, random_access_iterator<const char*>(s+10));
test(random_access_iterator<const char*>(s+5), -5, random_access_iterator<const char*>(s));
test(s+5, 5, s+10);
test(s+5, -5, s);
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <InputIterator Iter>
// Iter::difference_type
// distance(Iter first, Iter last);
//
// template <RandomAccessIterator Iter>
// Iter::difference_type
// distance(Iter first, Iter last);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It first, It last, typename std::iterator_traits<It>::difference_type x)
{
assert(std::distance(first, last) == x);
}
int main()
{
const char* s = "1234567890";
test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), 10);
test(forward_iterator<const char*>(s), forward_iterator<const char*>(s+10), 10);
test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+10), 10);
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+10), 10);
test(s, s+10, 10);
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <InputIterator Iter>
// Iter next(Iter x, Iter::difference_type n = 1);
#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)
{
assert(std::next(i, n) == x);
}
template <class It>
void
test(It i, It x)
{
assert(std::next(i) == x);
}
int main()
{
const char* s = "1234567890";
test(forward_iterator<const char*>(s), 10, forward_iterator<const char*>(s+10));
test(bidirectional_iterator<const char*>(s), 10, bidirectional_iterator<const char*>(s+10));
test(random_access_iterator<const char*>(s), 10, random_access_iterator<const char*>(s+10));
test(s, 10, s+10);
test(forward_iterator<const char*>(s), forward_iterator<const char*>(s+1));
test(bidirectional_iterator<const char*>(s), bidirectional_iterator<const char*>(s+1));
test(random_access_iterator<const char*>(s), random_access_iterator<const char*>(s+1));
test(s, s+1);
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <BidirectionalIterator Iter>
// Iter prev(Iter x, Iter::difference_type n = 1);
#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)
{
assert(std::prev(i, n) == x);
}
template <class It>
void
test(It i, It x)
{
assert(std::prev(i) == x);
}
int main()
{
const char* s = "1234567890";
test(bidirectional_iterator<const char*>(s+10), 10, bidirectional_iterator<const char*>(s));
test(random_access_iterator<const char*>(s+10), 10, random_access_iterator<const char*>(s));
test(s+10, 10, s);
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);
}

View File

@@ -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>
// template<class T>
// struct iterator_traits<const T*>
// {
// typedef ptrdiff_t difference_type;
// typedef T value_type;
// typedef const T* pointer;
// typedef const T& reference;
// typedef random_access_iterator_tag iterator_category;
// };
#include <iterator>
#include <type_traits>
struct A {};
int main()
{
typedef std::iterator_traits<const A*> It;
static_assert((std::is_same<It::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<It::value_type, A>::value), "");
static_assert((std::is_same<It::pointer, const A*>::value), "");
static_assert((std::is_same<It::reference, const A&>::value), "");
static_assert((std::is_same<It::iterator_category, std::random_access_iterator_tag>::value), "");
}

View File

@@ -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>
// template<class NotAnIterator>
// struct iterator_traits
// {
// };
#include <iterator>
struct not_an_iterator
{
};
template <class _Tp>
struct has_value_type
{
private:
struct two {char lx; char lxx;};
template <class _Up> static two test(...);
template <class _Up> static char test(typename _Up::value_type* = 0);
public:
static const bool value = sizeof(test<_Tp>(0)) == 1;
};
int main()
{
typedef std::iterator_traits<not_an_iterator> It;
static_assert(!(has_value_type<It>::value), "");
}

View File

@@ -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>
// template<class Iter>
// struct iterator_traits
// {
// typedef typename Iter::difference_type difference_type;
// typedef typename Iter::value_type value_type;
// typedef typename Iter::pointer pointer;
// typedef typename Iter::reference reference;
// typedef typename Iter::iterator_category iterator_category;
// };
#include <iterator>
#include <type_traits>
struct A {};
struct test_iterator
{
typedef int difference_type;
typedef A value_type;
typedef A* pointer;
typedef A& reference;
typedef std::forward_iterator_tag iterator_category;
};
int main()
{
typedef std::iterator_traits<test_iterator> It;
static_assert((std::is_same<It::difference_type, int>::value), "");
static_assert((std::is_same<It::value_type, A>::value), "");
static_assert((std::is_same<It::pointer, A*>::value), "");
static_assert((std::is_same<It::iterator_category, std::forward_iterator_tag>::value), "");
}

View File

@@ -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>
// template<class T>
// struct iterator_traits<T*>
// {
// typedef ptrdiff_t difference_type;
// typedef T value_type;
// typedef T* pointer;
// typedef T& reference;
// typedef random_access_iterator_tag iterator_category;
// };
#include <iterator>
#include <type_traits>
struct A {};
int main()
{
typedef std::iterator_traits<A*> It;
static_assert((std::is_same<It::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<It::value_type, A>::value), "");
static_assert((std::is_same<It::pointer, A*>::value), "");
static_assert((std::is_same<It::reference, A&>::value), "");
static_assert((std::is_same<It::iterator_category, std::random_access_iterator_tag>::value), "");
}

View File

@@ -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()
{
}

View File

@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// 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>
// struct bidirectional_iterator_tag : public forward_iterator_tag {};
#include <iterator>
#include <type_traits>
int main()
{
std::bidirectional_iterator_tag tag;
static_assert((std::is_base_of<std::forward_iterator_tag,
std::bidirectional_iterator_tag>::value), "");
static_assert((!std::is_base_of<std::output_iterator_tag,
std::bidirectional_iterator_tag>::value), "");
}

View File

@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// 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>
// struct forward_iterator_tag: public input_iterator_tag {};
#include <iterator>
#include <type_traits>
int main()
{
std::forward_iterator_tag tag;
static_assert((std::is_base_of<std::input_iterator_tag,
std::forward_iterator_tag>::value), "");
static_assert((!std::is_base_of<std::output_iterator_tag,
std::forward_iterator_tag>::value), "");
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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>
// struct input_iterator_tag {};
#include <iterator>
#include <type_traits>
int main()
{
std::input_iterator_tag tag;
static_assert((!std::is_base_of<std::output_iterator_tag,
std::input_iterator_tag>::value), "");
}

View File

@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// 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>
// struct output_iterator_tag {};
#include <iterator>
#include <type_traits>
int main()
{
std::output_iterator_tag tag;
static_assert((!std::is_base_of<std::input_iterator_tag,
std::output_iterator_tag>::value), "");
}

View File

@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// 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>
// struct random_access_iterator_tag : public bidirectional_iterator_tag {};
#include <iterator>
#include <type_traits>
int main()
{
std::random_access_iterator_tag tag;
static_assert((std::is_base_of<std::bidirectional_iterator_tag,
std::random_access_iterator_tag>::value), "");
static_assert((!std::is_base_of<std::output_iterator_tag,
std::random_access_iterator_tag>::value), "");
}

View File

@@ -0,0 +1,148 @@
//===----------------------------------------------------------------------===//
//
// 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>
// template <class C> auto begin(C& c) -> decltype(c.begin());
// template <class C> auto begin(const C& c) -> decltype(c.begin());
// template <class C> auto end(C& c) -> decltype(c.end());
// template <class C> auto end(const C& c) -> decltype(c.end());
// template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il);
// template <class E> reverse_iterator<const E*> rend(initializer_list<E> il);
#include <__config>
#if __cplusplus >= 201103L
#include <iterator>
#include <cassert>
#include <vector>
#include <array>
#include <list>
#include <initializer_list>
template<typename C>
void test_const_container( const C & c, typename C::value_type val ) {
assert ( std::begin(c) == c.begin());
assert (*std::begin(c) == val );
assert ( std::begin(c) != c.end());
assert ( std::end(c) == c.end());
#if _LIBCPP_STD_VER > 11
assert ( std::cbegin(c) == c.cbegin());
assert ( std::cbegin(c) != c.cend());
assert ( std::cend(c) == c.cend());
assert ( std::rbegin(c) == c.rbegin());
assert ( std::rbegin(c) != c.rend());
assert ( std::rend(c) == c.rend());
assert ( std::crbegin(c) == c.crbegin());
assert ( std::crbegin(c) != c.crend());
assert ( std::crend(c) == c.crend());
#endif
}
template<typename T>
void test_const_container( const std::initializer_list<T> & c, T val ) {
assert ( std::begin(c) == c.begin());
assert (*std::begin(c) == val );
assert ( std::begin(c) != c.end());
assert ( std::end(c) == c.end());
#if _LIBCPP_STD_VER > 11
// initializer_list doesn't have cbegin/cend/rbegin/rend
// but std::cbegin(),etc work (b/c they're general fn templates)
// assert ( std::cbegin(c) == c.cbegin());
// assert ( std::cbegin(c) != c.cend());
// assert ( std::cend(c) == c.cend());
// assert ( std::rbegin(c) == c.rbegin());
// assert ( std::rbegin(c) != c.rend());
// assert ( std::rend(c) == c.rend());
// assert ( std::crbegin(c) == c.crbegin());
// assert ( std::crbegin(c) != c.crend());
// assert ( std::crend(c) == c.crend());
#endif
}
template<typename C>
void test_container( C & c, typename C::value_type val ) {
assert ( std::begin(c) == c.begin());
assert (*std::begin(c) == val );
assert ( std::begin(c) != c.end());
assert ( std::end(c) == c.end());
#if _LIBCPP_STD_VER > 11
assert ( std::cbegin(c) == c.cbegin());
assert ( std::cbegin(c) != c.cend());
assert ( std::cend(c) == c.cend());
assert ( std::rbegin(c) == c.rbegin());
assert ( std::rbegin(c) != c.rend());
assert ( std::rend(c) == c.rend());
assert ( std::crbegin(c) == c.crbegin());
assert ( std::crbegin(c) != c.crend());
assert ( std::crend(c) == c.crend());
#endif
}
template<typename T>
void test_container( std::initializer_list<T> & c, T val ) {
assert ( std::begin(c) == c.begin());
assert (*std::begin(c) == val );
assert ( std::begin(c) != c.end());
assert ( std::end(c) == c.end());
#if _LIBCPP_STD_VER > 11
// initializer_list doesn't have cbegin/cend/rbegin/rend
// assert ( std::cbegin(c) == c.cbegin());
// assert ( std::cbegin(c) != c.cend());
// assert ( std::cend(c) == c.cend());
// assert ( std::rbegin(c) == c.rbegin());
// assert ( std::rbegin(c) != c.rend());
// assert ( std::rend(c) == c.rend());
// assert ( std::crbegin(c) == c.crbegin());
// assert ( std::crbegin(c) != c.crend());
// assert ( std::crend(c) == c.crend());
#endif
}
template<typename T, size_t Sz>
void test_const_array( const T (&array)[Sz] ) {
assert ( std::begin(array) == array );
assert (*std::begin(array) == array[0] );
assert ( std::begin(array) != std::end(array));
assert ( std::end(array) == array + Sz);
#if _LIBCPP_STD_VER > 11
assert ( std::cbegin(array) == array );
assert (*std::cbegin(array) == array[0] );
assert ( std::cbegin(array) != std::cend(array));
assert ( std::cend(array) == array + Sz);
#endif
}
int main(){
std::vector<int> v; v.push_back(1);
std::list<int> l; l.push_back(2);
std::array<int, 1> a; a[0] = 3;
std::initializer_list<int> il = { 4 };
test_container ( v, 1 );
test_container ( l, 2 );
test_container ( a, 3 );
test_container ( il, 4 );
test_const_container ( v, 1 );
test_const_container ( l, 2 );
test_const_container ( a, 3 );
test_const_container ( il, 4 );
static constexpr int arrA [] { 1, 2, 3 };
test_const_array ( arrA );
#if _LIBCPP_STD_VER > 11
constexpr const int *b = std::cbegin(arrA);
constexpr const int *e = std::cend(arrA);
static_assert(e - b == 3, "");
#endif
}
#else
int main(){}
#endif

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// 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>
// back_insert_iterator
// explicit back_insert_iterator(Cont& x);
// test for explicit
#include <iterator>
#include <vector>
int main()
{
std::back_insert_iterator<std::vector<int> > i = std::vector<int>();
}

View File

@@ -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>
// back_insert_iterator
// explicit back_insert_iterator(Cont& x);
#include <iterator>
#include <vector>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::back_insert_iterator<C> i(c);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -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>
// back_insert_iterator
// back_insert_iterator<Cont> operator++(int);
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::back_insert_iterator<C> i(c);
std::back_insert_iterator<C> r = i++;
r = 0;
assert(c.size() == 1);
assert(c.back() == 0);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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>
// back_insert_iterator
// back_insert_iterator<Cont>& operator++();
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::back_insert_iterator<C> i(c);
std::back_insert_iterator<C>& r = ++i;
assert(&r == &i);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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>
// back_insert_iterator
// requires CopyConstructible<Cont::value_type>
// back_insert_iterator<Cont>&
// operator=(const Cont::value_type& value);
#include <iterator>
#include <vector>
#include <cassert>
template <class C>
void
test(C c)
{
const typename C::value_type v = typename C::value_type();
std::back_insert_iterator<C> i(c);
i = v;
assert(c.back() == v);
}
class Copyable
{
int data_;
public:
Copyable() : data_(0) {}
~Copyable() {data_ = -1;}
friend bool operator==(const Copyable& x, const Copyable& y)
{return x.data_ == y.data_;}
};
int main()
{
test(std::vector<Copyable>());
}

View File

@@ -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>
// back_insert_iterator
// requires CopyConstructible<Cont::value_type>
// back_insert_iterator<Cont>&
// operator=(Cont::value_type&& value);
#include <iterator>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <vector>
#include <memory>
#include <cassert>
template <class C>
void
test(C c)
{
std::back_insert_iterator<C> i(c);
i = typename C::value_type();
assert(c.back() == typename C::value_type());
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
test(std::vector<std::unique_ptr<int> >());
#endif
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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>
// back_insert_iterator
// back_insert_iterator<Cont>& operator*();
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::back_insert_iterator<C> i(c);
std::back_insert_iterator<C>& r = *i;
assert(&r == &i);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -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>
// template <BackInsertionContainer Cont>
// back_insert_iterator<Cont>
// back_inserter(Cont& x);
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::back_insert_iterator<C> i = std::back_inserter(c);
i = 0;
assert(c.size() == 1);
assert(c.back() == 0);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -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()
{
}

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// 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>
// back_insert_iterator
// Test nested types and data member:
// template <BackInsertionContainer Cont>
// class back_insert_iterator {
// protected:
// Cont* container;
// public:
// typedef Cont container_type;
// typedef void value_type;
// typedef void difference_type;
// typedef back_insert_iterator<Cont>& reference;
// typedef void pointer;
// };
#include <iterator>
#include <type_traits>
#include <vector>
template <class C>
struct find_container
: private std::back_insert_iterator<C>
{
explicit find_container(C& c) : std::back_insert_iterator<C>(c) {}
void test() {this->container = 0;}
};
template <class C>
void
test()
{
typedef std::back_insert_iterator<C> R;
C c;
find_container<C> q(c);
q.test();
static_assert((std::is_same<typename R::container_type, C>::value), "");
static_assert((std::is_same<typename R::value_type, void>::value), "");
static_assert((std::is_same<typename R::difference_type, void>::value), "");
static_assert((std::is_same<typename R::reference, R&>::value), "");
static_assert((std::is_same<typename R::pointer, void>::value), "");
static_assert((std::is_same<typename R::iterator_category, std::output_iterator_tag>::value), "");
}
int main()
{
test<std::vector<int> >();
}

View File

@@ -0,0 +1,24 @@
//===----------------------------------------------------------------------===//
//
// 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>
// front_insert_iterator
// explicit front_insert_iterator(Cont& x);
// test for explicit
#include <iterator>
#include <list>
int main()
{
std::front_insert_iterator<std::list<int> > i = std::list<int>();
}

View File

@@ -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>
// front_insert_iterator
// explicit front_insert_iterator(Cont& x);
#include <iterator>
#include <list>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::front_insert_iterator<C> i(c);
}
int main()
{
test(std::list<int>());
test(nasty_list<int>());
}

View File

@@ -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>
// front_insert_iterator
// front_insert_iterator<Cont> operator++(int);
#include <iterator>
#include <list>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::front_insert_iterator<C> i(c);
std::front_insert_iterator<C> r = i++;
r = 0;
assert(c.size() == 1);
assert(c.back() == 0);
}
int main()
{
test(std::list<int>());
test(nasty_list<int>());
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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>
// front_insert_iterator
// front_insert_iterator<Cont>& operator++();
#include <iterator>
#include <list>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::front_insert_iterator<C> i(c);
std::front_insert_iterator<C>& r = ++i;
assert(&r == &i);
}
int main()
{
test(std::list<int>());
test(nasty_list<int>());
}

View File

@@ -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>
// front_insert_iterator
// front_insert_iterator<Cont>&
// operator=(const Cont::value_type& value);
#include <iterator>
#include <list>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
const typename C::value_type v = typename C::value_type();
std::front_insert_iterator<C> i(c);
i = v;
assert(c.front() == v);
}
class Copyable
{
int data_;
public:
Copyable() : data_(0) {}
~Copyable() {data_ = -1;}
friend bool operator==(const Copyable& x, const Copyable& y)
{return x.data_ == y.data_;}
};
int main()
{
test(std::list<Copyable>());
test(nasty_list<Copyable>());
}

View File

@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// 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>
// front_insert_iterator
// front_insert_iterator<Cont>&
// operator=(Cont::value_type&& value);
#include <iterator>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <list>
#include <memory>
#include <cassert>
template <class C>
void
test(C c)
{
std::front_insert_iterator<C> i(c);
i = typename C::value_type();
assert(c.front() == typename C::value_type());
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
test(std::list<std::unique_ptr<int> >());
#endif
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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>
// front_insert_iterator
// front_insert_iterator<Cont>& operator*();
#include <iterator>
#include <list>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::front_insert_iterator<C> i(c);
std::front_insert_iterator<C>& r = *i;
assert(&r == &i);
}
int main()
{
test(std::list<int>());
test(nasty_list<int>());
}

View File

@@ -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>
// template <BackInsertionContainer Cont>
// front_insert_iterator<Cont>
// front_inserter(Cont& x);
#include <iterator>
#include <list>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::front_insert_iterator<C> i = std::front_inserter(c);
i = 0;
assert(c.size() == 1);
assert(c.front() == 0);
}
int main()
{
test(std::list<int>());
test(nasty_list<int>());
}

View File

@@ -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()
{
}

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// 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>
// front_insert_iterator
// Test nested types and data member:
// template <class Container>
// class front_insert_iterator {
// protected:
// Container* container;
// public:
// typedef Container container_type;
// typedef void value_type;
// typedef void difference_type;
// typedef front_insert_iterator<Cont>& reference;
// typedef void pointer;
// typedef output_iterator_tag iterator_category;
// };
#include <iterator>
#include <type_traits>
#include <vector>
template <class C>
struct find_container
: private std::front_insert_iterator<C>
{
explicit find_container(C& c) : std::front_insert_iterator<C>(c) {}
void test() {this->container = 0;}
};
template <class C>
void
test()
{
typedef std::front_insert_iterator<C> R;
C c;
find_container<C> q(c);
q.test();
static_assert((std::is_same<typename R::container_type, C>::value), "");
static_assert((std::is_same<typename R::value_type, void>::value), "");
static_assert((std::is_same<typename R::difference_type, void>::value), "");
static_assert((std::is_same<typename R::reference, R&>::value), "");
static_assert((std::is_same<typename R::pointer, void>::value), "");
static_assert((std::is_same<typename R::iterator_category, std::output_iterator_tag>::value), "");
}
int main()
{
test<std::vector<int> >();
}

View File

@@ -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>
// insert_iterator
// insert_iterator(Cont& x, Cont::iterator i);
#include <iterator>
#include <vector>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::insert_iterator<C> i(c, c.begin());
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -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>
// insert_iterator
// insert_iterator<Cont> operator++(int);
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::insert_iterator<C> i(c, c.end());
std::insert_iterator<C> r = i++;
r = 0;
assert(c.size() == 1);
assert(c.back() == 0);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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>
// insert_iterator
// insert_iterator<Cont>& operator++();
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::insert_iterator<C> i(c, c.end());
std::insert_iterator<C>& r = ++i;
assert(&r == &i);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// 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>
// insert_iterator
// requires CopyConstructible<Cont::value_type>
// insert_iterator<Cont>&
// operator=(const Cont::value_type& value);
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c1, typename C::difference_type j,
typename C::value_type x1, typename C::value_type x2,
typename C::value_type x3, const C& c2)
{
std::insert_iterator<C> q(c1, c1.begin() + j);
q = x1;
q = x2;
q = x3;
assert(c1 == c2);
}
template <class C>
void
insert3at(C& c, typename C::iterator i,
typename C::value_type x1, typename C::value_type x2,
typename C::value_type x3)
{
i = c.insert(i, x1);
i = c.insert(++i, x2);
c.insert(++i, x3);
}
int main()
{
{
typedef std::vector<int> C;
C c1;
for (int i = 0; i < 3; ++i)
c1.push_back(i);
C c2 = c1;
insert3at(c2, c2.begin(), 'a', 'b', 'c');
test(c1, 0, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+1, 'a', 'b', 'c');
test(c1, 1, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+2, 'a', 'b', 'c');
test(c1, 2, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+3, 'a', 'b', 'c');
test(c1, 3, 'a', 'b', 'c', c2);
}
{
typedef nasty_vector<int> C;
C c1;
for (int i = 0; i < 3; ++i)
c1.push_back(i);
C c2 = c1;
insert3at(c2, c2.begin(), 'a', 'b', 'c');
test(c1, 0, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+1, 'a', 'b', 'c');
test(c1, 1, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+2, 'a', 'b', 'c');
test(c1, 2, 'a', 'b', 'c', c2);
c2 = c1;
insert3at(c2, c2.begin()+3, 'a', 'b', 'c');
test(c1, 3, 'a', 'b', 'c', c2);
}
}

View File

@@ -0,0 +1,97 @@
//===----------------------------------------------------------------------===//
//
// 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>
// insert_iterator
// requires CopyConstructible<Cont::value_type>
// insert_iterator<Cont>&
// operator=(const Cont::value_type& value);
#include <iterator>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <vector>
#include <memory>
#include <cassert>
template <class C>
void
test(C c1, typename C::difference_type j,
typename C::value_type x1, typename C::value_type x2,
typename C::value_type x3, const C& c2)
{
std::insert_iterator<C> q(c1, c1.begin() + j);
q = std::move(x1);
q = std::move(x2);
q = std::move(x3);
assert(c1 == c2);
}
template <class C>
void
insert3at(C& c, typename C::iterator i,
typename C::value_type x1, typename C::value_type x2,
typename C::value_type x3)
{
i = c.insert(i, std::move(x1));
i = c.insert(++i, std::move(x2));
c.insert(++i, std::move(x3));
}
struct do_nothing
{
void operator()(void*) const {}
};
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
typedef std::unique_ptr<int, do_nothing> Ptr;
typedef std::vector<Ptr> C;
C c1;
int x[6] = {0};
for (int i = 0; i < 3; ++i)
c1.push_back(Ptr(x+i));
C c2;
for (int i = 0; i < 3; ++i)
c2.push_back(Ptr(x+i));
insert3at(c2, c2.begin(), Ptr(x+3), Ptr(x+4), Ptr(x+5));
test(std::move(c1), 0, Ptr(x+3), Ptr(x+4), Ptr(x+5), c2);
c1.clear();
for (int i = 0; i < 3; ++i)
c1.push_back(Ptr(x+i));
c2.clear();
for (int i = 0; i < 3; ++i)
c2.push_back(Ptr(x+i));
insert3at(c2, c2.begin()+1, Ptr(x+3), Ptr(x+4), Ptr(x+5));
test(std::move(c1), 1, Ptr(x+3), Ptr(x+4), Ptr(x+5), c2);
c1.clear();
for (int i = 0; i < 3; ++i)
c1.push_back(Ptr(x+i));
c2.clear();
for (int i = 0; i < 3; ++i)
c2.push_back(Ptr(x+i));
insert3at(c2, c2.begin()+2, Ptr(x+3), Ptr(x+4), Ptr(x+5));
test(std::move(c1), 2, Ptr(x+3), Ptr(x+4), Ptr(x+5), c2);
c1.clear();
for (int i = 0; i < 3; ++i)
c1.push_back(Ptr(x+i));
c2.clear();
for (int i = 0; i < 3; ++i)
c2.push_back(Ptr(x+i));
insert3at(c2, c2.begin()+3, Ptr(x+3), Ptr(x+4), Ptr(x+5));
test(std::move(c1), 3, Ptr(x+3), Ptr(x+4), Ptr(x+5), c2);
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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>
// insert_iterator
// insert_iterator<Cont>& operator*();
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::insert_iterator<C> i(c, c.end());
std::insert_iterator<C>& r = *i;
assert(&r == &i);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -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>
// template <InsertionContainer Cont>
// insert_iterator<Cont>
// inserter(Cont& x, Cont::iterator i);
#include <iterator>
#include <vector>
#include <cassert>
#include "nasty_containers.hpp"
template <class C>
void
test(C c)
{
std::insert_iterator<C> i = std::inserter(c, c.end());
i = 0;
assert(c.size() == 1);
assert(c.back() == 0);
}
int main()
{
test(std::vector<int>());
test(nasty_vector<int>());
}

View File

@@ -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()
{
}

View File

@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// 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>
// insert_iterator
// Test nested types and data members:
// template <InsertionContainer Cont>
// class insert_iterator {
// protected:
// Cont* container;
// Cont::iterator iter;
// public:
// typedef Cont container_type;
// typedef void value_type;
// typedef void difference_type;
// typedef insert_iterator<Cont>& reference;
// typedef void pointer;
// };
#include <iterator>
#include <type_traits>
#include <vector>
template <class C>
struct find_members
: private std::insert_iterator<C>
{
explicit find_members(C& c) : std::insert_iterator<C>(c, c.begin()) {}
void test()
{
this->container = 0;
(void)(this->iter == this->iter);
}
};
template <class C>
void
test()
{
typedef std::insert_iterator<C> R;
C c;
find_members<C> q(c);
q.test();
static_assert((std::is_same<typename R::container_type, C>::value), "");
static_assert((std::is_same<typename R::value_type, void>::value), "");
static_assert((std::is_same<typename R::difference_type, void>::value), "");
static_assert((std::is_same<typename R::reference, R&>::value), "");
static_assert((std::is_same<typename R::pointer, void>::value), "");
static_assert((std::is_same<typename R::iterator_category, std::output_iterator_tag>::value), "");
}
int main()
{
test<std::vector<int> >();
}

View File

@@ -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()
{
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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>
// move_iterator
// template <InputIterator Iter>
// move_iterator<Iter>
// make_move_iterator(const Iter& i);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It i)
{
const std::move_iterator<It> r(i);
assert(std::make_move_iterator(i) == r);
}
int main()
{
{
char s[] = "1234567890";
test(input_iterator<char*>(s+5));
test(forward_iterator<char*>(s+5));
test(bidirectional_iterator<char*>(s+5));
test(random_access_iterator<char*>(s+5));
test(s+5);
}
{
int a[] = {1,2,3,4};
std::make_move_iterator(a+4);
std::make_move_iterator(a); // test for LWG issue 2061
}
}

View File

@@ -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>
// move_iterator
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasMinus<Iter1, Iter2>
// auto
// operator-(const move_iterator<Iter1>& x, const move_iterator<Iter2>& y)
// -> decltype(x.base() - y.base());
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It l, It r, typename std::iterator_traits<It>::difference_type x)
{
const std::move_iterator<It> r1(l);
const std::move_iterator<It> r2(r);
assert(r1 - r2 == x);
}
int main()
{
char s[] = "1234567890";
test(random_access_iterator<char*>(s+5), random_access_iterator<char*>(s), 5);
test(s+5, s, 5);
}

View File

@@ -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>
// move_iterator
// template <RandomAccessIterator Iter>
// move_iterator<Iter>
// operator+(Iter::difference_type n, const move_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::move_iterator<It> r(i);
std::move_iterator<It> rr = n + r;
assert(rr.base() == x);
}
int main()
{
char s[] = "1234567890";
test(random_access_iterator<char*>(s+5), 5, random_access_iterator<char*>(s+10));
test(s+5, 5, s+10);
}

View File

@@ -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>
// move_iterator
// requires RandomAccessIterator<Iter>
// move_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::move_iterator<It> r(i);
std::move_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);
}

View File

@@ -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>
// move_iterator
// requires RandomAccessIterator<Iter>
// move_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::move_iterator<It> r(i);
std::move_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);
}

View File

@@ -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>
// move_iterator
// requires RandomAccessIterator<Iter>
// move_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::move_iterator<It> r(i);
std::move_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);
}

View File

@@ -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>
// move_iterator
// requires RandomAccessIterator<Iter>
// move_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::move_iterator<It> r(i);
std::move_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);
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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>
// move_iterator
// template <InputIterator Iter1, InputIterator Iter2>
// requires HasEqualTo<Iter1, Iter2>
// bool
// operator==(const move_iterator<Iter1>& x, const move_iterator<Iter2>& y);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
const std::move_iterator<It> r1(l);
const std::move_iterator<It> r2(r);
assert((r1 == r2) == x);
}
int main()
{
char s[] = "1234567890";
test(input_iterator<char*>(s), input_iterator<char*>(s), true);
test(input_iterator<char*>(s), input_iterator<char*>(s+1), false);
test(forward_iterator<char*>(s), forward_iterator<char*>(s), true);
test(forward_iterator<char*>(s), forward_iterator<char*>(s+1), false);
test(bidirectional_iterator<char*>(s), bidirectional_iterator<char*>(s), true);
test(bidirectional_iterator<char*>(s), bidirectional_iterator<char*>(s+1), false);
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s), true);
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1), false);
test(s, s, true);
test(s, s+1, false);
}

View File

@@ -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>
// move_iterator
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasLess<Iter2, Iter1>
// bool
// operator>(const move_iterator<Iter1>& x, const move_iterator<Iter2>& y);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
const std::move_iterator<It> r1(l);
const std::move_iterator<It> r2(r);
assert((r1 > r2) == x);
}
int main()
{
char s[] = "1234567890";
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s), false);
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1), false);
test(random_access_iterator<char*>(s+1), random_access_iterator<char*>(s), true);
test(s, s, false);
test(s, s+1, false);
test(s+1, s, true);
}

View File

@@ -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>
// move_iterator
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasLess<Iter1, Iter2>
// bool
// operator>=(const move_iterator<Iter1>& x, const move_iterator<Iter2>& y);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
const std::move_iterator<It> r1(l);
const std::move_iterator<It> r2(r);
assert((r1 >= r2) == x);
}
int main()
{
char s[] = "1234567890";
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s), true);
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1), false);
test(random_access_iterator<char*>(s+1), random_access_iterator<char*>(s), true);
test(s, s, true);
test(s, s+1, false);
test(s+1, s, true);
}

View File

@@ -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>
// move_iterator
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasLess<Iter1, Iter2>
// bool
// operator<(const move_iterator<Iter1>& x, const move_iterator<Iter2>& y);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
const std::move_iterator<It> r1(l);
const std::move_iterator<It> r2(r);
assert((r1 < r2) == x);
}
int main()
{
char s[] = "1234567890";
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s), false);
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1), true);
test(random_access_iterator<char*>(s+1), random_access_iterator<char*>(s), false);
test(s, s, false);
test(s, s+1, true);
test(s+1, s, false);
}

View File

@@ -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>
// move_iterator
// template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
// requires HasLess<Iter2, Iter1>
// bool
// operator<=(const move_iterator<Iter1>& x, const move_iterator<Iter2>& y);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
const std::move_iterator<It> r1(l);
const std::move_iterator<It> r2(r);
assert((r1 <= r2) == x);
}
int main()
{
char s[] = "1234567890";
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s), true);
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1), true);
test(random_access_iterator<char*>(s+1), random_access_iterator<char*>(s), false);
test(s, s, true);
test(s, s+1, true);
test(s+1, s, false);
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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>
// move_iterator
// template <InputIterator Iter1, InputIterator Iter2>
// requires HasEqualTo<Iter1, Iter2>
// bool
// operator!=(const move_iterator<Iter1>& x, const move_iterator<Iter2>& y);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It l, It r, bool x)
{
const std::move_iterator<It> r1(l);
const std::move_iterator<It> r2(r);
assert((r1 != r2) == x);
}
int main()
{
char s[] = "1234567890";
test(input_iterator<char*>(s), input_iterator<char*>(s), false);
test(input_iterator<char*>(s), input_iterator<char*>(s+1), true);
test(forward_iterator<char*>(s), forward_iterator<char*>(s), false);
test(forward_iterator<char*>(s), forward_iterator<char*>(s+1), true);
test(bidirectional_iterator<char*>(s), bidirectional_iterator<char*>(s), false);
test(bidirectional_iterator<char*>(s), bidirectional_iterator<char*>(s+1), true);
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s), false);
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1), true);
test(s, s, false);
test(s, s+1, true);
}

View File

@@ -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>
// move_iterator
// template <class U>
// requires HasConstructor<Iter, const U&>
// move_iterator(const move_iterator<U> &u);
// test requires
#include <iterator>
template <class It, class U>
void
test(U u)
{
std::move_iterator<U> r2(u);
std::move_iterator<It> r1 = r2;
}
struct base {};
struct derived {};
int main()
{
derived d;
test<base*>(&d);
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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>
// move_iterator
// template <class U>
// requires HasConstructor<Iter, const U&>
// move_iterator(const move_iterator<U> &u);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It, class U>
void
test(U u)
{
const std::move_iterator<U> r2(u);
std::move_iterator<It> r1 = r2;
assert(r1.base() == u);
}
struct Base {};
struct Derived : Base {};
int main()
{
Derived d;
test<input_iterator<Base*> >(input_iterator<Derived*>(&d));
test<forward_iterator<Base*> >(forward_iterator<Derived*>(&d));
test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d));
test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d));
test<Base*>(&d);
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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>
// move_iterator
// move_iterator();
#include <iterator>
#include "test_iterators.h"
template <class It>
void
test()
{
std::move_iterator<It> r;
}
int main()
{
test<input_iterator<char*> >();
test<forward_iterator<char*> >();
test<bidirectional_iterator<char*> >();
test<random_access_iterator<char*> >();
test<char*>();
}

View File

@@ -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>
// move_iterator
// explicit move_iterator(Iter );
// test explicit
#include <iterator>
template <class It>
void
test(It i)
{
std::move_iterator<It> r = i;
}
int main()
{
char s[] = "123";
test(s);
}

View File

@@ -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>
// move_iterator
// explicit move_iterator(Iter i);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It i)
{
std::move_iterator<It> r(i);
assert(r.base() == i);
}
int main()
{
char s[] = "123";
test(input_iterator<char*>(s));
test(forward_iterator<char*>(s));
test(bidirectional_iterator<char*>(s));
test(random_access_iterator<char*>(s));
test(s);
}

View File

@@ -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()
{
}

View File

@@ -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>
// move_iterator
// move_iterator operator--(int);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It i, It x)
{
std::move_iterator<It> r(i);
std::move_iterator<It> rr = r--;
assert(r.base() == x);
assert(rr.base() == i);
}
int main()
{
char s[] = "123";
test(bidirectional_iterator<char*>(s+1), bidirectional_iterator<char*>(s));
test(random_access_iterator<char*>(s+1), random_access_iterator<char*>(s));
test(s+1, s);
}

View File

@@ -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>
// move_iterator
// move_iterator& operator--();
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It i, It x)
{
std::move_iterator<It> r(i);
std::move_iterator<It>& rr = --r;
assert(r.base() == x);
assert(&rr == &r);
}
int main()
{
char s[] = "123";
test(bidirectional_iterator<char*>(s+1), bidirectional_iterator<char*>(s));
test(random_access_iterator<char*>(s+1), random_access_iterator<char*>(s));
test(s+1, s);
}

View File

@@ -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>
// move_iterator
// move_iterator operator++(int);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It i, It x)
{
std::move_iterator<It> r(i);
std::move_iterator<It> rr = r++;
assert(r.base() == x);
assert(rr.base() == i);
}
int main()
{
char s[] = "123";
test(input_iterator<char*>(s), input_iterator<char*>(s+1));
test(forward_iterator<char*>(s), forward_iterator<char*>(s+1));
test(bidirectional_iterator<char*>(s), bidirectional_iterator<char*>(s+1));
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1));
test(s, s+1);
}

View File

@@ -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>
// move_iterator
// move_iterator& operator++();
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It>
void
test(It i, It x)
{
std::move_iterator<It> r(i);
std::move_iterator<It>& rr = ++r;
assert(r.base() == x);
assert(&rr == &r);
}
int main()
{
char s[] = "123";
test(input_iterator<char*>(s), input_iterator<char*>(s+1));
test(forward_iterator<char*>(s), forward_iterator<char*>(s+1));
test(bidirectional_iterator<char*>(s), bidirectional_iterator<char*>(s+1));
test(random_access_iterator<char*>(s), random_access_iterator<char*>(s+1));
test(s, s+1);
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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>
// move_iterator
// requires RandomAccessIterator<Iter>
// unspecified operator[](difference_type n) const;
#include <iterator>
#include <cassert>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <memory>
#endif
#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::move_iterator<It> r(i);
value_type rr = r[n];
assert(rr == x);
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
struct do_nothing
{
void operator()(void*) const {}
};
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
char s[] = "1234567890";
test(random_access_iterator<char*>(s+5), 4, '0');
test(s+5, 4, '0');
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
int i[5];
typedef std::unique_ptr<int, do_nothing> Ptr;
Ptr p[5];
for (unsigned j = 0; j < 5; ++j)
p[j].reset(i+j);
test(p, 3, Ptr(i+3));
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -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>
// move_iterator
// pointer operator->() const;
#include <iterator>
#include <cassert>
template <class It>
void
test(It i)
{
std::move_iterator<It> r(i);
assert(r.operator->() == i);
}
int main()
{
char s[] = "123";
test(s);
}

View File

@@ -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>
// move_iterator
// reference operator*() const;
#include <iterator>
#include <cassert>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <memory>
#endif
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::move_iterator<It> r(i);
assert(*r == x);
typename std::iterator_traits<It>::value_type x2 = *r;
assert(x2 == x);
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
struct do_nothing
{
void operator()(void*) const {}
};
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
A a;
test(&a, A());
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
int i;
std::unique_ptr<int, do_nothing> p(&i);
test(&p, std::unique_ptr<int, do_nothing>(&i));
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@@ -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>
// move_iterator
// template <class U>
// requires HasAssign<Iter, const U&>
// move_iterator&
// operator=(const move_iterator<U>& u);
// test requires
#include <iterator>
template <class It, class U>
void
test(U u)
{
const std::move_iterator<U> r2(u);
std::move_iterator<It> r1;
r1 = r2;
}
struct base {};
struct derived {};
int main()
{
derived d;
test<base*>(&d);
}

View File

@@ -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>
// move_iterator
// template <class U>
// requires HasAssign<Iter, const U&>
// move_iterator&
// operator=(const move_iterator<U>& u);
#include <iterator>
#include <cassert>
#include "test_iterators.h"
template <class It, class U>
void
test(U u)
{
const std::move_iterator<U> r2(u);
std::move_iterator<It> r1;
std::move_iterator<It>& rr = r1 = r2;
assert(r1.base() == u);
assert(&rr == &r1);
}
struct Base {};
struct Derived : Base {};
int main()
{
Derived d;
test<input_iterator<Base*> >(input_iterator<Derived*>(&d));
test<forward_iterator<Base*> >(forward_iterator<Derived*>(&d));
test<bidirectional_iterator<Base*> >(bidirectional_iterator<Derived*>(&d));
test<random_access_iterator<const Base*> >(random_access_iterator<Derived*>(&d));
test<Base*>(&d);
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// 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>
// move_iterator
// Test nested types:
// template <InputIterator Iter>
// class move_iterator {
// public:
// typedef Iter iterator_type;
// typedef Iter::difference_type difference_type;
// typedef Iterator pointer;
// typedef Iter::value_type value_type;
// typedef value_type&& reference;
// };
#include <iterator>
#include <type_traits>
#include "test_iterators.h"
template <class It>
void
test()
{
typedef std::move_iterator<It> R;
typedef std::iterator_traits<It> T;
static_assert((std::is_same<typename R::iterator_type, It>::value), "");
static_assert((std::is_same<typename R::difference_type, typename T::difference_type>::value), "");
static_assert((std::is_same<typename R::pointer, typename T::pointer>::value), "");
static_assert((std::is_same<typename R::value_type, typename T::value_type>::value), "");
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
static_assert((std::is_same<typename R::reference, typename R::value_type&&>::value), "");
#else
static_assert((std::is_same<typename R::reference, typename T::reference>::value), "");
#endif
static_assert((std::is_same<typename R::iterator_category, typename T::iterator_category>::value), "");
}
int main()
{
test<input_iterator<char*> >();
test<forward_iterator<char*> >();
test<bidirectional_iterator<char*> >();
test<random_access_iterator<char*> >();
test<char*>();
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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()
{
}

View File

@@ -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*>();
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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()
{
}

Some files were not shown because too many files have changed in this diff Show More