diff options
Diffstat (limited to 'libcxx/test/containers/sequences')
322 files changed, 15549 insertions, 0 deletions
diff --git a/libcxx/test/containers/sequences/array/array.cons/default.pass.cpp b/libcxx/test/containers/sequences/array/array.cons/default.pass.cpp new file mode 100644 index 00000000000..c8fc3aafdee --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.cons/default.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// array(); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c; + assert(c.size() == 3); + } + { + typedef double T; + typedef std::array<T, 0> C; + C c; + assert(c.size() == 0); + } +} diff --git a/libcxx/test/containers/sequences/array/array.cons/initializer_list.pass.cpp b/libcxx/test/containers/sequences/array/array.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..f5542831009 --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.cons/initializer_list.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// Construct with initizializer list + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + assert(c.size() == 3); + assert(c[0] == 1); + assert(c[1] == 2); + assert(c[2] == 3.5); + } + { + typedef double T; + typedef std::array<T, 0> C; + C c = {}; + assert(c.size() == 0); + } +} diff --git a/libcxx/test/containers/sequences/array/array.data/data.pass.cpp b/libcxx/test/containers/sequences/array/array.data/data.pass.cpp new file mode 100644 index 00000000000..147fe9eda11 --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.data/data.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// T *data(); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + T* p = c.data(); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3.5); + } + { + typedef double T; + typedef std::array<T, 0> C; + C c = {}; + T* p = c.data(); + } +} diff --git a/libcxx/test/containers/sequences/array/array.data/data_const.pass.cpp b/libcxx/test/containers/sequences/array/array.data/data_const.pass.cpp new file mode 100644 index 00000000000..63d2fcb410c --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.data/data_const.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// const T* data() const; + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + const C c = {1, 2, 3.5}; + const T* p = c.data(); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3.5); + } + { + typedef double T; + typedef std::array<T, 0> C; + const C c = {}; + const T* p = c.data(); + } +} diff --git a/libcxx/test/containers/sequences/array/array.fill/fill.pass.cpp b/libcxx/test/containers/sequences/array/array.fill/fill.pass.cpp new file mode 100644 index 00000000000..d8c3918446b --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.fill/fill.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// void fill(const T& u); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + c.fill(5.5); + assert(c.size() == 3); + assert(c[0] == 5.5); + assert(c[1] == 5.5); + assert(c[2] == 5.5); + } + { + typedef double T; + typedef std::array<T, 0> C; + C c = {}; + c.fill(5.5); + assert(c.size() == 0); + } +} diff --git a/libcxx/test/containers/sequences/array/array.size/size.pass.cpp b/libcxx/test/containers/sequences/array/array.size/size.pass.cpp new file mode 100644 index 00000000000..3f9d7b9ff58 --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.size/size.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <class T, size_t N> constexpr size_type array<T,N>::size(); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + assert(c.size() == 3); + } + { + typedef double T; + typedef std::array<T, 0> C; + C c = {}; + assert(c.size() == 0); + } +} diff --git a/libcxx/test/containers/sequences/array/array.special/swap.pass.cpp b/libcxx/test/containers/sequences/array/array.special/swap.pass.cpp new file mode 100644 index 00000000000..4b0a47f1372 --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.special/swap.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <class T, size_t N> void swap(array<T,N>& x, array<T,N>& y); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c1 = {1, 2, 3.5}; + C c2 = {4, 5, 6.5}; + swap(c1, c2); + assert(c1.size() == 3); + assert(c1[0] == 4); + assert(c1[1] == 5); + assert(c1[2] == 6.5); + assert(c2.size() == 3); + assert(c2[0] == 1); + assert(c2[1] == 2); + assert(c2[2] == 3.5); + } + { + typedef double T; + typedef std::array<T, 0> C; + C c1 = {}; + C c2 = {}; + swap(c1, c2); + assert(c1.size() == 0); + assert(c2.size() == 0); + } +} diff --git a/libcxx/test/containers/sequences/array/array.swap/swap.pass.cpp b/libcxx/test/containers/sequences/array/array.swap/swap.pass.cpp new file mode 100644 index 00000000000..447077569f5 --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.swap/swap.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// void swap(array& a); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c1 = {1, 2, 3.5}; + C c2 = {4, 5, 6.5}; + c1.swap(c2); + assert(c1.size() == 3); + assert(c1[0] == 4); + assert(c1[1] == 5); + assert(c1[2] == 6.5); + assert(c2.size() == 3); + assert(c2[0] == 1); + assert(c2[1] == 2); + assert(c2[2] == 3.5); + } + { + typedef double T; + typedef std::array<T, 0> C; + C c1 = {}; + C c2 = {}; + c1.swap(c2); + assert(c1.size() == 0); + assert(c2.size() == 0); + } +} diff --git a/libcxx/test/containers/sequences/array/array.tuple/get.pass.cpp b/libcxx/test/containers/sequences/array/array.tuple/get.pass.cpp new file mode 100644 index 00000000000..8fc28c7db7a --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.tuple/get.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <size_t I, class T, size_t N> T& get(array<T, N>& a); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + std::get<1>(c) = 5.5; + assert(c[0] == 1); + assert(c[1] == 5.5); + assert(c[2] == 3.5); + } +} diff --git a/libcxx/test/containers/sequences/array/array.tuple/get_const.pass.cpp b/libcxx/test/containers/sequences/array/array.tuple/get_const.pass.cpp new file mode 100644 index 00000000000..6380bc8c038 --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.tuple/get_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <size_t I, class T, size_t N> const T& get(const array<T, N>& a); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + const C c = {1, 2, 3.5}; + assert(std::get<0>(c) == 1); + assert(std::get<1>(c) == 2); + assert(std::get<2>(c) == 3.5); + } +} diff --git a/libcxx/test/containers/sequences/array/array.tuple/tuple_element.pass.cpp b/libcxx/test/containers/sequences/array/array.tuple/tuple_element.pass.cpp new file mode 100644 index 00000000000..fd58ed76681 --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.tuple/tuple_element.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// tuple_element<I, array<T, N> >::type + +#include <array> +#include <type_traits> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + static_assert((std::is_same<std::tuple_element<0, C>::type, T>::value), ""); + static_assert((std::is_same<std::tuple_element<1, C>::type, T>::value), ""); + static_assert((std::is_same<std::tuple_element<2, C>::type, T>::value), ""); + } + { + typedef int T; + typedef std::array<T, 3> C; + static_assert((std::is_same<std::tuple_element<0, C>::type, T>::value), ""); + static_assert((std::is_same<std::tuple_element<1, C>::type, T>::value), ""); + static_assert((std::is_same<std::tuple_element<2, C>::type, T>::value), ""); + } +} diff --git a/libcxx/test/containers/sequences/array/array.tuple/tuple_size.pass.cpp b/libcxx/test/containers/sequences/array/array.tuple/tuple_size.pass.cpp new file mode 100644 index 00000000000..403fbd3807d --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.tuple/tuple_size.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// tuple_size<array<T, N> >::value + +#include <array> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + static_assert((std::tuple_size<C>::value == 3), ""); + } + { + typedef double T; + typedef std::array<T, 0> C; + static_assert((std::tuple_size<C>::value == 0), ""); + } +} diff --git a/libcxx/test/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp b/libcxx/test/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp new file mode 100644 index 00000000000..9dc64a0f46a --- /dev/null +++ b/libcxx/test/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// support for zero-sized array + +#include <array> + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/array/begin.pass.cpp b/libcxx/test/containers/sequences/array/begin.pass.cpp new file mode 100644 index 00000000000..98f456fc9ca --- /dev/null +++ b/libcxx/test/containers/sequences/array/begin.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// iterator begin(); + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + C::iterator i = c.begin(); + assert(*i == 1); + assert(&*i == c.data()); + *i = 5.5; + assert(c[0] == 5.5); + } + { + } +} diff --git a/libcxx/test/containers/sequences/array/types.pass.cpp b/libcxx/test/containers/sequences/array/types.pass.cpp new file mode 100644 index 00000000000..f1f200f4e4b --- /dev/null +++ b/libcxx/test/containers/sequences/array/types.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <class T, size_t N > +// struct array +// { +// // types: +// typedef T& reference; +// typedef const T& const_reference; +// typedef implementation defined iterator; +// typedef implementation defined const_iterator; +// typedef T value_type; +// typedef T* pointer; +// typedef size_t size_type; +// typedef ptrdiff_t difference_type; +// typedef T value_type; +// typedef std::reverse_iterator<iterator> reverse_iterator; +// typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + +#include <array> +#include <iterator> +#include <type_traits> + +int main() +{ + { + typedef double T; + typedef std::array<T, 10> C; + static_assert((std::is_same<C::reference, T&>::value), ""); + static_assert((std::is_same<C::const_reference, const T&>::value), ""); + static_assert((std::is_same<C::iterator, T*>::value), ""); + static_assert((std::is_same<C::const_iterator, const T*>::value), ""); + static_assert((std::is_same<C::pointer, T*>::value), ""); + static_assert((std::is_same<C::const_pointer, const T*>::value), ""); + static_assert((std::is_same<C::size_type, std::size_t>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<C::reverse_iterator, std::reverse_iterator<C::iterator> >::value), ""); + static_assert((std::is_same<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator> >::value), ""); + } + { + typedef int* T; + typedef std::array<T, 0> C; + static_assert((std::is_same<C::reference, T&>::value), ""); + static_assert((std::is_same<C::const_reference, const T&>::value), ""); + static_assert((std::is_same<C::iterator, T*>::value), ""); + static_assert((std::is_same<C::const_iterator, const T*>::value), ""); + static_assert((std::is_same<C::pointer, T*>::value), ""); + static_assert((std::is_same<C::const_pointer, const T*>::value), ""); + static_assert((std::is_same<C::size_type, std::size_t>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + static_assert((std::is_same<C::reverse_iterator, std::reverse_iterator<C::iterator> >::value), ""); + static_assert((std::is_same<C::const_reverse_iterator, std::reverse_iterator<C::const_iterator> >::value), ""); + } +} diff --git a/libcxx/test/containers/sequences/array/version.pass.cpp b/libcxx/test/containers/sequences/array/version.pass.cpp new file mode 100644 index 00000000000..fed0e116c86 --- /dev/null +++ b/libcxx/test/containers/sequences/array/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +#include <array> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/container.adaptors/nothing_to_do.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..fa4d462f18d --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp new file mode 100644 index 00000000000..5c9178297f3 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// explicit priority_queue(const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" + +template <class T> +struct test + : public std::priority_queue<T, std::vector<T, test_allocator<T> > > +{ + typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const value_compare& comp, const test_allocator<int>& a) + : base(comp, c, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator<int>& a) : base(comp, c, a) {} +#ifdef _LIBCPP_MOVE + test(const value_compare& comp, container_type&& c, + const test_allocator<int>& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif + test_allocator<int> get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + test<int> q((test_allocator<int>(3))); + assert(q.c.get_allocator() == test_allocator<int>(3)); + assert(q.c.size() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp new file mode 100644 index 00000000000..399018a14eb --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// priority_queue(const Compare& comp, const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" + +template <class T> +struct test + : public std::priority_queue<T, std::vector<T, test_allocator<T> > > +{ + typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const value_compare& comp, const test_allocator<int>& a) + : base(comp, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator<int>& a) : base(comp, c, a) {} +#ifdef _LIBCPP_MOVE + test(const value_compare& comp, container_type&& c, + const test_allocator<int>& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif + test_allocator<int> get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + test<int> q(std::less<int>(), test_allocator<int>(3)); + assert(q.c.get_allocator() == test_allocator<int>(3)); + assert(q.c.size() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp new file mode 100644 index 00000000000..467b3fa8998 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// priority_queue(const Compare& comp, const container_type& c, +// const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +template <class T> +struct test + : public std::priority_queue<T, std::vector<T, test_allocator<T> > > +{ + typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const value_compare& comp, const test_allocator<int>& a) + : base(comp, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator<int>& a) : base(comp, c, a) {} +#ifdef _LIBCPP_MOVE + test(const value_compare& comp, container_type&& c, + const test_allocator<int>& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif + test_allocator<int> get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + typedef std::vector<int, test_allocator<int> > C; + C v = make<C>(5); + test<int> q(std::less<int>(), v, test_allocator<int>(3)); + assert(q.c.get_allocator() == test_allocator<int>(3)); + assert(q.size() == 5); + assert(q.top() == 4); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp new file mode 100644 index 00000000000..a4fb5b3b0b6 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// priority_queue(const Compare& comp, container_type&& c, +// const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +template <class T> +struct test + : public std::priority_queue<T, std::vector<T, test_allocator<T> > > +{ + typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const value_compare& comp, const test_allocator<int>& a) + : base(comp, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator<int>& a) : base(comp, c, a) {} +#ifdef _LIBCPP_MOVE + test(const value_compare& comp, container_type&& c, + const test_allocator<int>& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif + test_allocator<int> get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + typedef std::vector<int, test_allocator<int> > C; + test<int> q(std::less<int>(), make<C>(5), test_allocator<int>(3)); + assert(q.c.get_allocator() == test_allocator<int>(3)); + assert(q.size() == 5); + assert(q.top() == 4); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp new file mode 100644 index 00000000000..f526cb44d47 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// priority_queue(const priority_queue& q, const Alloc& a); + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +#include "../../../../test_allocator.h" + +template <class T> +struct test + : public std::priority_queue<T, std::vector<T, test_allocator<T> > > +{ + typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const value_compare& comp, const test_allocator<int>& a) + : base(comp, c, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator<int>& a) : base(comp, c, a) {} + test(const test& q, const test_allocator<int>& a) : base(q, a) {} + test_allocator<int> get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + test<int> qo(std::less<int>(), + make<std::vector<int, test_allocator<int> > >(5), + test_allocator<int>(2)); + test<int> q(qo, test_allocator<int>(6)); + assert(q.size() == 5); + assert(q.c.get_allocator() == test_allocator<int>(6)); + assert(q.top() == int(4)); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_move_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_move_alloc.pass.cpp new file mode 100644 index 00000000000..40361a4738a --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_move_alloc.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// priority_queue(priority_queue&& q, const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#include "../../../../test_allocator.h" + +template <class T> +struct test + : public std::priority_queue<T, std::vector<T, test_allocator<T> > > +{ + typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const value_compare& comp, const test_allocator<int>& a) + : base(comp, c, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator<int>& a) : base(comp, c, a) {} + test(const value_compare& comp, container_type&& c, + const test_allocator<int>& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} + test_allocator<int> get_allocator() {return c.get_allocator();} + + using base::c; +}; + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + test<MoveOnly> qo(std::less<MoveOnly>(), + make<std::vector<MoveOnly, test_allocator<MoveOnly> > >(5), + test_allocator<MoveOnly>(2)); + test<MoveOnly> q(std::move(qo), test_allocator<MoveOnly>(6)); + assert(q.size() == 5); + assert(q.c.get_allocator() == test_allocator<MoveOnly>(6)); + assert(q.top() == MoveOnly(4)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/assign_copy.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..d6965400427 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/assign_copy.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue& operator=(const priority_queue&) = default; + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::vector<int> v = make<std::vector<int> >(5); + std::priority_queue<int, std::vector<int>, std::greater<int> > qo(std::greater<int>(), v); + std::priority_queue<int, std::vector<int>, std::greater<int> > q; + q = qo; + assert(q.size() == 5); + assert(q.top() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/assign_move.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..70d75c623ed --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/assign_move.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue& operator=(priority_queue&& q); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::priority_queue<MoveOnly> qo(std::less<MoveOnly>(), make<std::vector<MoveOnly> >(5)); + std::priority_queue<MoveOnly> q; + q = std::move(qo); + assert(q.size() == 5); + assert(q.top() == MoveOnly(4)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp.pass.cpp new file mode 100644 index 00000000000..ea3a5cc7e43 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// explicit priority_queue(const Compare& comp); + +#include <queue> +#include <cassert> + +#include "../../../../stack_allocator.h" + +int main() +{ + std::priority_queue<int, std::vector<int, stack_allocator<int, 10> > > q((std::less<int>())); + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp_container.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp_container.pass.cpp new file mode 100644 index 00000000000..b8a178cf959 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp_container.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// explicit priority_queue(const Compare& comp, const container_type& c); + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::vector<int> v = make<std::vector<int> >(5); + std::priority_queue<int, std::vector<int>, std::greater<int> > q(std::greater<int>(), v); + assert(q.size() == 5); + assert(q.top() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp_rcontainer.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp_rcontainer.pass.cpp new file mode 100644 index 00000000000..9fb559fdfe1 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_comp_rcontainer.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// explicit priority_queue(const Compare& comp, container_type&& c); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::priority_queue<MoveOnly> q(std::less<MoveOnly>(), make<std::vector<MoveOnly> >(5)); + assert(q.size() == 5); + assert(q.top() == MoveOnly(4)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_copy.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_copy.pass.cpp new file mode 100644 index 00000000000..ce1a46ad937 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_copy.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(const priority_queue&) = default; + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::vector<int> v = make<std::vector<int> >(5); + std::priority_queue<int, std::vector<int>, std::greater<int> > qo(std::greater<int>(), v); + std::priority_queue<int, std::vector<int>, std::greater<int> > q = qo; + assert(q.size() == 5); + assert(q.top() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_default.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_default.pass.cpp new file mode 100644 index 00000000000..547d0f1d389 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_default.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +#include <queue> +#include <cassert> + +#include "../../../../stack_allocator.h" + +int main() +{ + std::priority_queue<int, std::vector<int, stack_allocator<int, 10> > > q; + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter.pass.cpp new file mode 100644 index 00000000000..4ba4aa60f62 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class InputIterator> +// priority_queue(InputIterator first, InputIterator last); + +#include <queue> +#include <cassert> + +int main() +{ + int a[] = {3, 5, 2, 0, 6, 8, 1}; + int* an = a + sizeof(a)/sizeof(a[0]); + std::priority_queue<int> q(a, an); + assert(q.size() == an - a); + assert(q.top() == 8); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..87c29abd177 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class InputIterator> +// priority_queue(InputIterator first, InputIterator last, const Compare& comp); + +#include <queue> +#include <cassert> + +int main() +{ + int a[] = {3, 5, 2, 0, 6, 8, 1}; + int* an = a + sizeof(a)/sizeof(a[0]); + std::priority_queue<int, std::vector<int>, std::greater<int> > + q(a, an, std::greater<int>()); + assert(q.size() == an - a); + assert(q.top() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_cont.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_cont.pass.cpp new file mode 100644 index 00000000000..4d56b773ea3 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_cont.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class InputIterator> +// priority_queue(InputIterator first, InputIterator last, +// const Compare& comp, const container_type& c); + +#include <queue> +#include <cassert> + +int main() +{ + int a[] = {3, 5, 2, 0, 6, 8, 1}; + const int n = sizeof(a)/sizeof(a[0]); + std::vector<int> v(a, a+n/2); + std::priority_queue<int> q(a+n/2, a+n, std::less<int>(), v); + assert(q.size() == n); + assert(q.top() == 8); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_rcont.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_rcont.pass.cpp new file mode 100644 index 00000000000..c13c97f5ced --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_rcont.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class InputIterator> +// priority_queue(InputIterator first, InputIterator last, +// const Compare& comp, container_type&& c); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + int a[] = {3, 5, 2, 0, 6, 8, 1}; + const int n = sizeof(a)/sizeof(a[0]); + std::priority_queue<MoveOnly> q(a+n/2, a+n, + std::less<MoveOnly>(), + std::vector<MoveOnly>(a, a+n/2)); + assert(q.size() == n); + assert(q.top() == MoveOnly(8)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_move.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_move.pass.cpp new file mode 100644 index 00000000000..e7629725e9f --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.cons/ctor_move.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(priority_queue&& q); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::priority_queue<MoveOnly> qo(std::less<MoveOnly>(), make<std::vector<MoveOnly> >(5)); + std::priority_queue<MoveOnly> q = std::move(qo); + assert(q.size() == 5); + assert(q.top() == MoveOnly(4)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/emplace.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/emplace.pass.cpp new file mode 100644 index 00000000000..8651e1efa94 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/emplace.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// template <class... Args> void emplace(Args&&... args); + +#include <queue> +#include <cassert> + +#include "../../../../Emplaceable.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::priority_queue<Emplaceable> q; + q.emplace(1, 2.5); + assert(q.top() == Emplaceable(1, 2.5)); + q.emplace(3, 4.5); + assert(q.top() == Emplaceable(3, 4.5)); + q.emplace(2, 3.5); + assert(q.top() == Emplaceable(3, 4.5)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/empty.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/empty.pass.cpp new file mode 100644 index 00000000000..53397ce98cc --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/empty.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// bool empty() const; + + +#include <queue> +#include <cassert> + +int main() +{ + std::priority_queue<int> q; + assert(q.empty()); + q.push(1); + assert(!q.empty()); + q.pop(); + assert(q.empty()); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/pop.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/pop.pass.cpp new file mode 100644 index 00000000000..858224d537d --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/pop.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// void pop(); + +#include <queue> +#include <cassert> + +int main() +{ + std::priority_queue<int> q; + q.push(1); + assert(q.top() == 1); + q.push(3); + assert(q.top() == 3); + q.push(2); + assert(q.top() == 3); + q.pop(); + assert(q.top() == 2); + q.pop(); + assert(q.top() == 1); + q.pop(); + assert(q.empty()); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/push.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/push.pass.cpp new file mode 100644 index 00000000000..ba706912f5b --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/push.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// void push(const value_type& v); + +#include <queue> +#include <cassert> + +int main() +{ + std::priority_queue<int> q; + q.push(1); + assert(q.top() == 1); + q.push(3); + assert(q.top() == 3); + q.push(2); + assert(q.top() == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/push_rvalue.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/push_rvalue.pass.cpp new file mode 100644 index 00000000000..0db166ae85a --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/push_rvalue.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// void push(value_type&& v); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::priority_queue<MoveOnly> q; + q.push(1); + assert(q.top() == 1); + q.push(3); + assert(q.top() == 3); + q.push(2); + assert(q.top() == 3); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/size.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/size.pass.cpp new file mode 100644 index 00000000000..a75523e12b4 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/size.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// size_type size() const; + +#include <queue> +#include <cassert> + +int main() +{ + std::priority_queue<int> q; + assert(q.size() == 0); + q.push(1); + assert(q.size() == 1); + q.pop(); + assert(q.size() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/swap.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/swap.pass.cpp new file mode 100644 index 00000000000..729604b7ed9 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/swap.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// void swap(priority_queue& q); + +#include <queue> +#include <cassert> + +int main() +{ + std::priority_queue<int> q1; + std::priority_queue<int> q2; + q1.push(1); + q1.push(3); + q1.push(2); + q1.swap(q2); + assert(q1.empty()); + assert(q2.size() == 3); + assert(q2.top() == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/top.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/top.pass.cpp new file mode 100644 index 00000000000..014bbfa82dd --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.members/top.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// const_reference top() const; + +#include <queue> +#include <cassert> + +int main() +{ + std::priority_queue<int> q; + q.push(1); + assert(q.top() == 1); + q.push(3); + assert(q.top() == 3); + q.push(2); + assert(q.top() == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.special/swap.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.special/swap.pass.cpp new file mode 100644 index 00000000000..6987f73743e --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/priqueue.special/swap.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// priority_queue(); + +// template <class T, class Container, class Compare> +// void swap(priority_queue<T, Container, Compare>& x, +// priority_queue<T, Container, Compare>& y); + +#include <queue> +#include <cassert> + +int main() +{ + std::priority_queue<int> q1; + std::priority_queue<int> q2; + q1.push(1); + q1.push(3); + q1.push(2); + swap(q1, q2); + assert(q1.empty()); + assert(q2.size() == 3); + assert(q2.top() == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/priority.queue/types.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/priority.queue/types.pass.cpp new file mode 100644 index 00000000000..13051b0c1c4 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/priority.queue/types.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class T, class Container = vector<T>, +// class Compare = less<typename Container::value_type>> +// class priority_queue +// { +// public: +// typedef Container container_type; +// typedef typename container_type::value_type value_type; +// typedef typename container_type::reference reference; +// typedef typename container_type::const_reference const_reference; +// typedef typename container_type::size_type size_type; +// +// protected: +// container_type c; +// Compare comp; + +#include <queue> +#include <cassert> +#include <type_traits> + +struct test + : private std::priority_queue<int> +{ + test() + { + c.push_back(1); + assert(comp(1, 2)); + } +}; + +struct C +{ + typedef int value_type; + typedef int& reference; + typedef const int& const_reference; + typedef int size_type; +}; + +int main() +{ + static_assert((std::is_same<std::priority_queue<int>::container_type, std::vector<int> >::value), ""); + static_assert((std::is_same<std::priority_queue<double, std::deque<int> >::container_type, std::deque<int> >::value), ""); + static_assert((std::is_same<std::priority_queue<double, std::deque<int> >::value_type, int>::value), ""); + static_assert((std::is_same<std::priority_queue<int>::reference, std::vector<int>::reference>::value), ""); + static_assert((std::is_same<std::priority_queue<int>::const_reference, std::vector<int>::const_reference>::value), ""); + static_assert((std::is_same<std::priority_queue<int>::size_type, std::vector<int>::size_type>::value), ""); + static_assert((std::uses_allocator<std::priority_queue<int>, std::allocator<int> >::value), ""); + static_assert((!std::uses_allocator<std::priority_queue<int, C>, std::allocator<int> >::value), ""); + test t; +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_alloc.pass.cpp new file mode 100644 index 00000000000..07bc9ccf19a --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_alloc.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// explicit queue(const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" + +struct test + : private std::queue<int, std::deque<int, test_allocator<int> > > +{ + typedef std::queue<int, std::deque<int, test_allocator<int> > > base; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const container_type& c, const test_allocator<int>& a) : base(c, a) {} +#ifdef _LIBCPP_MOVE + test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif + test_allocator<int> get_allocator() {return c.get_allocator();} +}; + +int main() +{ + test q(test_allocator<int>(3)); + assert(q.get_allocator() == test_allocator<int>(3)); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp new file mode 100644 index 00000000000..ae93fd3ee9f --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// queue(const container_type& c, const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +typedef std::deque<int, test_allocator<int> > C; + +struct test + : public std::queue<int, C> +{ + typedef std::queue<int, C> base; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const container_type& c, const test_allocator<int>& a) : base(c, a) {} +#ifdef _LIBCPP_MOVE + test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif + test_allocator<int> get_allocator() {return c.get_allocator();} +}; + +int main() +{ + C d = make<C>(5); + test q(d, test_allocator<int>(4)); + assert(q.get_allocator() == test_allocator<int>(4)); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.front() == d[i]); + q.pop(); + } +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_queue_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_queue_alloc.pass.cpp new file mode 100644 index 00000000000..a3b119246b5 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_queue_alloc.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// queue(const queue& q, const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +typedef std::deque<int, test_allocator<int> > C; + +template <class T> +struct test + : public std::queue<T, C> +{ + typedef std::queue<T, C> base; + typedef test_allocator<int> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(const test& q, const allocator_type& a) : base(q, a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +int main() +{ + test<int> q(make<C>(5), test_allocator<int>(4)); + test<int> q2(q, test_allocator<int>(5)); + assert(q2.get_allocator() == test_allocator<int>(5)); + assert(q2.size() == 5); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_rcontainer_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_rcontainer_alloc.pass.cpp new file mode 100644 index 00000000000..21b73c3ae13 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_rcontainer_alloc.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// queue(const container_type& c, const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque<MoveOnly, test_allocator<MoveOnly> > C; + +template <class T> +struct test + : public std::queue<T, C> +{ + typedef std::queue<T, C> base; + typedef test_allocator<MoveOnly> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + test<MoveOnly> q(make<C>(5), test_allocator<MoveOnly>(4)); + assert(q.get_allocator() == test_allocator<MoveOnly>(4)); + assert(q.size() == 5); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_rqueue_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_rqueue_alloc.pass.cpp new file mode 100644 index 00000000000..1789c9fe596 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons.alloc/ctor_rqueue_alloc.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class Alloc> +// queue(queue&& q, const Alloc& a); + +#include <queue> +#include <cassert> + +#include "../../../../test_allocator.h" +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque<MoveOnly, test_allocator<MoveOnly> > C; + +template <class T> +struct test + : public std::queue<T, C> +{ + typedef std::queue<T, C> base; + typedef test_allocator<MoveOnly> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + test<MoveOnly> q(make<C>(5), test_allocator<MoveOnly>(4)); + test<MoveOnly> q2(std::move(q), test_allocator<MoveOnly>(5)); + assert(q2.get_allocator() == test_allocator<MoveOnly>(5)); + assert(q2.size() == 5); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_container.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_container.pass.cpp new file mode 100644 index 00000000000..66d813df29c --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_container.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// explicit queue(const container_type& c); + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::deque<int> d = make<std::deque<int> >(5); + std::queue<int> q(d); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.front() == d[i]); + q.pop(); + } +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_copy.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_copy.pass.cpp new file mode 100644 index 00000000000..d96d01365db --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// queue(const queue&) = default; + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::queue<int> q(make<std::deque<int> >(5)); + std::queue<int> q2 = q; + assert(q2 == q); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_default.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_default.pass.cpp new file mode 100644 index 00000000000..188a7cd2019 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_default.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// queue(); + +#include <queue> +#include <cassert> + +#include "../../../../stack_allocator.h" + +int main() +{ + std::queue<int, std::vector<int, stack_allocator<int, 10> > > q; + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.front() == 1); + assert(q.back() == 2); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_move.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_move.pass.cpp new file mode 100644 index 00000000000..d9a8e0b8424 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_move.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// queue(queue&& q); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::queue<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + std::queue<MoveOnly> q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_rcontainer.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_rcontainer.pass.cpp new file mode 100644 index 00000000000..123b6712669 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.cons/ctor_rcontainer.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// explicit queue(container_type&& c); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::queue<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + assert(q.size() == 5); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/assign_copy.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/assign_copy.pass.cpp new file mode 100644 index 00000000000..0d3cb3e7a5d --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/assign_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// queue& operator=(const queue& q); + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::queue<int> q(make<std::deque<int> >(5)); + std::queue<int> q2; + q2 = q; + assert(q2 == q); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/assign_move.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/assign_move.pass.cpp new file mode 100644 index 00000000000..bae8db1e319 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/assign_move.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// queue& operator=(queue&& q); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::queue<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + std::queue<MoveOnly> q2; + q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/back.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/back.pass.cpp new file mode 100644 index 00000000000..55e28bb7b35 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/back.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// reference back(); + +#include <queue> +#include <cassert> + +int main() +{ + std::queue<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + int& ir = q.back(); + assert(ir == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/back_const.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/back_const.pass.cpp new file mode 100644 index 00000000000..fc39b6bb9e7 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/back_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// const_reference back() const; + +#include <queue> +#include <cassert> + +int main() +{ + std::queue<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + const std::queue<int>& cqr = q; + const int& cir = cqr.back(); + assert(cir == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/emplace.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/emplace.pass.cpp new file mode 100644 index 00000000000..115887502f7 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/emplace.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class... Args> void emplace(Args&&... args); + +#include <queue> +#include <cassert> + +#include "../../../../Emplaceable.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::queue<Emplaceable> q; + q.emplace(1, 2.5); + q.emplace(2, 3.5); + q.emplace(3, 4.5); + assert(q.size() == 3); + assert(q.front() == Emplaceable(1, 2.5)); + assert(q.back() == Emplaceable(3, 4.5)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/empty.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/empty.pass.cpp new file mode 100644 index 00000000000..a59ef7c8fb6 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/empty.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// bool empty() const; + +#include <queue> +#include <cassert> + +int main() +{ + std::queue<int> q; + assert(q.empty()); + q.push(1); + assert(!q.empty()); + q.pop(); + assert(q.empty()); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/front.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/front.pass.cpp new file mode 100644 index 00000000000..0f57001ed84 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/front.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// reference front(); + +#include <queue> +#include <cassert> + +int main() +{ + std::queue<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + int& ir = q.front(); + assert(ir == 1); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/front_const.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/front_const.pass.cpp new file mode 100644 index 00000000000..b3e1b560bcd --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/front_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// const_reference front() const; + +#include <queue> +#include <cassert> + +int main() +{ + std::queue<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + const std::queue<int>& cqr = q; + const int& cir = cqr.front(); + assert(cir == 1); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/pop.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/pop.pass.cpp new file mode 100644 index 00000000000..df32f893e40 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/pop.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// void pop(); + +#include <queue> +#include <cassert> + +int main() +{ + std::queue<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + assert(q.size() == 3); + assert(q.front() == 1); + assert(q.back() == 3); + q.pop(); + assert(q.size() == 2); + assert(q.front() == 2); + assert(q.back() == 3); + q.pop(); + assert(q.size() == 1); + assert(q.front() == 3); + assert(q.back() == 3); + q.pop(); + assert(q.size() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/push.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/push.pass.cpp new file mode 100644 index 00000000000..4a0b6507c94 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/push.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// void push(const value_type& v); + +#include <queue> +#include <cassert> + +int main() +{ + std::queue<int> q; + q.push(1); + assert(q.size() == 1); + assert(q.front() == 1); + assert(q.back() == 1); + q.push(2); + assert(q.size() == 2); + assert(q.front() == 1); + assert(q.back() == 2); + q.push(3); + assert(q.size() == 3); + assert(q.front() == 1); + assert(q.back() == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/push_rv.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/push_rv.pass.cpp new file mode 100644 index 00000000000..356410ef944 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/push_rv.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// void push(value_type&& v); + +#include <queue> +#include <cassert> + +#include "../../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::queue<MoveOnly> q; + q.push(MoveOnly(1)); + assert(q.size() == 1); + assert(q.front() == MoveOnly(1)); + assert(q.back() == MoveOnly(1)); + q.push(MoveOnly(2)); + assert(q.size() == 2); + assert(q.front() == MoveOnly(1)); + assert(q.back() == MoveOnly(2)); + q.push(MoveOnly(3)); + assert(q.size() == 3); + assert(q.front() == MoveOnly(1)); + assert(q.back() == MoveOnly(3)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/size.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/size.pass.cpp new file mode 100644 index 00000000000..9d584458ef2 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/size.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// size_type size() const; + +#include <queue> +#include <cassert> + +int main() +{ + std::queue<int> q; + assert(q.size() == 0); + q.push(1); + assert(q.size() == 1); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/swap.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/swap.pass.cpp new file mode 100644 index 00000000000..c22092114ff --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/swap.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// void swap(queue& q); + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::queue<int> q1 = make<std::queue<int> >(5); + std::queue<int> q2 = make<std::queue<int> >(10); + std::queue<int> q1_save = q1; + std::queue<int> q2_save = q2; + q1.swap(q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/types.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/types.pass.cpp new file mode 100644 index 00000000000..8e3aaecb52d --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.defn/types.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class T, class Container = deque<T>> +// class queue +// { +// public: +// typedef Container container_type; +// typedef typename container_type::value_type value_type; +// typedef typename container_type::reference reference; +// typedef typename container_type::const_reference const_reference; +// typedef typename container_type::size_type size_type; +// +// protected: +// container_type c; +// ... +// }; + +#include <queue> +#include <type_traits> + +struct test + : private std::queue<int> +{ + test() + { + c.push_back(1); + } +}; + +struct C +{ + typedef int value_type; + typedef int& reference; + typedef const int& const_reference; + typedef int size_type; +}; + +int main() +{ + static_assert((std::is_same<std::queue<int>::container_type, std::deque<int> >::value), ""); + static_assert((std::is_same<std::queue<double, std::vector<int> >::container_type, std::vector<int> >::value), ""); + static_assert((std::is_same<std::queue<double, std::vector<int> >::value_type, int>::value), ""); + static_assert((std::is_same<std::queue<int>::reference, std::deque<int>::reference>::value), ""); + static_assert((std::is_same<std::queue<int>::const_reference, std::deque<int>::const_reference>::value), ""); + static_assert((std::is_same<std::queue<int>::size_type, std::deque<int>::size_type>::value), ""); + static_assert((std::uses_allocator<std::queue<int>, std::allocator<int> >::value), ""); + static_assert((!std::uses_allocator<std::queue<int, C>, std::allocator<int> >::value), ""); + test t; +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.ops/eq.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.ops/eq.pass.cpp new file mode 100644 index 00000000000..32cdc5e66d4 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.ops/eq.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class T, class Container> +// bool operator==(const queue<T, Container>& x,const queue<T, Container>& y); +// +// template <class T, class Container> +// bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y); + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::queue<int> q1 = make<std::queue<int> >(5); + std::queue<int> q2 = make<std::queue<int> >(10); + std::queue<int> q1_save = q1; + std::queue<int> q2_save = q2; + assert(q1 == q1_save); + assert(q1 != q2); + assert(q2 == q2_save); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.ops/lt.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.ops/lt.pass.cpp new file mode 100644 index 00000000000..ac2c0d4ecb7 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.ops/lt.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class T, class Container> +// bool operator< (const queue<T, Container>& x,const queue<T, Container>& y); +// +// template <class T, class Container> +// bool operator> (const queue<T, Container>& x,const queue<T, Container>& y); +// +// template <class T, class Container> +// bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y); +// +// template <class T, class Container> +// bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y); + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::queue<int> q1 = make<std::queue<int> >(5); + std::queue<int> q2 = make<std::queue<int> >(10); + assert(q1 < q2); + assert(q2 > q1); + assert(q1 <= q2); + assert(q2 >= q1); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/queue.special/swap.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/queue.special/swap.pass.cpp new file mode 100644 index 00000000000..cdbb84aa3af --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/queue.special/swap.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +// template <class T, class Container> +// void swap(queue<T, Container>& x, queue<T, Container>& y); + +#include <queue> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::queue<int> q1 = make<std::queue<int> >(5); + std::queue<int> q2 = make<std::queue<int> >(10); + std::queue<int> q1_save = q1; + std::queue<int> q2_save = q2; + swap(q1, q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/queue/version.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/queue/version.pass.cpp new file mode 100644 index 00000000000..75155973b91 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/queue/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <queue> + +#include <queue> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp new file mode 100644 index 00000000000..bcd9c427430 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// explicit stack(const Alloc& a); + +#include <stack> +#include <cassert> + +#include "../../../../test_allocator.h" + +struct test + : private std::stack<int, std::deque<int, test_allocator<int> > > +{ + typedef std::stack<int, std::deque<int, test_allocator<int> > > base; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const container_type& c, const test_allocator<int>& a) : base(c, a) {} +#ifdef _LIBCPP_MOVE + test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif + test_allocator<int> get_allocator() {return c.get_allocator();} +}; + +int main() +{ + test q(test_allocator<int>(3)); + assert(q.get_allocator() == test_allocator<int>(3)); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp new file mode 100644 index 00000000000..296ae646ef6 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// stack(const container_type& c, const Alloc& a); + +#include <stack> +#include <cassert> + +#include "../../../../test_allocator.h" + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +typedef std::deque<int, test_allocator<int> > C; + +struct test + : public std::stack<int, C> +{ + typedef std::stack<int, C> base; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const container_type& c, const test_allocator<int>& a) : base(c, a) {} +#ifdef _LIBCPP_MOVE + test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif + test_allocator<int> get_allocator() {return c.get_allocator();} +}; + +int main() +{ + C d = make<C>(5); + test q(d, test_allocator<int>(4)); + assert(q.get_allocator() == test_allocator<int>(4)); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.top() == d[d.size() - i - 1]); + q.pop(); + } +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp new file mode 100644 index 00000000000..6bd16ae606a --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// stack(const stack& q, const Alloc& a); + +#include <stack> +#include <cassert> + +#include "../../../../test_allocator.h" + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(int(i)); + return c; +} + +typedef std::deque<int, test_allocator<int> > C; + +template <class T> +struct test + : public std::stack<T, C> +{ + typedef std::stack<T, C> base; + typedef test_allocator<int> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(const test& q, const allocator_type& a) : base(q, a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +int main() +{ + test<int> q(make<C>(5), test_allocator<int>(4)); + test<int> q2(q, test_allocator<int>(5)); + assert(q2.get_allocator() == test_allocator<int>(5)); + assert(q2.size() == 5); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp new file mode 100644 index 00000000000..711b71b8c8f --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// stack(const container_type& c, const Alloc& a); + +#include <stack> +#include <cassert> + +#include "../../../../test_allocator.h" +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque<MoveOnly, test_allocator<MoveOnly> > C; + +template <class T> +struct test + : public std::stack<T, C> +{ + typedef std::stack<T, C> base; + typedef test_allocator<MoveOnly> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + test<MoveOnly> q(make<C>(5), test_allocator<MoveOnly>(4)); + assert(q.get_allocator() == test_allocator<MoveOnly>(4)); + assert(q.size() == 5); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp new file mode 100644 index 00000000000..418bc97dd42 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// stack(stack&& q, const Alloc& a); + +#include <stack> +#include <cassert> + +#include "../../../../test_allocator.h" +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque<MoveOnly, test_allocator<MoveOnly> > C; + +template <class T> +struct test + : public std::stack<T, C> +{ + typedef std::stack<T, C> base; + typedef test_allocator<MoveOnly> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + test<MoveOnly> q(make<C>(5), test_allocator<MoveOnly>(4)); + test<MoveOnly> q2(std::move(q), test_allocator<MoveOnly>(5)); + assert(q2.get_allocator() == test_allocator<MoveOnly>(5)); + assert(q2.size() == 5); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_container.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_container.pass.cpp new file mode 100644 index 00000000000..5fa68ae8d72 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_container.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// explicit stack(const container_type& c); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::deque<int> d = make<std::deque<int> >(5); + std::stack<int> q(d); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.top() == d[d.size() - i - 1]); + q.pop(); + } +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp new file mode 100644 index 00000000000..06f5d502ce4 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack(const stack&) = default; + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::stack<int> q(make<std::deque<int> >(5)); + std::stack<int> q2 = q; + assert(q2 == q); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_default.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_default.pass.cpp new file mode 100644 index 00000000000..de12fb0660b --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_default.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack(); + +#include <stack> +#include <vector> +#include <cassert> + +#include "../../../../stack_allocator.h" + +int main() +{ + std::stack<int, std::vector<int, stack_allocator<int, 10> > > q; + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_move.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_move.pass.cpp new file mode 100644 index 00000000000..55b4c7a9cbf --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_move.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack(stack&& q); + +#include <stack> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::stack<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + std::stack<MoveOnly> q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp new file mode 100644 index 00000000000..43051b512d1 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// explicit stack(container_type&& c); + +#include <stack> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::stack<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + assert(q.size() == 5); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/assign_copy.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/assign_copy.pass.cpp new file mode 100644 index 00000000000..00ad5c087f8 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/assign_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack& operator=(const stack& q); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::stack<int> q(make<std::deque<int> >(5)); + std::stack<int> q2; + q2 = q; + assert(q2 == q); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/assign_move.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/assign_move.pass.cpp new file mode 100644 index 00000000000..6025e7b58df --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/assign_move.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack& operator=(stack&& q); + +#include <stack> +#include <cassert> + +#include "../../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + std::stack<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + std::stack<MoveOnly> q2; + q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/emplace.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/emplace.pass.cpp new file mode 100644 index 00000000000..1a5c107ffba --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/emplace.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class... Args> void emplace(Args&&... args); + +#include <stack> +#include <cassert> + +#include "../../../../Emplaceable.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::stack<Emplaceable> q; + q.emplace(1, 2.5); + q.emplace(2, 3.5); + q.emplace(3, 4.5); + assert(q.size() == 3); + assert(q.top() == Emplaceable(3, 4.5)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/empty.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/empty.pass.cpp new file mode 100644 index 00000000000..1180204218a --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/empty.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// bool empty() const; + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.empty()); + q.push(1); + assert(!q.empty()); + q.pop(); + assert(q.empty()); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/pop.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/pop.pass.cpp new file mode 100644 index 00000000000..cf62cd4c3d2 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/pop.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void pop(); + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + assert(q.size() == 3); + assert(q.top() == 3); + q.pop(); + assert(q.size() == 2); + assert(q.top() == 2); + q.pop(); + assert(q.size() == 1); + assert(q.top() == 1); + q.pop(); + assert(q.size() == 0); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/push.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/push.pass.cpp new file mode 100644 index 00000000000..17fc58da8af --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/push.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void push(const value_type& v); + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + q.push(1); + assert(q.size() == 1); + assert(q.top() == 1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); + q.push(3); + assert(q.size() == 3); + assert(q.top() == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/push_rv.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/push_rv.pass.cpp new file mode 100644 index 00000000000..5e9d554fdab --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/push_rv.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void push(value_type&& v); + +#include <stack> +#include <cassert> + +#include "../../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::stack<MoveOnly> q; + q.push(MoveOnly(1)); + assert(q.size() == 1); + assert(q.top() == MoveOnly(1)); + q.push(MoveOnly(2)); + assert(q.size() == 2); + assert(q.top() == MoveOnly(2)); + q.push(MoveOnly(3)); + assert(q.size() == 3); + assert(q.top() == MoveOnly(3)); +#endif +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/size.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/size.pass.cpp new file mode 100644 index 00000000000..06d84d6d1e1 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/size.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// size_type size() const; + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.size() == 0); + q.push(1); + assert(q.size() == 1); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/swap.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/swap.pass.cpp new file mode 100644 index 00000000000..f3427b6912c --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/swap.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void swap(stack& q); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack<int> q1 = make<std::stack<int> >(5); + std::stack<int> q2 = make<std::stack<int> >(10); + std::stack<int> q1_save = q1; + std::stack<int> q2_save = q2; + q1.swap(q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/top.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/top.pass.cpp new file mode 100644 index 00000000000..4c71dc15ca7 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/top.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// reference top(); + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + int& ir = q.top(); + assert(ir == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/top_const.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/top_const.pass.cpp new file mode 100644 index 00000000000..7afceb0a8d5 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/top_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// const_reference top() const; + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + const std::stack<int>& cqr = q; + const int& cir = cqr.top(); + assert(cir == 3); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/types.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/types.pass.cpp new file mode 100644 index 00000000000..7c128317524 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.defn/types.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class T, class Container = deque<T>> +// class stack +// { +// public: +// typedef Container container_type; +// typedef typename container_type::value_type value_type; +// typedef typename container_type::reference reference; +// typedef typename container_type::const_reference const_reference; +// typedef typename container_type::size_type size_type; +// +// protected: +// container_type c; +// ... +// }; + +#include <stack> +#include <vector> +#include <type_traits> + +struct test + : private std::stack<int> +{ + test() + { + c.push_back(1); + } +}; + +struct C +{ + typedef int value_type; + typedef int& reference; + typedef const int& const_reference; + typedef int size_type; +}; + +int main() +{ + static_assert((std::is_same<std::stack<int>::container_type, std::deque<int> >::value), ""); + static_assert((std::is_same<std::stack<double, std::vector<int> >::container_type, std::vector<int> >::value), ""); + static_assert((std::is_same<std::stack<double, std::vector<int> >::value_type, int>::value), ""); + static_assert((std::is_same<std::stack<int>::reference, std::deque<int>::reference>::value), ""); + static_assert((std::is_same<std::stack<int>::const_reference, std::deque<int>::const_reference>::value), ""); + static_assert((std::is_same<std::stack<int>::size_type, std::deque<int>::size_type>::value), ""); + static_assert((std::uses_allocator<std::stack<int>, std::allocator<int> >::value), ""); + static_assert((!std::uses_allocator<std::stack<int, C>, std::allocator<int> >::value), ""); + test t; +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.ops/eq.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.ops/eq.pass.cpp new file mode 100644 index 00000000000..ceb551010db --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.ops/eq.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class T, class Container> +// bool operator==(const stack<T, Container>& x,const stack<T, Container>& y); +// +// template <class T, class Container> +// bool operator!=(const stack<T, Container>& x,const stack<T, Container>& y); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack<int> q1 = make<std::stack<int> >(5); + std::stack<int> q2 = make<std::stack<int> >(10); + std::stack<int> q1_save = q1; + std::stack<int> q2_save = q2; + assert(q1 == q1_save); + assert(q1 != q2); + assert(q2 == q2_save); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.ops/lt.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.ops/lt.pass.cpp new file mode 100644 index 00000000000..a1dd3d22e34 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.ops/lt.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class T, class Container> +// bool operator< (const stack<T, Container>& x,const stack<T, Container>& y); +// +// template <class T, class Container> +// bool operator> (const stack<T, Container>& x,const stack<T, Container>& y); +// +// template <class T, class Container> +// bool operator>=(const stack<T, Container>& x,const stack<T, Container>& y); +// +// template <class T, class Container> +// bool operator<=(const stack<T, Container>& x,const stack<T, Container>& y); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack<int> q1 = make<std::stack<int> >(5); + std::stack<int> q2 = make<std::stack<int> >(10); + assert(q1 < q2); + assert(q2 > q1); + assert(q1 <= q2); + assert(q2 >= q1); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/stack.special/swap.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/stack.special/swap.pass.cpp new file mode 100644 index 00000000000..f1913cd2b5f --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/stack.special/swap.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class T, class Container> +// void swap(stack<T, Container>& x, stack<T, Container>& y); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack<int> q1 = make<std::stack<int> >(5); + std::stack<int> q2 = make<std::stack<int> >(10); + std::stack<int> q1_save = q1; + std::stack<int> q2_save = q2; + swap(q1, q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/libcxx/test/containers/sequences/container.adaptors/stack/version.pass.cpp b/libcxx/test/containers/sequences/container.adaptors/stack/version.pass.cpp new file mode 100644 index 00000000000..517d112b503 --- /dev/null +++ b/libcxx/test/containers/sequences/container.adaptors/stack/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +#include <stack> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/deque/deque.capacity/access.pass.cpp b/libcxx/test/containers/sequences/deque/deque.capacity/access.pass.cpp new file mode 100644 index 00000000000..a0f140b8458 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.capacity/access.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// reference operator[](size_type __i); +// const_reference operator[](size_type __i) const; +// +// reference at(size_type __i); +// const_reference at(size_type __i) const; +// +// reference front(); +// const_reference front() const; +// +// reference back(); +// const_reference back() const; + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +int main() +{ + { + std::deque<int> c = make(10); + for (unsigned i = 0; i < 10; ++i) + assert(c[i] == i); + for (unsigned i = 0; i < 10; ++i) + assert(c.at(i) == i); + assert(c.front() == 0); + assert(c.back() == 9); + } + { + const std::deque<int> c = make(10); + for (unsigned i = 0; i < 10; ++i) + assert(c[i] == i); + for (unsigned i = 0; i < 10; ++i) + assert(c.at(i) == i); + assert(c.front() == 0); + assert(c.back() == 9); + } +} diff --git a/libcxx/test/containers/sequences/deque/deque.capacity/resize_size.pass.cpp b/libcxx/test/containers/sequences/deque/deque.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..138230afba6 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.capacity/resize_size.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void resize(size_type n); + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<int>& c1, int size) +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + std::size_t c1_osize = c1.size(); + c1.resize(size); + assert(c1.size() == size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + CI i = c1.begin(); + for (int j = 0; j < std::min(c1_osize, c1.size()); ++j, ++i) + assert(*i == j); + for (int j = c1_osize; j < c1.size(); ++j, ++i) + assert(*i == 0); +} + +void +testN(int start, int N, int M) +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + C c1 = make(N, start); + test(c1, M); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN(rng[i], rng[j], rng[k]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp b/libcxx/test/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..a1dcb5042e5 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void resize(size_type n, const value_type& v); + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<int>& c1, int size, int x) +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + std::size_t c1_osize = c1.size(); + c1.resize(size, x); + assert(c1.size() == size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + CI i = c1.begin(); + for (int j = 0; j < std::min(c1_osize, c1.size()); ++j, ++i) + assert(*i == j); + for (int j = c1_osize; j < c1.size(); ++j, ++i) + assert(*i == x); +} + +void +testN(int start, int N, int M) +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + C c1 = make(N, start); + test(c1, M, -10); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN(rng[i], rng[j], rng[k]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp b/libcxx/test/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..11bb34a2235 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void shrink_to_fit(); + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<int>& c1) +{ + std::deque<int> s = c1; + c1.shrink_to_fit(); + assert(c1 == s); +} + +void +testN(int start, int N) +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + C c1 = make(N, start); + test(c1); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/alloc.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/alloc.pass.cpp new file mode 100644 index 00000000000..0a95f8aec32 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/alloc.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// explicit deque(const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "../../../test_allocator.h" +#include "../../../NotConstructible.h" + +template <class T, class Allocator> +void +test(const Allocator& a) +{ + std::deque<T, Allocator> d(a); + assert(d.size() == 0); + assert(d.get_allocator() == a); +} + +int main() +{ + test<int>(std::allocator<int>()); + test<NotConstructible>(test_allocator<NotConstructible>(3)); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..84b8c369701 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void assign(initializer_list<value_type> il); + +#include <deque> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::deque<int> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp new file mode 100644 index 00000000000..a915bfe10dc --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class InputIterator> +// void assign(InputIterator f, InputIterator l); + +#include <deque> +#include <cassert> + +#include "../../../iterators.h" + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<int>& c1, const std::deque<int>& c2) +{ + std::size_t c1_osize = c1.size(); + c1.assign(c2.begin(), c2.end()); + assert(distance(c1.begin(), c1.end()) == c1.size()); + assert(c1 == c2); +} + +void +testN(int start, int N, int M) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + C c1 = make(N, start); + C c2 = make(M); + test(c1, c2); +} + +void +testI(std::deque<int>& c1, const std::deque<int>& c2) +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + typedef input_iterator<CI> ICI; + std::size_t c1_osize = c1.size(); + c1.assign(ICI(c2.begin()), ICI(c2.end())); + assert(distance(c1.begin(), c1.end()) == c1.size()); + assert(c1 == c2); +} + +void +testNI(int start, int N, int M) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + C c1 = make(N, start); + C c2 = make(M); + testI(c1, c2); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN(rng[i], rng[j], rng[k]); + testNI(1500, 2000, 1000); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp new file mode 100644 index 00000000000..963366b830d --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void assign(size_type n, const value_type& v); + +#include <deque> +#include <cassert> + +#include "../../../iterators.h" + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<int>& c1, int size, int v) +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + std::size_t c1_osize = c1.size(); + c1.assign(size, v); + assert(c1.size() == size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + for (CI i = c1.begin(); i != c1.end(); ++i) + assert(*i == v); +} + +void +testN(int start, int N, int M) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + C c1 = make(N, start); + test(c1, M, -10); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN(rng[i], rng[j], rng[k]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/copy.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/copy.pass.cpp new file mode 100644 index 00000000000..00ee3647787 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/copy.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(const deque&); + +#include <deque> +#include <cassert> +#include "../../../test_allocator.h" + +template <class C> +void +test(const C& x) +{ + C c(x); + assert(c == x); +} + +int main() +{ + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque<int>(ab, an)); + } + { + std::deque<int, test_allocator<int> > v(3, 2, test_allocator<int>(5)); + std::deque<int, test_allocator<int> > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::deque<int, other_allocator<int> > v(3, 2, other_allocator<int>(5)); + std::deque<int, other_allocator<int> > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == other_allocator<int>(-2)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..7b2dc60ea1f --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(const deque& c, const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "../../../test_allocator.h" + +template <class C> +void +test(const C& x, const typename C::allocator_type& a) +{ + C c(x, a); + assert(c == x); + assert(c.get_allocator() == a); +} + +int main() +{ + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque<int, test_allocator<int> >(ab, an, test_allocator<int>(3)), + test_allocator<int>(4)); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque<int, other_allocator<int> >(ab, an, other_allocator<int>(3)), + other_allocator<int>(4)); + } +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/default.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/default.pass.cpp new file mode 100644 index 00000000000..cf6074bfbfd --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/default.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque() + +#include <deque> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "../../../NotConstructible.h" + +template <class T, class Allocator> +void +test() +{ + std::deque<T, Allocator> d; + assert(d.size() == 0); +} + +int main() +{ + test<int, std::allocator<int> >(); + test<NotConstructible, stack_allocator<NotConstructible, 1> >(); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/initializer_list.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..4718bf831be --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/initializer_list.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(initializer_list<value_type> il); + +#include <deque> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::deque<int> d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..ec865c50a96 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <deque> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::deque<int, test_allocator<int>> d({3, 4, 5, 6}, test_allocator<int>(3)); + assert(d.get_allocator() == test_allocator<int>(3)); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/iter_iter.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..ef7489d5e64 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/iter_iter.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class InputIterator> deque(InputIterator f, InputIterator l); + +#include <deque> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "../../../iterators.h" + +template <class InputIterator> +void +test(InputIterator f, InputIterator l) +{ + typedef typename std::iterator_traits<InputIterator>::value_type T; + typedef std::allocator<T> Allocator; + typedef std::deque<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + C d(f, l); + assert(d.size() == std::distance(f, l)); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f) + assert(*i == *f); +} + +template <class Allocator, class InputIterator> +void +test(InputIterator f, InputIterator l) +{ + typedef typename std::iterator_traits<InputIterator>::value_type T; + typedef std::deque<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + C d(f, l); + assert(d.size() == std::distance(f, l)); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f) + assert(*i == *f); +} + +int main() +{ + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(input_iterator<const int*>(ab), input_iterator<const int*>(an)); + test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an)); + test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an)); + test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an)); + test<stack_allocator<int, 4096> >(ab, an); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..c05e00da071 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class InputIterator> +// deque(InputIterator f, InputIterator l, const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "../../../iterators.h" +#include "../../../test_allocator.h" + +template <class InputIterator, class Allocator> +void +test(InputIterator f, InputIterator l, const Allocator& a) +{ + typedef typename std::iterator_traits<InputIterator>::value_type T; + typedef std::deque<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + C d(f, l, a); + assert(d.get_allocator() == a); + assert(d.size() == std::distance(f, l)); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f) + assert(*i == *f); +} + +int main() +{ + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(input_iterator<const int*>(ab), input_iterator<const int*>(an), test_allocator<int>(3)); + test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), test_allocator<int>(4)); + test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), test_allocator<int>(5)); + test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), test_allocator<int>(6)); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/move.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/move.pass.cpp new file mode 100644 index 00000000000..9d00b0c10bd --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/move.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(deque&&); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A(2)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == c1.get_allocator()); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef other_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A(2)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == c1.get_allocator()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/move_alloc.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..aedaf349138 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/move_alloc.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(deque&& c, const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A(1)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3(std::move(c1), A(3)); + assert(c2 == c3); + assert(c3.get_allocator() == A(3)); + assert(c1.size() != 0); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A(1)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3(std::move(c1), A(1)); + assert(c2 == c3); + assert(c3.get_allocator() == A(1)); + assert(c1.size() == 0); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef other_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A(1)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3(std::move(c1), A(3)); + assert(c2 == c3); + assert(c3.get_allocator() == A(3)); + assert(c1.size() != 0); + } +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/move_assign.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..e368cc5f27e --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/move_assign.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque& operator=(deque&& c); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A(5)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A(5)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3(A(5)); + c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == A(5)); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A(5)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A(5)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3(A(6)); + c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() != 0); + assert(c3.get_allocator() == A(6)); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef other_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A(5)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A(5)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3(A(6)); + c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == A(5)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/op_equal.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/op_equal.pass.cpp new file mode 100644 index 00000000000..48f4f76ae76 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/op_equal.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque& operator=(const deque& c); + +#include <deque> +#include <cassert> +#include "../../../test_allocator.h" + +template <class C> +void +test(const C& x) +{ + C c; + c = x; + assert(c == x); +} + +int main() +{ + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque<int>(ab, an)); + } + { + std::deque<int, test_allocator<int> > l(3, 2, test_allocator<int>(5)); + std::deque<int, test_allocator<int> > l2(l, test_allocator<int>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<int>(3)); + } + { + std::deque<int, other_allocator<int> > l(3, 2, other_allocator<int>(5)); + std::deque<int, other_allocator<int> > l2(l, other_allocator<int>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<int>(5)); + } +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..dd37698b01d --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque& operator=(initializer_list<value_type> il); + +#include <deque> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::deque<int> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/size.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/size.pass.cpp new file mode 100644 index 00000000000..6d38ab6238b --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/size.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// explicit deque(size_type n); + +#include <deque> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "../../../DefaultOnly.h" + +template <class T, class Allocator> +void +test(unsigned n) +{ + typedef std::deque<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + assert(DefaultOnly::count == 0); + { + C d(n); + assert(DefaultOnly::count == n); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); +#ifdef _LIBCPP_MOVE + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == T()); +#endif + } + assert(DefaultOnly::count == 0); +} + +int main() +{ + test<DefaultOnly, std::allocator<DefaultOnly> >(0); + test<DefaultOnly, std::allocator<DefaultOnly> >(1); + test<DefaultOnly, std::allocator<DefaultOnly> >(10); + test<DefaultOnly, std::allocator<DefaultOnly> >(1023); + test<DefaultOnly, std::allocator<DefaultOnly> >(1024); + test<DefaultOnly, std::allocator<DefaultOnly> >(1025); + test<DefaultOnly, std::allocator<DefaultOnly> >(2047); + test<DefaultOnly, std::allocator<DefaultOnly> >(2048); + test<DefaultOnly, std::allocator<DefaultOnly> >(2049); + test<DefaultOnly, std::allocator<DefaultOnly> >(4095); + test<DefaultOnly, std::allocator<DefaultOnly> >(4096); + test<DefaultOnly, std::allocator<DefaultOnly> >(4097); + test<DefaultOnly, stack_allocator<DefaultOnly, 4096> >(4095); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/size_value.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/size_value.pass.cpp new file mode 100644 index 00000000000..a8f9f47e49d --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/size_value.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(size_type n, const value_type& v); + +#include <deque> +#include <cassert> + +#include "../../../stack_allocator.h" + +template <class T, class Allocator> +void +test(unsigned n, const T& x) +{ + typedef std::deque<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + C d(n, x); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test<int, std::allocator<int> >(0, 5); + test<int, std::allocator<int> >(1, 10); + test<int, std::allocator<int> >(10, 11); + test<int, std::allocator<int> >(1023, -11); + test<int, std::allocator<int> >(1024, 25); + test<int, std::allocator<int> >(1025, 0); + test<int, std::allocator<int> >(2047, 110); + test<int, std::allocator<int> >(2048, -500); + test<int, std::allocator<int> >(2049, 654); + test<int, std::allocator<int> >(4095, 78); + test<int, std::allocator<int> >(4096, 1165); + test<int, std::allocator<int> >(4097, 157); + test<int, stack_allocator<int, 4096> >(4095, 90); +} diff --git a/libcxx/test/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp b/libcxx/test/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..dfcea0b8b75 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(size_type n, const value_type& v, const allocator_type& a); + +#include <deque> +#include <cassert> + +template <class T, class Allocator> +void +test(unsigned n, const T& x, const Allocator& a) +{ + typedef std::deque<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + C d(n, x, a); + assert(d.get_allocator() == a); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + std::allocator<int> a; + test(0, 5, a); + test(1, 10, a); + test(10, 11, a); + test(1023, -11, a); + test(1024, 25, a); + test(1025, 0, a); + test(2047, 110, a); + test(2048, -500, a); + test(2049, 654, a); + test(4095, 78, a); + test(4096, 1165, a); + test(4097, 157, a); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/emplace.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..1929a0634d3 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/emplace.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class... Args> iterator emplace(const_iterator p, Args&&... args); + +#include <deque> +#include <cassert> + +#include "../../../Emplaceable.h" + +#ifdef _LIBCPP_MOVE + +std::deque<Emplaceable> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<Emplaceable> c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(Emplaceable()); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(int P, std::deque<Emplaceable>& c1) +{ + typedef std::deque<Emplaceable> C; + typedef C::iterator I; + typedef C::const_iterator CI; + std::size_t c1_osize = c1.size(); + CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5)); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + assert(*i == Emplaceable(1, 2.5)); +} + +void +testN(int start, int N) +{ + typedef std::deque<Emplaceable> C; + typedef C::iterator I; + typedef C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1); + } + } +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..26a1fb88294 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class... Args> void emplace_back(Args&&... args); + +#include <deque> +#include <cassert> + +#include "../../../Emplaceable.h" + +#ifdef _LIBCPP_MOVE + +std::deque<Emplaceable> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<Emplaceable> c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(Emplaceable()); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<Emplaceable>& c1) +{ + typedef std::deque<Emplaceable> C; + typedef C::iterator I; + std::size_t c1_osize = c1.size(); + c1.emplace_back(Emplaceable(1, 2.5)); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.end(); + assert(*--i == Emplaceable(1, 2.5)); +} + +void +testN(int start, int N) +{ + typedef std::deque<Emplaceable> C; + C c1 = make(N, start); + test(c1); +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..49ac15c4783 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class... Args> void emplace_front(Args&&... args); + +#include <deque> +#include <cassert> + +#include "../../../Emplaceable.h" + +#ifdef _LIBCPP_MOVE + +std::deque<Emplaceable> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<Emplaceable> c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(Emplaceable()); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<Emplaceable>& c1) +{ + typedef std::deque<Emplaceable> C; + typedef C::iterator I; + std::size_t c1_osize = c1.size(); + c1.emplace_front(Emplaceable(1, 2.5)); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + assert(*i == Emplaceable(1, 2.5)); +} + +void +testN(int start, int N) +{ + typedef std::deque<Emplaceable> C; + C c1 = make(N, start); + test(c1); +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..35afea306bb --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator erase(const_iterator p) + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(int P, std::deque<int>& c1) +{ + typedef std::deque<int> C; + typedef C::iterator I; + assert(P < c1.size()); + std::size_t c1_osize = c1.size(); + I i = c1.erase(c1.cbegin() + P); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize - 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + int j = 0; + for (; j < P; ++j, ++i) + assert(*i == j); + for (++j; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +void +testN(int start, int N) +{ + typedef std::deque<int> C; + int pstep = std::max(N / std::max(std::min(N, 10), 1), 1); + for (int p = 0; p < N; p += pstep) + { + C c1 = make(N, start); + test(p, c1); + } +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..e082a058017 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator erase(const_iterator f, const_iterator l) + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(int P, std::deque<int>& c1, int size) +{ + typedef std::deque<int> C; + typedef C::iterator I; + assert(P + size <= c1.size()); + std::size_t c1_osize = c1.size(); + I i = c1.erase(c1.cbegin() + P, c1.cbegin() + (P + size)); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize - size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + int j = 0; + for (; j < P; ++j, ++i) + assert(*i == j); + for (j += size; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +void +testN(int start, int N) +{ + typedef std::deque<int> C; + int pstep = std::max(N / std::max(std::min(N, 10), 1), 1); + for (int p = 0; p <= N; p += pstep) + { + int sstep = std::max((N - p) / std::max(std::min(N - p, 10), 1), 1); + for (int s = 0; s <= N - p; s += sstep) + { + C c1 = make(N, start); + test(p, c1, s); + } + } +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..4a5fceaaab2 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <deque> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::deque<int> d(10, 1); + std::deque<int>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(i == d.begin() + 2); + assert(d[0] == 1); + assert(d[1] == 1); + assert(d[2] == 3); + assert(d[3] == 4); + assert(d[4] == 5); + assert(d[5] == 6); + assert(d[6] == 1); + assert(d[7] == 1); + assert(d[8] == 1); + assert(d[9] == 1); + assert(d[10] == 1); + assert(d[11] == 1); + assert(d[12] == 1); + assert(d[13] == 1); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..15f9c0fc087 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,236 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class InputIterator> +// iterator insert (const_iterator p, InputIterator f, InputIterator l); + +#include <deque> +#include <cassert> + +#include "../../../iterators.h" +#include "../../../MoveOnly.h" +#include "../../../stack_allocator.h" + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(int P, std::deque<int>& c1, const std::deque<int>& c2) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + typedef bidirectional_iterator<CI> BCI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, BCI(c2.begin()), BCI(c2.end())); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + c2.size()); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == j); + for (int j = 0; j < c2.size(); ++j, ++i) + assert(*i == j); + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +void +testN(int start, int N, int M) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } +} + +void +testI(int P, std::deque<int>& c1, const std::deque<int>& c2) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + typedef input_iterator<CI> ICI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, ICI(c2.begin()), ICI(c2.end())); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + c2.size()); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == j); + for (int j = 0; j < c2.size(); ++j, ++i) + assert(*i == j); + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +void +testNI(int start, int N, int M) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } +} + +void +test_move() +{ +#ifdef _LIBCPP_MOVE + std::deque<MoveOnly, stack_allocator<MoveOnly, 2000> > c; + typedef std::deque<MoveOnly>::const_iterator CI; + { + MoveOnly mo(0); + typedef MoveOnly* I; + c.insert(c.end(), std::move_iterator<I>(&mo), std::move_iterator<I>(&mo+1)); + } + int j = 0; + for (CI i = c.begin(); i != c.end(); ++i, ++j) + assert(*i == MoveOnly(j)); + { + MoveOnly mo(1); + typedef input_iterator<MoveOnly*> I; + c.insert(c.end(), std::move_iterator<I>(I(&mo)), std::move_iterator<I>(I(&mo+1))); + } + j = 0; + for (CI i = c.begin(); i != c.end(); ++i, ++j) + assert(*i == MoveOnly(j)); +#endif +} + + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN(rng[i], rng[j], rng[k]); + testNI(1500, 2000, 1000); + test_move(); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp new file mode 100644 index 00000000000..b7743f949d2 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator insert (const_iterator p, value_type&& v); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +std::deque<MoveOnly> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<MoveOnly> c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(MoveOnly(i)); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(int P, std::deque<MoveOnly>& c1, int x) +{ + typedef std::deque<MoveOnly> C; + typedef C::iterator I; + typedef C::const_iterator CI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, MoveOnly(x)); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == MoveOnly(j)); + assert(*i == MoveOnly(x)); + ++i; + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == MoveOnly(j)); +} + +void +testN(int start, int N) +{ + typedef std::deque<MoveOnly> C; + typedef C::iterator I; + typedef C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp new file mode 100644 index 00000000000..c94d830b672 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator insert (const_iterator p, size_type n, const value_type& v); + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(int P, std::deque<int>& c1, int size, int x) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, size, x); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == j); + for (int j = 0; j < size; ++j, ++i) + assert(*i == x); + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +void +testN(int start, int N, int M) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } +} + +void +self_reference_test() +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + for (int i = 0; i < 20; ++i) + { + for (int j = 0; j < 20; ++j) + { + C c = make(20); + CI it = c.cbegin() + i; + CI jt = c.cbegin() + j; + c.insert(it, 5, *jt); + assert(c.size() == 25); + assert(distance(c.begin(), c.end()) == c.size()); + it = c.cbegin(); + for (int k = 0; k < i; ++k, ++it) + assert(*it == k); + for (int k = 0; k < 5; ++k, ++it) + assert(*it == j); + for (int k = i; k < 20; ++k, ++it) + assert(*it == k); + } + } +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN(rng[i], rng[j], rng[k]); + self_reference_test(); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp new file mode 100644 index 00000000000..71836d4c460 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator insert (const_iterator p, const value_type& v); + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(int P, std::deque<int>& c1, int x) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, x); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == j); + assert(*i == x); + ++i; + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +void +testN(int start, int N) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } +} + +void +self_reference_test() +{ + typedef std::deque<int> C; + typedef C::const_iterator CI; + for (int i = 0; i < 20; ++i) + { + for (int j = 0; j < 20; ++j) + { + C c = make(20); + CI it = c.cbegin() + i; + CI jt = c.cbegin() + j; + c.insert(it, *jt); + assert(c.size() == 21); + assert(distance(c.begin(), c.end()) == c.size()); + it = c.cbegin(); + for (int k = 0; k < i; ++k, ++it) + assert(*it == k); + assert(*it == j); + ++it; + for (int k = i; k < 20; ++k, ++it) + assert(*it == k); + } + } +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); + self_reference_test(); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..0af20b425e5 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void pop_back() + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<int>& c1) +{ + typedef std::deque<int> C; + typedef C::iterator I; + std::size_t c1_osize = c1.size(); + c1.pop_back(); + assert(c1.size() == c1_osize - 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + for (int j = 0; j < c1.size(); ++j, ++i) + assert(*i == j); +} + +void +testN(int start, int N) +{ + if (N != 0) + { + typedef std::deque<int> C; + C c1 = make(N, start); + test(c1); + } +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..f8ea30217d5 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void pop_front() + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<int>& c1) +{ + typedef std::deque<int> C; + typedef C::iterator I; + std::size_t c1_osize = c1.size(); + c1.pop_front(); + assert(c1.size() == c1_osize - 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + for (int j = 1; j < c1.size(); ++j, ++i) + assert(*i == j); +} + +void +testN(int start, int N) +{ + if (N != 0) + { + typedef std::deque<int> C; + C c1 = make(N, start); + test(c1); + } +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/push_back.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..344a813bbc0 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/push_back.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_back(const value_type& v); +// void pop_back(); +// void pop_front(); + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void test(int size) +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + { + std::deque<int> c = make(size, rng[j]); + std::deque<int>::const_iterator it = c.begin(); + for (int i = 0; i < size; ++i, ++it) + assert(*it == i); + } +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + test(rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..bbbfc18b916 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_back(value_type&& v); +// void pop_back(); +// void pop_front(); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +std::deque<MoveOnly> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<MoveOnly> c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(MoveOnly(i)); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void test(int size) +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + { + std::deque<MoveOnly> c = make(size, rng[j]); + std::deque<MoveOnly>::const_iterator it = c.begin(); + for (int i = 0; i < size; ++i, ++it) + assert(*it == MoveOnly(i)); + } +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + test(rng[j]); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/push_front.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/push_front.pass.cpp new file mode 100644 index 00000000000..fe2b4e4dddb --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/push_front.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_front(const value_type& v); + +#include <deque> +#include <cassert> + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<int>& c1, int x) +{ + typedef std::deque<int> C; + typedef C::iterator I; + std::size_t c1_osize = c1.size(); + c1.push_front(x); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + assert(*i == x); + ++i; + for (int j = 0; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +void +testN(int start, int N) +{ + typedef std::deque<int> C; + C c1 = make(N, start); + test(c1, -10); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp b/libcxx/test/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp new file mode 100644 index 00000000000..10804aabd80 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_front(value_type&& v); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" + +#ifdef _LIBCPP_MOVE + +std::deque<MoveOnly> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<MoveOnly> c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(MoveOnly(i)); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void +test(std::deque<MoveOnly>& c1, int x) +{ + typedef std::deque<MoveOnly> C; + typedef C::iterator I; + std::size_t c1_osize = c1.size(); + c1.push_front(MoveOnly(x)); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + assert(*i == MoveOnly(x)); + ++i; + for (int j = 0; j < c1_osize; ++j, ++i) + assert(*i == MoveOnly(j)); +} + +void +testN(int start, int N) +{ + typedef std::deque<MoveOnly> C; + C c1 = make(N, start); + test(c1, -10); +} + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +#endif +} diff --git a/libcxx/test/containers/sequences/deque/deque.special/copy.pass.cpp b/libcxx/test/containers/sequences/deque/deque.special/copy.pass.cpp new file mode 100644 index 00000000000..80200ed0d1b --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.special/copy.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Optimization for deque::iterators + +// template <class InputIterator, class OutputIterator> +// OutputIterator +// copy(InputIterator first, InputIterator last, OutputIterator result); + +#include <deque> +#include <cassert> + +#include "../../../iterators.h" + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void testN(int start, int N) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + typedef random_access_iterator<I> RAI; + typedef random_access_iterator<CI> RACI; + typedef input_iterator<CI> ICI; + C c1 = make(N, start); + C c2 = make(N); + assert(std::copy(c1.cbegin(), c1.cend(), c2.begin()) == c2.end()); + assert(c1 == c2); + assert(std::copy(c2.cbegin(), c2.cend(), c1.begin()) == c1.end()); + assert(c1 == c2); + assert(std::copy(c1.cbegin(), c1.cend(), RAI(c2.begin())) == RAI(c2.end())); + assert(c1 == c2); + assert(std::copy(c2.cbegin(), c2.cend(), RAI(c1.begin())) == RAI(c1.end())); + assert(c1 == c2); + assert(std::copy(RACI(c1.cbegin()), RACI(c1.cend()), c2.begin()) == c2.end()); + assert(c1 == c2); + assert(std::copy(ICI(c2.cbegin()), ICI(c2.cend()), c1.begin()) == c1.end()); + assert(c1 == c2); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.special/copy_backward.pass.cpp b/libcxx/test/containers/sequences/deque/deque.special/copy_backward.pass.cpp new file mode 100644 index 00000000000..aae5e1ae00a --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.special/copy_backward.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Optimization for deque::iterators + +// template <class InputIterator, class OutputIterator> +// OutputIterator +// copy_backward(InputIterator first, InputIterator last, OutputIterator result); + +#include <deque> +#include <cassert> + +#include "../../../iterators.h" + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void testN(int start, int N) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + typedef random_access_iterator<I> RAI; + typedef random_access_iterator<CI> RACI; + C c1 = make(N, start); + C c2 = make(N); + assert(std::copy_backward(c1.cbegin(), c1.cend(), c2.end()) == c2.begin()); + assert(c1 == c2); + assert(std::copy_backward(c2.cbegin(), c2.cend(), c1.end()) == c1.begin()); + assert(c1 == c2); + assert(std::copy_backward(c1.cbegin(), c1.cend(), RAI(c2.end())) == RAI(c2.begin())); + assert(c1 == c2); + assert(std::copy_backward(c2.cbegin(), c2.cend(), RAI(c1.end())) == RAI(c1.begin())); + assert(c1 == c2); + assert(std::copy_backward(RACI(c1.cbegin()), RACI(c1.cend()), c2.end()) == c2.begin()); + assert(c1 == c2); + assert(std::copy_backward(RACI(c2.cbegin()), RACI(c2.cend()), c1.end()) == c1.begin()); + assert(c1 == c2); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.special/move.pass.cpp b/libcxx/test/containers/sequences/deque/deque.special/move.pass.cpp new file mode 100644 index 00000000000..4fb2bd351c5 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.special/move.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Optimization for deque::iterators + +// template <class InputIterator, class OutputIterator> +// OutputIterator +// move(InputIterator first, InputIterator last, OutputIterator result); + +#include <deque> +#include <cassert> + +#include "../../../iterators.h" + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void testN(int start, int N) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + typedef random_access_iterator<I> RAI; + typedef random_access_iterator<CI> RACI; + C c1 = make(N, start); + C c2 = make(N); + assert(std::move(c1.cbegin(), c1.cend(), c2.begin()) == c2.end()); + assert(c1 == c2); + assert(std::move(c2.cbegin(), c2.cend(), c1.begin()) == c1.end()); + assert(c1 == c2); + assert(std::move(c1.cbegin(), c1.cend(), RAI(c2.begin())) == RAI(c2.end())); + assert(c1 == c2); + assert(std::move(c2.cbegin(), c2.cend(), RAI(c1.begin())) == RAI(c1.end())); + assert(c1 == c2); + assert(std::move(RACI(c1.cbegin()), RACI(c1.cend()), c2.begin()) == c2.end()); + assert(c1 == c2); + assert(std::move(RACI(c2.cbegin()), RACI(c2.cend()), c1.begin()) == c1.end()); + assert(c1 == c2); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.special/move_backward.pass.cpp b/libcxx/test/containers/sequences/deque/deque.special/move_backward.pass.cpp new file mode 100644 index 00000000000..9e5f435c2d8 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.special/move_backward.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Optimization for deque::iterators + +// template <class InputIterator, class OutputIterator> +// OutputIterator +// move_backward(InputIterator first, InputIterator last, OutputIterator result); + +#include <deque> +#include <cassert> + +#include "../../../iterators.h" + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void testN(int start, int N) +{ + typedef std::deque<int> C; + typedef C::iterator I; + typedef C::const_iterator CI; + typedef random_access_iterator<I> RAI; + typedef random_access_iterator<CI> RACI; + C c1 = make(N, start); + C c2 = make(N); + assert(std::move_backward(c1.cbegin(), c1.cend(), c2.end()) == c2.begin()); + assert(c1 == c2); + assert(std::move_backward(c2.cbegin(), c2.cend(), c1.end()) == c1.begin()); + assert(c1 == c2); + assert(std::move_backward(c1.cbegin(), c1.cend(), RAI(c2.end())) == RAI(c2.begin())); + assert(c1 == c2); + assert(std::move_backward(c2.cbegin(), c2.cend(), RAI(c1.end())) == RAI(c1.begin())); + assert(c1 == c2); + assert(std::move_backward(RACI(c1.cbegin()), RACI(c1.cend()), c2.end()) == c2.begin()); + assert(c1 == c2); + assert(std::move_backward(RACI(c2.cbegin()), RACI(c2.cend()), c1.end()) == c1.begin()); + assert(c1 == c2); +} + +int main() +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN(rng[i], rng[j]); +} diff --git a/libcxx/test/containers/sequences/deque/deque.special/swap.pass.cpp b/libcxx/test/containers/sequences/deque/deque.special/swap.pass.cpp new file mode 100644 index 00000000000..a3d416c3412 --- /dev/null +++ b/libcxx/test/containers/sequences/deque/deque.special/swap.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class T, class A> +// void swap(deque<T, A>& x, deque<T, A>& y); + +#include <deque> +#include <cassert> +#include "../../../test_allocator.h" + +std::deque<int> +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + std::deque<int> c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +void testN(int start, int N, int M) +{ + typedef std::deque<int> C; + C c1 = make(N, start); + C c2 = make(M); + C c1_save = c1; + C c2_save = c2; + swap(c1, c2); + assert(c1 == c2_save); + assert(c2 == c1_save); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN(rng[i], rng[j], rng[k]); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef test_allocator<int> A; + std::deque<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::deque<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::deque<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(1)); + assert((c2 == std::deque<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef other_allocator<int> A; + std::deque<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::deque<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::deque<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(2)); + assert((c2 == std::deque<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(1)); + } +} diff --git a/libcxx/test/containers/sequences/deque/types.pass.cpp b/libcxx/test/containers/sequences/deque/types.pass.cpp new file mode 100644 index 00000000000..9e2e1bd398b --- /dev/null +++ b/libcxx/test/containers/sequences/deque/types.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Test nested types and default template args: + +// template <class T, class Allocator = allocator<T> > +// class deque +// { +// public: +// typedef T value_type; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef implementation-defined iterator; +// typedef implementation-defined const_iterator; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef std::reverse_iterator<iterator> reverse_iterator; +// typedef std::reverse_iterator<const_iterator> const_reverse_iterator; +// }; + +#include <deque> +#include <iterator> +#include <type_traits> + +#include "../../test_allocator.h" +#include "../../Copyable.h" + +template <class T, class Allocator> +void +test() +{ + typedef std::deque<T, Allocator> C; + + static_assert((std::is_same<typename C::value_type, T>::value), ""); + static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), ""); + static_assert((std::is_same<typename C::allocator_type, Allocator>::value), ""); + static_assert((std::is_same<typename C::size_type, typename Allocator::size_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), ""); + static_assert((std::is_same<typename C::reference, typename Allocator::reference>::value), ""); + static_assert((std::is_same<typename C::const_reference, typename Allocator::const_reference>::value), ""); + static_assert((std::is_same<typename C::pointer, typename Allocator::pointer>::value), ""); + static_assert((std::is_same<typename C::const_pointer, typename Allocator::const_pointer>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename C::iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename C::const_iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename C::reverse_iterator, + std::reverse_iterator<typename C::iterator> >::value), ""); + static_assert((std::is_same< + typename C::const_reverse_iterator, + std::reverse_iterator<typename C::const_iterator> >::value), ""); +} + +int main() +{ + test<int, test_allocator<int> >(); + test<int*, std::allocator<int*> >(); + test<Copyable, test_allocator<Copyable> >(); + static_assert((std::is_same<std::deque<char>::allocator_type, + std::allocator<char> >::value), ""); +} diff --git a/libcxx/test/containers/sequences/deque/version.pass.cpp b/libcxx/test/containers/sequences/deque/version.pass.cpp new file mode 100644 index 00000000000..6e73ad3944e --- /dev/null +++ b/libcxx/test/containers/sequences/deque/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +#include <deque> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp new file mode 100644 index 00000000000..0bd0ce1c773 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// reference front(); +// const_reference front() const; + +#include <forward_list> +#include <cassert> +#include <iterator> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + assert(c.front() == 0); + c.front() = 10; + assert(c.front() == 10); + assert(*c.begin() == 10); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const C c(std::begin(t), std::end(t)); + assert(c.front() == 0); + assert(*c.begin() == 0); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp new file mode 100644 index 00000000000..333a5b20d26 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// explicit forward_list(const allocator_type& a); + +#include <forward_list> +#include <cassert> + +#include "../../../test_allocator.h" +#include "../../../NotConstructible.h" + +int main() +{ + { + typedef test_allocator<NotConstructible> A; + typedef A::value_type T; + typedef std::forward_list<T, A> C; + C c = A(12); + assert(c.get_allocator() == A(12)); + assert(c.empty()); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp new file mode 100644 index 00000000000..f9309cfc367 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// explicit forward_list(const allocator_type& a); + +#include <forward_list> +#include <cassert> + +#include "../../../test_allocator.h" +#include "../../../NotConstructible.h" + +int main() +{ + { + typedef test_allocator<NotConstructible> A; + typedef A::value_type T; + typedef std::forward_list<T, A> C; + C c(A(12)); + assert(c.get_allocator() == A(12)); + assert(c.empty()); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..c20673bbcff --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp @@ -0,0 +1,119 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list& operator=(const forward_list& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../test_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(10)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(11)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(11)); + } + { + typedef int T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(10)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(11)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(11)); + } + + { + typedef int T; + typedef other_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(10)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef other_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(11)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef other_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(10)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef other_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(11)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp new file mode 100644 index 00000000000..ac970e17d1b --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void assign(initializer_list<value_type> il); + +#include <forward_list> +#include <cassert> +#include <iterator> + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c.assign({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c.assign({10, 11, 12, 13}); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..fd0b76169c4 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp @@ -0,0 +1,162 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list& operator=(forward_list&& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../test_allocator.h" +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(10)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(11)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A(11)); + assert(!c0.empty()); + } + { + typedef MoveOnly T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(10)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(11)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A(11)); + assert(!c0.empty()); + } + + { + typedef MoveOnly T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(10)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(11)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(10)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(11)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp new file mode 100644 index 00000000000..26281ba04d1 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list& operator=(initializer_list<value_type> il); + +#include <forward_list> +#include <cassert> +#include <iterator> + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c = {10, 11, 12, 13}; + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp new file mode 100644 index 00000000000..9c535fff9a0 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class InputIterator> +// void assign(InputIterator first, InputIterator last); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../iterators.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + typedef input_iterator<const T*> I; + c.assign(I(std::begin(t0)), I(std::end(t0))); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + typedef input_iterator<const T*> I; + c.assign(I(std::begin(t0)), I(std::end(t0))); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp new file mode 100644 index 00000000000..aae35abf2c2 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void assign(size_type n, const value_type& v); + +#include <forward_list> +#include <cassert> +#include <iterator> + + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c.assign(10, 1); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 1); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c.assign(4, 10); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10); + assert(n == 4); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp new file mode 100644 index 00000000000..fa4ee752761 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(const forward_list& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../test_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A(10)); + C c = c0; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A(10)); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef int T; + typedef other_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A(10)); + C c = c0; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A(-2)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..6d62410c0c3 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(const forward_list& x, const allocator_type& a); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../test_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A(10)); + C c(c0, A(9)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A(9)); + } + { + typedef int T; + typedef other_allocator<int> A; + typedef std::forward_list<T, A> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A(10)); + C c(c0, A(9)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A(9)); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp new file mode 100644 index 00000000000..55cdbe1570e --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(); + +#include <forward_list> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + C c; + assert(c.empty()); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp new file mode 100644 index 00000000000..696eba18956 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(initializer_list<value_type> il); + +#include <forward_list> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef int T; + typedef std::forward_list<T> C; + C c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == 10); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp new file mode 100644 index 00000000000..0baba2d65d4 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(initializer_list<value_type> il, const allocator_type& a); + +#include <forward_list> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + C c({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, A(14)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c.get_allocator() == A(14)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp new file mode 100644 index 00000000000..22c47be6beb --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(forward_list&& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../test_allocator.h" +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t)), I(std::end(t)), A(10)); + C c = std::move(c0); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c0.empty()); + assert(c.get_allocator() == A(10)); + } + { + typedef MoveOnly T; + typedef other_allocator<int> A; + typedef std::forward_list<T, A> C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t)), I(std::end(t)), A(10)); + C c = std::move(c0); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c0.empty()); + assert(c.get_allocator() == A(10)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..16b8f9f7bed --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(forward_list&& x, const allocator_type& a); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../test_allocator.h" +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t)), I(std::end(t)), A(10)); + C c(std::move(c0), A(10)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c0.empty()); + assert(c.get_allocator() == A(10)); + } + { + typedef MoveOnly T; + typedef test_allocator<int> A; + typedef std::forward_list<T, A> C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator<T*> I; + C c0(I(std::begin(t)), I(std::end(t)), A(10)); + C c(std::move(c0), A(9)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(!c0.empty()); + assert(c.get_allocator() == A(9)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp new file mode 100644 index 00000000000..23082f5f5cf --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class InputIterator> +// forward_list(InputIterator first, InputIterator last); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../iterators.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + typedef input_iterator<const T*> I; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(I(std::begin(t)), I(std::end(t))); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp new file mode 100644 index 00000000000..42e71835d7c --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class InputIterator> +// forward_list(InputIterator first, InputIterator last, +// const allocator_type& a); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "../../../test_allocator.h" +#include "../../../iterators.h" + +int main() +{ + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + typedef input_iterator<const T*> I; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(I(std::begin(t)), I(std::end(t)), A(13)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c.get_allocator() == A(13)); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp new file mode 100644 index 00000000000..2c3a4c9f487 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// explicit forward_list(size_type n); + +#include <forward_list> +#include <cassert> + +#include "../../../DefaultOnly.h" + +int main() +{ + { + typedef DefaultOnly T; + typedef std::forward_list<T> C; + unsigned N = 10; + C c = N; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) +#ifdef _LIBCPP_MOVE + assert(*i == T()); +#else + ; +#endif + assert(n == N); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp new file mode 100644 index 00000000000..6990acea53b --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// explicit forward_list(size_type n); + +#include <forward_list> +#include <cassert> + +#include "../../../DefaultOnly.h" + +int main() +{ + { + typedef DefaultOnly T; + typedef std::forward_list<T> C; + unsigned N = 10; + C c(N); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) +#ifdef _LIBCPP_MOVE + assert(*i == T()); +#else + ; +#endif + assert(n == N); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp new file mode 100644 index 00000000000..ec1235a908e --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(size_type n, const value_type& v); + +#include <forward_list> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + T v(6); + unsigned N = 10; + C c(N, v); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == v); + assert(n == N); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..486b63c40a9 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(size_type n, const value_type& v, const allocator_type& a); + +#include <forward_list> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ + { + typedef test_allocator<int> A; + typedef A::value_type T; + typedef std::forward_list<T, A> C; + T v(6); + unsigned N = 10; + C c(N, v, A(12)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == v); + assert(n == N); + assert(c.get_allocator() == A(12)); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp new file mode 100644 index 00000000000..5c447a7f4fd --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator before_begin(); +// const_iterator before_begin() const; +// const_iterator cbefore_begin() const; + +#include <forward_list> +#include <cassert> +#include <iterator> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + C c; + C::iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 1); + } + { + typedef int T; + typedef std::forward_list<T> C; + const C c; + C::const_iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 1); + } + { + typedef int T; + typedef std::forward_list<T> C; + const C c; + C::const_iterator i = c.cbefore_begin(); + assert(std::distance(i, c.end()) == 1); + assert(c.cbefore_begin() == c.before_begin()); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 11); + assert(std::next(c.before_begin()) == c.begin()); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const C c(std::begin(t), std::end(t)); + C::const_iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 11); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp new file mode 100644 index 00000000000..86a0d6baf17 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include <forward_list> +#include <cassert> +#include <iterator> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::forward_list<T> C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::forward_list<T> C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::forward_list<T> C; + C::iterator i; + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..e10aa20a95c --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void clear(); + +#include <forward_list> +#include <cassert> + +#include "../../../NotConstructible.h" + +int main() +{ + { + typedef NotConstructible T; + typedef std::forward_list<T> C; + C c; + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp new file mode 100644 index 00000000000..35a45e0f748 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class... Args> +// iterator emplace_after(const_iterator p, Args&&... args); + +#include <forward_list> +#include <cassert> + +#include "../../../Emplaceable.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef Emplaceable T; + typedef std::forward_list<T> C; + typedef C::iterator I; + C c; + I i = c.emplace_after(c.cbefore_begin()); + assert(i == c.begin()); + assert(c.front() == Emplaceable()); + assert(distance(c.begin(), c.end()) == 1); + + i = c.emplace_after(c.cbegin(), 1, 2.5); + assert(i == next(c.begin())); + assert(c.front() == Emplaceable()); + assert(*next(c.begin()) == Emplaceable(1, 2.5)); + assert(distance(c.begin(), c.end()) == 2); + + i = c.emplace_after(next(c.cbegin()), 2, 3.5); + assert(i == next(c.begin(), 2)); + assert(c.front() == Emplaceable()); + assert(*next(c.begin()) == Emplaceable(1, 2.5)); + assert(*next(c.begin(), 2) == Emplaceable(2, 3.5)); + assert(distance(c.begin(), c.end()) == 3); + + i = c.emplace_after(c.cbegin(), 3, 4.5); + assert(i == next(c.begin())); + assert(c.front() == Emplaceable()); + assert(*next(c.begin(), 1) == Emplaceable(3, 4.5)); + assert(*next(c.begin(), 2) == Emplaceable(1, 2.5)); + assert(*next(c.begin(), 3) == Emplaceable(2, 3.5)); + assert(distance(c.begin(), c.end()) == 4); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..b831324f019 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class... Args> void emplace_front(Args&&... args); + +#include <forward_list> +#include <cassert> + +#include "../../../Emplaceable.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef Emplaceable T; + typedef std::forward_list<T> C; + C c; + c.emplace_front(); + assert(c.front() == Emplaceable()); + assert(distance(c.begin(), c.end()) == 1); + c.emplace_front(1, 2.5); + assert(c.front() == Emplaceable(1, 2.5)); + assert(*next(c.begin()) == Emplaceable()); + assert(distance(c.begin(), c.end()) == 2); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp new file mode 100644 index 00000000000..5d43a7c7286 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void erase_after(const_iterator first, const_iterator last); + +#include <forward_list> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + + c.erase_after(next(c.cbefore_begin(), 4), next(c.cbefore_begin(), 4)); + assert(distance(c.begin(), c.end()) == 10); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + assert(*next(c.begin(), 4) == 4); + assert(*next(c.begin(), 5) == 5); + assert(*next(c.begin(), 6) == 6); + assert(*next(c.begin(), 7) == 7); + assert(*next(c.begin(), 8) == 8); + assert(*next(c.begin(), 9) == 9); + + c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 5)); + assert(distance(c.begin(), c.end()) == 8); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + assert(*next(c.begin(), 5) == 7); + assert(*next(c.begin(), 6) == 8); + assert(*next(c.begin(), 7) == 9); + + c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 3)); + assert(distance(c.begin(), c.end()) == 8); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + assert(*next(c.begin(), 5) == 7); + assert(*next(c.begin(), 6) == 8); + assert(*next(c.begin(), 7) == 9); + + c.erase_after(next(c.cbefore_begin(), 5), next(c.cbefore_begin(), 9)); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + + c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 2)); + assert(distance(c.begin(), c.end()) == 4); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 4); + assert(*next(c.begin(), 2) == 5); + assert(*next(c.begin(), 3) == 6); + + c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 5)); + assert(distance(c.begin(), c.end()) == 0); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp new file mode 100644 index 00000000000..188ad524f0d --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void erase_after(const_iterator p); + +#include <forward_list> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.erase_after(next(c.cbefore_begin(), 4)); + assert(distance(c.begin(), c.end()) == 4); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + + c.erase_after(next(c.cbefore_begin(), 0)); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 2); + assert(*next(c.begin(), 2) == 3); + + c.erase_after(next(c.cbefore_begin(), 1)); + assert(distance(c.begin(), c.end()) == 2); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 3); + + c.erase_after(next(c.cbefore_begin(), 1)); + assert(distance(c.begin(), c.end()) == 1); + assert(*next(c.begin(), 0) == 1); + + c.erase_after(next(c.cbefore_begin(), 0)); + assert(distance(c.begin(), c.end()) == 0); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp new file mode 100644 index 00000000000..1d195bc5df8 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator insert_after(const_iterator p, const value_type& v); + +#include <forward_list> +#include <cassert> + + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0); + assert(i == c.begin()); + assert(c.front() == 0); + assert(c.front() == 0); + assert(distance(c.begin(), c.end()) == 1); + + i = c.insert_after(c.cbegin(), 1); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + + i = c.insert_after(next(c.cbegin()), 2); + assert(i == next(c.begin(), 2)); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(*next(c.begin(), 2) == 2); + assert(distance(c.begin(), c.end()) == 3); + + i = c.insert_after(c.cbegin(), 3); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 1); + assert(*next(c.begin(), 3) == 2); + assert(distance(c.begin(), c.end()) == 4); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp new file mode 100644 index 00000000000..b39b243d319 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator insert_after(const_iterator p, initializer_list<value_type> il); + +#include <forward_list> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef int T; + typedef std::forward_list<T> C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), {}); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), {0, 1, 2}); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + i = c.insert_after(c.begin(), {3, 4}); + assert(i == c.begin()); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 1); + assert(*next(c.begin(), 4) == 2); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp new file mode 100644 index 00000000000..c3cea9d3e85 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class InputIterator> +// iterator insert_after(const_iterator p, +// InputIterator first, InputIterator last); + +#include <forward_list> +#include <cassert> + +#include "../../../iterators.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + typedef C::iterator I; + typedef input_iterator<const T*> J; + C c; + const T t[] = {0, 1, 2, 3, 4}; + I i = c.insert_after(c.cbefore_begin(), J(t), J(t)); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), J(t), J(t+3)); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + i = c.insert_after(c.begin(), J(t+3), J(t+5)); + assert(i == c.begin()); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 1); + assert(*next(c.begin(), 4) == 2); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp new file mode 100644 index 00000000000..02eabb162b4 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator insert_after(const_iterator p, value_type&& v); + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly T; + typedef std::forward_list<T> C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0); + assert(i == c.begin()); + assert(c.front() == 0); + assert(c.front() == 0); + assert(distance(c.begin(), c.end()) == 1); + + i = c.insert_after(c.cbegin(), 1); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + + i = c.insert_after(next(c.cbegin()), 2); + assert(i == next(c.begin(), 2)); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(*next(c.begin(), 2) == 2); + assert(distance(c.begin(), c.end()) == 3); + + i = c.insert_after(c.cbegin(), 3); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 1); + assert(*next(c.begin(), 3) == 2); + assert(distance(c.begin(), c.end()) == 4); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp new file mode 100644 index 00000000000..18885d98d2a --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator insert_after(const_iterator p, size_type n, const value_type& v); + +#include <forward_list> +#include <cassert> + + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0, 0); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), 3, 3); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 3); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 3); + + i = c.insert_after(c.begin(), 2, 2); + assert(i == c.begin()); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 3); + assert(*next(c.begin(), 1) == 2); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + assert(*next(c.begin(), 4) == 3); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..44f7c4062c0 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void pop_front(); + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + typedef std::forward_list<T> C; + C c; + c.push_front(1); + c.push_front(3); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 1); + assert(c.front() == 1); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 0); + } +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly T; + typedef std::forward_list<T> C; + C c; + c.push_front(1); + c.push_front(3); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 1); + assert(c.front() == 1); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 0); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp new file mode 100644 index 00000000000..7dfe9311a2a --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void push_front(const value_type& v); + +#include <forward_list> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + C c; + c.push_front(1); + assert(c.front() == 1); + assert(distance(c.begin(), c.end()) == 1); + c.push_front(3); + assert(c.front() == 3); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp new file mode 100644 index 00000000000..a6a439da9f2 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void push_front(value_type&& v); + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly T; + typedef std::forward_list<T> C; + C c; + c.push_front(1); + assert(c.front() == 1); + assert(distance(c.begin(), c.end()) == 1); + c.push_front(3); + assert(c.front() == 3); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + } +#endif +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp new file mode 100644 index 00000000000..293427d4f1c --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void resize(size_type n); + +#include <forward_list> +#include <cassert> + +#include "../../../DefaultOnly.h" + +int main() +{ + { + typedef DefaultOnly T; + typedef std::forward_list<T> C; + C c; + c.resize(0); + assert(distance(c.begin(), c.end()) == 0); + c.resize(10); + assert(distance(c.begin(), c.end()) == 10); + c.resize(20); + assert(distance(c.begin(), c.end()) == 20); + c.resize(5); + assert(distance(c.begin(), c.end()) == 5); + c.resize(0); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.resize(3); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + c.resize(6); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 0); + assert(*next(c.begin(), 4) == 0); + assert(*next(c.begin(), 5) == 0); + + c.resize(6); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 0); + assert(*next(c.begin(), 4) == 0); + assert(*next(c.begin(), 5) == 0); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp new file mode 100644 index 00000000000..9698fd6b369 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void resize(size_type n, const value_type& v); + +#include <forward_list> +#include <cassert> + +#include "../../../DefaultOnly.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.resize(3, 10); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + c.resize(6, 10); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 10); + assert(*next(c.begin(), 4) == 10); + assert(*next(c.begin(), 5) == 10); + + c.resize(6, 12); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 10); + assert(*next(c.begin(), 4) == 10); + assert(*next(c.begin(), 5) == 10); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp new file mode 100644 index 00000000000..438bd6cd985 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void merge(forward_list&& x); + +#include <forward_list> +#include <iterator> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {3, 5, 6, 7, 12, 13}; + const T t2[] = {0, 1, 2, 4, 8, 9, 10, 11, 14, 15}; + const T t3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.merge(c2); + C c3(std::begin(t3), std::end(t3)); + assert(c1 == c3); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp new file mode 100644 index 00000000000..5123084a35a --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class Compare> void merge(forward_list&& x, Compare comp); + +#include <forward_list> +#include <iterator> +#include <functional> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {13, 12, 7, 6, 5, 3}; + const T t2[] = {15, 14, 11, 10, 9, 8, 4, 2, 1, 0}; + const T t3[] = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.merge(c2, std::greater<T>()); + C c3(std::begin(t3), std::end(t3)); + assert(c1 == c3); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp new file mode 100644 index 00000000000..d68078c71bc --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void remove(const value_type& v); + +#include <forward_list> +#include <iterator> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 0, 0, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2; + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + C c1; + C c2; + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp new file mode 100644 index 00000000000..9a85d958d48 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class Predicate> void remove_if(Predicate pred); + +#include <forward_list> +#include <iterator> +#include <cassert> + +bool g(int i) +{ + return i < 3; +} + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove_if(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 0, 0, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2; + c1.remove_if(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove_if(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + C c1; + C c2; + c1.remove_if(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove_if(g); + assert(c1 == c2); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp new file mode 100644 index 00000000000..2516f51ccfa --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void reverse(); + +#include <forward_list> +#include <iterator> +#include <algorithm> +#include <cassert> + +void test(int N) +{ + typedef int T; + typedef std::forward_list<T> C; + C c; + for (int i = 0; i < N; ++i) + c.push_front(i); + c.reverse(); + assert(distance(c.begin(), c.end()) == N); + C::const_iterator j = c.begin(); + for (int i = 0; i < N; ++i, ++j) + assert(*j == i); +} + +int main() +{ + for (int i = 0; i < 10; ++i) + test(i); +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp new file mode 100644 index 00000000000..79b0109683b --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void sort(); + +#include <forward_list> +#include <iterator> +#include <algorithm> +#include <vector> +#include <cassert> + +void test(int N) +{ + typedef int T; + typedef std::forward_list<T> C; + typedef std::vector<T> V; + V v; + for (int i = 0; i < N; ++i) + v.push_back(i); + std::random_shuffle(v.begin(), v.end()); + C c(v.begin(), v.end()); + c.sort(); + assert(distance(c.begin(), c.end()) == N); + C::const_iterator j = c.begin(); + for (int i = 0; i < N; ++i, ++j) + assert(*j == i); +} + +int main() +{ + for (int i = 0; i < 40; ++i) + test(i); +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp new file mode 100644 index 00000000000..b220e1775d6 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class Compare> void sort(Compare comp); + +#include <forward_list> +#include <iterator> +#include <algorithm> +#include <vector> +#include <functional> +#include <cassert> + +void test(int N) +{ + typedef int T; + typedef std::forward_list<T> C; + typedef std::vector<T> V; + V v; + for (int i = 0; i < N; ++i) + v.push_back(i); + std::random_shuffle(v.begin(), v.end()); + C c(v.begin(), v.end()); + c.sort(std::greater<T>()); + assert(distance(c.begin(), c.end()) == N); + C::const_iterator j = c.begin(); + for (int i = 0; i < N; ++i, ++j) + assert(*j == N-1-i); +} + +int main() +{ + for (int i = 0; i < 40; ++i) + test(i); +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp new file mode 100644 index 00000000000..a1692949a04 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void splice_after(const_iterator p, forward_list&& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +typedef int T; +typedef std::forward_list<T> C; +const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7}; +const T t2[] = {10, 11, 12, 13, 14, 15}; +const int size_t1 = std::end(t1) - std::begin(t1); +const int size_t2 = std::end(t2) - std::begin(t2); + +void +testd(const C& c, int p, int l) +{ + C::const_iterator i = c.begin(); + int n1 = 0; + for (; n1 < p; ++n1, ++i) + assert(*i == t1[n1]); + for (int n2 = 0; n2 < l; ++n2, ++i) + assert(*i == t2[n2]); + for (; n1 < size_t1; ++n1, ++i) + assert(*i == t1[n1]); + assert(distance(c.begin(), c.end()) == size_t1 + l); +} + +int main() +{ + // splicing different containers + for (int l = 0; l <= size_t2; ++l) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(t2, t2+l); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2)); + testd(c1, p, l); + } + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp new file mode 100644 index 00000000000..08c365e9ebe --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void splice_after(const_iterator p, forward_list&& x, const_iterator i); + +#include <forward_list> +#include <cassert> +#include <iterator> + +typedef int T; +typedef std::forward_list<T> C; +const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7}; +const T t2[] = {10, 11, 12}; +const int size_t1 = std::end(t1) - std::begin(t1); +const int size_t2 = std::end(t2) - std::begin(t2); + +void +testd(const C& c, int p, int f) +{ + C::const_iterator i = c.begin(); + int n1 = 0; + for (; n1 < p; ++n1, ++i) + assert(*i == t1[n1]); + for (int n2 = f; n2 < f+1; ++n2, ++i) + assert(*i == t2[n2]); + for (; n1 < size_t1; ++n1, ++i) + assert(*i == t1[n1]); + assert(distance(c.begin(), c.end()) == size_t1 + 1); +} + +void +tests(const C& c, int p, int f) +{ + C::const_iterator i = c.begin(); + int n = 0; + int d = 1; + if (p == f || p == f+1) + { + for (n = 0; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + else if (p < f) + { + for (n = 0; n < p; ++n, ++i) + assert(*i == t1[n]); + for (n = f; n < f+1; ++n, ++i) + assert(*i == t1[n]); + for (n = p; n < f; ++n, ++i) + assert(*i == t1[n]); + for (n = f+1; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + else // p > f+1 + { + for (n = 0; n < f; ++n, ++i) + assert(*i == t1[n]); + for (n = f+1; n < p; ++n, ++i) + assert(*i == t1[n]); + for (n = f; n < f+1; ++n, ++i) + assert(*i == t1[n]); + for (n = p; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + assert(distance(c.begin(), c.end()) == size_t1); +} + +int main() +{ + // splicing different containers + for (int f = 0; f <= size_t2-1; ++f) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2), + next(c2.cbefore_begin(), f)); + testd(c1, p, f); + } + } + + // splicing within same container + for (int f = 0; f <= size_t1-1; ++f) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f)); + tests(c1, p, f); + } + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp new file mode 100644 index 00000000000..2aac66a4688 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void splice_after(const_iterator p, forward_list&& x, +// const_iterator first, const_iterator last); + +#include <forward_list> +#include <cassert> +#include <iterator> + +typedef int T; +typedef std::forward_list<T> C; +const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7}; +const T t2[] = {10, 11, 12, 13, 14, 15}; +const int size_t1 = std::end(t1) - std::begin(t1); +const int size_t2 = std::end(t2) - std::begin(t2); + +void +testd(const C& c, int p, int f, int l) +{ + C::const_iterator i = c.begin(); + int n1 = 0; + for (; n1 < p; ++n1, ++i) + assert(*i == t1[n1]); + for (int n2 = f; n2 < l-1; ++n2, ++i) + assert(*i == t2[n2]); + for (; n1 < size_t1; ++n1, ++i) + assert(*i == t1[n1]); + assert(distance(c.begin(), c.end()) == size_t1 + (l > f+1 ? l-1-f : 0)); +} + +void +tests(const C& c, int p, int f, int l) +{ + C::const_iterator i = c.begin(); + int n = 0; + int d = l > f+1 ? l-1-f : 0; + if (d == 0 || p == f) + { + for (n = 0; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + else if (p < f) + { + for (n = 0; n < p; ++n, ++i) + assert(*i == t1[n]); + for (n = f; n < l-1; ++n, ++i) + assert(*i == t1[n]); + for (n = p; n < f; ++n, ++i) + assert(*i == t1[n]); + for (n = l-1; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + else // p > f + { + for (n = 0; n < f; ++n, ++i) + assert(*i == t1[n]); + for (n = l-1; n < p; ++n, ++i) + assert(*i == t1[n]); + for (n = f; n < l-1; ++n, ++i) + assert(*i == t1[n]); + for (n = p; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + assert(distance(c.begin(), c.end()) == size_t1); +} + +int main() +{ + // splicing different containers + for (int f = 0; f <= size_t2+1; ++f) + { + for (int l = f; l <= size_t2+1; ++l) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2), + next(c2.cbefore_begin(), f), next(c2.cbefore_begin(), l)); + testd(c1, p, f, l); + } + } + } + + // splicing within same container + for (int f = 0; f <= size_t1+1; ++f) + { + for (int l = f; l <= size_t1; ++l) + { + for (int p = 0; p <= f; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l)); + tests(c1, p, f, l); + } + for (int p = l; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l)); + tests(c1, p, f, l); + } + } + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp new file mode 100644 index 00000000000..bed53ec7972 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void unique(); + +#include <forward_list> +#include <iterator> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {0, 5, 0, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 0, 0, 0}; + const T t2[] = {0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + C c1; + C c2; + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp new file mode 100644 index 00000000000..d7d85439545 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class BinaryPredicate> void unique(BinaryPredicate binary_pred); + +#include <forward_list> +#include <iterator> +#include <cassert> + +bool g(int x, int y) +{ + return x == y; +} + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {0, 5, 0, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {0, 0, 0, 0}; + const T t2[] = {0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + C c1; + C c2; + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T> C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp new file mode 100644 index 00000000000..c4b3f37e065 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class T, class Allocator> +// bool operator==(const forward_list<T, Allocator>& x, +// const forward_list<T, Allocator>& y); +// +// template <class T, class Allocator> +// bool operator!=(const forward_list<T, Allocator>& x, +// const forward_list<T, Allocator>& y); + +#include <forward_list> +#include <iterator> +#include <algorithm> +#include <cassert> + +void test(int N, int M) +{ + typedef int T; + typedef std::forward_list<T> C; + C c1; + for (int i = 0; i < N; ++i) + c1.push_front(i); + C c2; + for (int i = 0; i < M; ++i) + c2.push_front(i); + if (N == M) + assert(c1 == c2); + else + assert(c1 != c2); + c2 = c1; + assert(c1 == c2); + if (N > 0) + { + c2.front() = N+1; + assert(c1 != c2); + } +} + +int main() +{ + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + test(i, j); +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp new file mode 100644 index 00000000000..561c4b17765 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp @@ -0,0 +1,178 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void swap(forward_list& x); + +#include <forward_list> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + C c2(A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A(1)); + C c2(A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(2)); + } + + { + typedef int T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + C c2(A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A(1)); + C c2(A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(1)); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp new file mode 100644 index 00000000000..69c50ebbe48 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp @@ -0,0 +1,179 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class T, class Allocator> +// void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y); + +#include <forward_list> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + C c2(A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A(1)); + C c2(A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(2)); + } + + { + typedef int T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + C c2(A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A(1)); + C c2(A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(1)); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp b/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp new file mode 100644 index 00000000000..33c2bbca710 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class T, class Allocator> +// bool operator< (const forward_list<T, Allocator>& x, +// const forward_list<T, Allocator>& y); +// +// template <class T, class Allocator> +// bool operator> (const forward_list<T, Allocator>& x, +// const forward_list<T, Allocator>& y); +// +// template <class T, class Allocator> +// bool operator>=(const forward_list<T, Allocator>& x, +// const forward_list<T, Allocator>& y); +// +// template <class T, class Allocator> +// bool operator<=(const forward_list<T, Allocator>& x, +// const forward_list<T, Allocator>& y); + +#include <forward_list> +#include <iterator> +#include <algorithm> +#include <cassert> + +void test(int N, int M) +{ + typedef int T; + typedef std::forward_list<T> C; + C c1; + for (int i = 0; i < N; ++i) + c1.push_front(i); + C c2; + for (int i = 0; i < M; ++i) + c2.push_front(i); + if (N < M) + assert(c1 < c2); + if (N <= M) + assert(c1 <= c2); + if (N >= M) + assert(c1 >= c2); + if (N > M) + assert(c1 > c2); +} + +int main() +{ + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + test(i, j); +} diff --git a/libcxx/test/containers/sequences/forwardlist/max_size.pass.cpp b/libcxx/test/containers/sequences/forwardlist/max_size.pass.cpp new file mode 100644 index 00000000000..b42ff869eed --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/max_size.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// size_type max_size() const; + +#include <forward_list> +#include <cassert> + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + C c; + assert(c.max_size() > 0); + } +} diff --git a/libcxx/test/containers/sequences/forwardlist/types.pass.cpp b/libcxx/test/containers/sequences/forwardlist/types.pass.cpp new file mode 100644 index 00000000000..814bca73477 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/types.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class T, class Allocator = allocator<T>> +// class forward_list +// { +// public: +// typedef T value_type; +// typedef Allocator allocator_type; +// +// typedef value_type& reference; +// typedef const value_type& const_reference; +// typedef typename allocator_traits<allocator_type>::pointer pointer; +// typedef typename allocator_traits<allocator_type>::const_pointer const_pointer; +// typedef typename allocator_traits<allocator_type>::size_type size_type; +// typedef typename allocator_traits<allocator_type>::difference_type difference_type; +// ... +// }; + +#include <forward_list> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::forward_list<char>::value_type, char>::value), ""); + static_assert((std::is_same<std::forward_list<char>::allocator_type, std::allocator<char> >::value), ""); + static_assert((std::is_same<std::forward_list<char>::reference, char&>::value), ""); + static_assert((std::is_same<std::forward_list<char>::const_reference, const char&>::value), ""); + static_assert((std::is_same<std::forward_list<char>::pointer, char*>::value), ""); + static_assert((std::is_same<std::forward_list<char>::const_pointer, const char*>::value), ""); + static_assert((std::is_same<std::forward_list<char>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::forward_list<char>::difference_type, std::ptrdiff_t>::value), ""); +} diff --git a/libcxx/test/containers/sequences/forwardlist/version.pass.cpp b/libcxx/test/containers/sequences/forwardlist/version.pass.cpp new file mode 100644 index 00000000000..d91bd747f66 --- /dev/null +++ b/libcxx/test/containers/sequences/forwardlist/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +#include <forward_list> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/list/list.capacity/resize_size.pass.cpp b/libcxx/test/containers/sequences/list/list.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..2369a5f4639 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.capacity/resize_size.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void resize(size_type sz); + +#include <list> +#include <cassert> +#include "../../../DefaultOnly.h" + +int main() +{ + { + std::list<int> l(5, 2); + l.resize(2); + assert(l.size() == 2); + assert(std::distance(l.begin(), l.end()) == 2); + assert(l == std::list<int>(2, 2)); + } + { + std::list<int> l(5, 2); + l.resize(10); + assert(l.size() == 10); + assert(std::distance(l.begin(), l.end()) == 10); + assert(l.front() == 2); + assert(l.back() == 0); + } +#ifdef __LIBCPP_MOVE + { + std::list<DefaultOnly> l(10); + l.resize(5); + assert(l.size() == 5); + assert(std::distance(l.begin(), l.end()) == 5); + } + { + std::list<DefaultOnly> l(10); + l.resize(20); + assert(l.size() == 20); + assert(std::distance(l.begin(), l.end()) == 20); + } +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.capacity/resize_size_value.pass.cpp b/libcxx/test/containers/sequences/list/list.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..3eca805bb6d --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.capacity/resize_size_value.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void resize(size_type sz, const value_type& x); + +#include <list> +#include <cassert> +#include "../../../DefaultOnly.h" + +int main() +{ + { + std::list<double> l(5, 2); + l.resize(2, 3.5); + assert(l.size() == 2); + assert(std::distance(l.begin(), l.end()) == 2); + assert(l == std::list<double>(2, 2)); + } + { + std::list<double> l(5, 2); + l.resize(10, 3.5); + assert(l.size() == 10); + assert(std::distance(l.begin(), l.end()) == 10); + assert(l.front() == 2); + assert(l.back() == 3.5); + } +} diff --git a/libcxx/test/containers/sequences/list/list.cons/assign_copy.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..bca800d8040 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/assign_copy.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list& operator=(const list& c); + +#include <list> +#include <cassert> +#include "../../../test_allocator.h" + +int main() +{ + { + std::list<int, test_allocator<int> > l(3, 2, test_allocator<int>(5)); + std::list<int, test_allocator<int> > l2(l, test_allocator<int>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<int>(3)); + } + { + std::list<int, other_allocator<int> > l(3, 2, other_allocator<int>(5)); + std::list<int, other_allocator<int> > l2(l, other_allocator<int>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<int>(5)); + } +} diff --git a/libcxx/test/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..eb7a50efe7a --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void assign(initializer_list<value_type> il); + +#include <list> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<int> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + std::list<int>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/assign_move.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..2c2ec5345bc --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/assign_move.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list& operator=(list&& c); + +#include <list> +#include <cassert> +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); + } + { + std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/copy.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/copy.pass.cpp new file mode 100644 index 00000000000..3a563ebd15d --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/copy.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(const list& c); + +#include <list> +#include <cassert> +#include "../../../DefaultOnly.h" +#include "../../../test_allocator.h" + +int main() +{ + { + std::list<int> l(3, 2); + std::list<int> l2 = l; + assert(l2 == l); + } + { + std::list<int, test_allocator<int> > l(3, 2, test_allocator<int>(5)); + std::list<int, test_allocator<int> > l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == l.get_allocator()); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::list<int, other_allocator<int> > l(3, 2, other_allocator<int>(5)); + std::list<int, other_allocator<int> > l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<int>(-2)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/copy_alloc.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..9c941233595 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/copy_alloc.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(const list& c, const allocator_type& a); + +#include <list> +#include <cassert> +#include "../../../DefaultOnly.h" +#include "../../../test_allocator.h" + +int main() +{ + { + std::list<int, test_allocator<int> > l(3, 2, test_allocator<int>(5)); + std::list<int, test_allocator<int> > l2(l, test_allocator<int>(3)); + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<int>(3)); + } + { + std::list<int, other_allocator<int> > l(3, 2, other_allocator<int>(5)); + std::list<int, other_allocator<int> > l2(l, other_allocator<int>(3)); + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<int>(3)); + } +} diff --git a/libcxx/test/containers/sequences/list/list.cons/default.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/default.pass.cpp new file mode 100644 index 00000000000..579c3aa1778 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/default.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// explicit list(const Alloc& = Alloc()); + +#include <list> +#include <cassert> +#include "../../../DefaultOnly.h" + +int main() +{ + { + std::list<int> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list<DefaultOnly> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list<int> l((std::allocator<int>())); + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } +} diff --git a/libcxx/test/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp new file mode 100644 index 00000000000..e6e11e276cb --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// explicit list(const Alloc& = Alloc()); + +#include <list> +#include <cassert> +#include "../../../stack_allocator.h" + +#include <iostream> + +int main() +{ + { + std::list<int> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list<int> l((std::allocator<int>())); + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list<int, stack_allocator<int, 4> > l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } +} diff --git a/libcxx/test/containers/sequences/list/list.cons/initializer_list.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..14d1a79b6a1 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/initializer_list.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(initializer_list<value_type> il); + +#include <list> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<int> d = {3, 4, 5, 6}; + assert(d.size() == 4); + std::list<int>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..6f00e2ff71d --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <list> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<int, test_allocator<int>> d({3, 4, 5, 6}, test_allocator<int>(3)); + assert(d.get_allocator() == test_allocator<int>(3)); + assert(d.size() == 4); + std::list<int>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/input_iterator.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/input_iterator.pass.cpp new file mode 100644 index 00000000000..e740b3e498e --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/input_iterator.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class InputIterator> +// list(InputIterator first, InputIterator last, const Allocator& = Allocator()); + +#include <list> +#include <cassert> +#include "../../../iterators.h" +#include "../../../stack_allocator.h" + +int main() +{ + { + int a[] = {0, 1, 2, 3}; + std::list<int> l(input_iterator<const int*>(a), + input_iterator<const int*>(a + sizeof(a)/sizeof(a[0]))); + assert(l.size() == sizeof(a)/sizeof(a[0])); + assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); + int j = 0; + for (std::list<int>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } + { + int a[] = {0, 1, 2, 3}; + std::list<int> l(input_iterator<const int*>(a), + input_iterator<const int*>(a + sizeof(a)/sizeof(a[0])), + std::allocator<int>()); + assert(l.size() == sizeof(a)/sizeof(a[0])); + assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); + int j = 0; + for (std::list<int>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } + { + int a[] = {0, 1, 2, 3}; + std::list<int, stack_allocator<int, sizeof(a)/sizeof(a[0])> > l(input_iterator<const int*>(a), + input_iterator<const int*>(a + sizeof(a)/sizeof(a[0]))); + assert(l.size() == sizeof(a)/sizeof(a[0])); + assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); + int j = 0; + for (std::list<int>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } +} diff --git a/libcxx/test/containers/sequences/list/list.cons/move.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/move.pass.cpp new file mode 100644 index 00000000000..189d63708bd --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/move.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(list&& c); + +#include <list> +#include <cassert> +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/move_alloc.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..4f5779eabb3 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/move_alloc.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(list&& c, const allocator_type& a); + +#include <list> +#include <cassert> +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); + } + { + std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5)); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(5)); + } + { + std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, other_allocator<MoveOnly> > l2(std::move(l), other_allocator<MoveOnly>(4)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == other_allocator<MoveOnly>(4)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..4ce3e5d049a --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list& operator=(initializer_list<value_type> il); + +#include <list> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<int> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + std::list<int>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/size_type.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/size_type.pass.cpp new file mode 100644 index 00000000000..4a9682245d9 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/size_type.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// explicit list(size_type n); + +#include <list> +#include <cassert> +#include "../../../DefaultOnly.h" +#include "../../../stack_allocator.h" + +int main() +{ + { + std::list<int> l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list<int>::const_iterator i = l.begin(); + assert(*i == 0); + ++i; + assert(*i == 0); + ++i; + assert(*i == 0); + } + { + std::list<int, stack_allocator<int, 3> > l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list<int>::const_iterator i = l.begin(); + assert(*i == 0); + ++i; + assert(*i == 0); + ++i; + assert(*i == 0); + } +#ifdef _LIBCPP_MOVE + { + std::list<DefaultOnly> l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + } +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.cons/size_value_alloc.pass.cpp b/libcxx/test/containers/sequences/list/list.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..34c9f7e36b9 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.cons/size_value_alloc.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(size_type n, const T& value, const Allocator& = Allocator()); + +#include <list> +#include <cassert> +#include "../../../DefaultOnly.h" +#include "../../../stack_allocator.h" + +int main() +{ + { + std::list<int> l(3, 2); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list<int>::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } + { + std::list<int> l(3, 2, std::allocator<int>()); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list<int>::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } + { + std::list<int, stack_allocator<int, 3> > l(3, 2); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list<int>::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/clear.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..1ebe348a4d3 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/clear.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void clear(); + +#include <list> +#include <cassert> + +int main() +{ + int a[] = {1, 2, 3}; + std::list<int> c(a, a+3); + c.clear(); + assert(c.empty()); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/emplace.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..60d5bc192ca --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/emplace.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class... Args> void emplace(const_iterator p, Args&&... args); + +#include <list> +#include <cassert> + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<A> c; + c.emplace(c.cbegin(), 2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace(c.cend(), 3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/emplace_back.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..7d1837955f0 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/emplace_back.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class... Args> void emplace_back(Args&&... args); + +#include <list> +#include <cassert> + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<A> c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/emplace_front.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..f60c4926db0 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/emplace_front.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class... Args> void emplace_front(Args&&... args); + +#include <list> +#include <cassert> + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<A> c; + c.emplace_front(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace_front(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 3); + assert(c.front().getd() == 4.5); + assert(c.back().geti() == 2); + assert(c.back().getd() == 3.5); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/erase_iter.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..16b725fd241 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/erase_iter.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator erase(const_iterator position); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {1, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int>::const_iterator i = l1.begin(); + ++i; + std::list<int>::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == 3); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == 3); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..629654193a3 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator erase(const_iterator first, const_iterator last); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {1, 2, 3}; + { + std::list<int> l1(a1, a1+3); + std::list<int>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + } + { + std::list<int> l1(a1, a1+3); + std::list<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert(l1 == std::list<int>(a1+1, a1+3)); + } + { + std::list<int> l1(a1, a1+3); + std::list<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert(l1 == std::list<int>(a1+2, a1+3)); + } + { + std::list<int> l1(a1, a1+3); + std::list<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + } +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..cdbe902a8af --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <list> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<int> d(10, 1); + std::list<int>::iterator i = d.insert(next(d.cbegin(), 2), {3, 4, 5, 6}); + assert(d.size() == 14); + assert(i == next(d.begin(), 2)); + i = d.begin(); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..31c057f0f4d --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <InputIterator Iter> +// iterator insert(const_iterator position, Iter first, Iter last); + +#include <list> +#include <cstdlib> +#include <cassert> + +int throw_next = 0xFFFF; +int count = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next == 0) + throw std::bad_alloc(); + --throw_next; + ++count; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --count; + std::free(p); +} + +int main() +{ + int a1[] = {1, 2, 3}; + std::list<int> l1; + std::list<int>::iterator i = l1.insert(l1.begin(), a1, a1+3); + assert(i == l1.begin()); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + int a2[] = {4, 5, 6}; + i = l1.insert(i, a2, a2+3); + assert(*i == 4); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); + throw_next = 2; + int save_count = count; + try + { + i = l1.insert(i, a2, a2+3); + assert(false); + } + catch (...) + { + } + assert(save_count == count); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp new file mode 100644 index 00000000000..1a1c97d799e --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator insert(const_iterator position, value_type&& x); + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<MoveOnly> l1; + l1.insert(l1.cend(), MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.insert(l1.cbegin(), MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(2)); + assert(l1.back() == MoveOnly(1)); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..ec9b0e9a46a --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +#include <list> +#include <cstdlib> +#include <cassert> + +int throw_next = 0xFFFF; +int count = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next == 0) + throw std::bad_alloc(); + --throw_next; + ++count; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --count; + std::free(p); +} + +int main() +{ + int a1[] = {1, 2, 3}; + int a2[] = {1, 4, 4, 4, 4, 4, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int>::iterator i = l1.insert(next(l1.cbegin()), 5, 4); + assert(i == next(l1.begin())); + assert(l1 == std::list<int>(a2, a2+8)); + throw_next = 4; + int save_count = count; + try + { + i = l1.insert(i, 5, 5); + assert(false); + } + catch (...) + { + } + throw_next = 0xFFFF; + assert(save_count == count); + assert(l1 == std::list<int>(a2, a2+8)); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..02d2cd116ca --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator insert(const_iterator position, const value_type& x); + +#include <list> +#include <cstdlib> +#include <cassert> + +int throw_next = 0xFFFF; +int count = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next == 0) + throw std::bad_alloc(); + --throw_next; + ++count; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --count; + std::free(p); +} + +int main() +{ + int a1[] = {1, 2, 3}; + int a2[] = {1, 4, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int>::iterator i = l1.insert(next(l1.cbegin()), 4); + assert(i == next(l1.begin())); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l1 == std::list<int>(a2, a2+4)); + throw_next = 0; + int save_count = count; + try + { + i = l1.insert(i, 5); + assert(false); + } + catch (...) + { + } + throw_next = 0xFFFF; + assert(save_count == count); + assert(l1 == std::list<int>(a2, a2+4)); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/pop_back.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..14deedb72b3 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/pop_back.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void pop_back(); + +#include <list> +#include <cassert> + +int main() +{ + int a[] = {1, 2, 3}; + std::list<int> c(a, a+3); + c.pop_back(); + assert(c == std::list<int>(a, a+2)); + c.pop_back(); + assert(c == std::list<int>(a, a+1)); + c.pop_back(); + assert(c.empty()); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/pop_front.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..159bc76c83d --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/pop_front.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void pop_front(); + +#include <list> +#include <cassert> + +int main() +{ + int a[] = {1, 2, 3}; + std::list<int> c(a, a+3); + c.pop_front(); + assert(c == std::list<int>(a+1, a+3)); + c.pop_front(); + assert(c == std::list<int>(a+2, a+3)); + c.pop_front(); + assert(c.empty()); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/push_back.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..8a1970ab08e --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/push_back.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_back(const value_type& x); + +#include <list> +#include <cassert> + +int main() +{ + std::list<int> c; + for (int i = 0; i < 5; ++i) + c.push_back(i); + int a[] = {0, 1, 2, 3, 4}; + assert(c == std::list<int>(a, a+5)); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..f51f05d8b38 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_back(value_type&& x); + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<MoveOnly> l1; + l1.push_back(MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.push_back(MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(1)); + assert(l1.back() == MoveOnly(2)); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/push_front.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/push_front.pass.cpp new file mode 100644 index 00000000000..5a71f331c34 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/push_front.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_front(const value_type& x); + +#include <list> +#include <cassert> + +int main() +{ + std::list<int> c; + for (int i = 0; i < 5; ++i) + c.push_front(i); + int a[] = {4, 3, 2, 1, 0}; + assert(c == std::list<int>(a, a+5)); +} diff --git a/libcxx/test/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp b/libcxx/test/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp new file mode 100644 index 00000000000..8f2773ed42a --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_front(value_type&& x); + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::list<MoveOnly> l1; + l1.push_front(MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.push_front(MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(2)); + assert(l1.back() == MoveOnly(1)); +#endif +} diff --git a/libcxx/test/containers/sequences/list/list.ops/merge.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/merge.pass.cpp new file mode 100644 index 00000000000..75eb5735db1 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/merge.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void merge(list& x); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + c1.merge(c2); + assert(c1 == std::list<int>(a3, a3+sizeof(a3)/sizeof(a3[0]))); +} diff --git a/libcxx/test/containers/sequences/list/list.ops/merge_comp.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/merge_comp.pass.cpp new file mode 100644 index 00000000000..6ef125da411 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/merge_comp.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class Compare> void merge(list& x, Compare comp); + +#include <list> +#include <functional> +#include <cassert> + +int main() +{ + int a1[] = {10, 9, 7, 3, 1}; + int a2[] = {11, 8, 6, 5, 4, 2, 0}; + int a3[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + c1.merge(c2, std::greater<int>()); + assert(c1 == std::list<int>(a3, a3+sizeof(a3)/sizeof(a3[0]))); +} diff --git a/libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp new file mode 100644 index 00000000000..4896d422a10 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/remove.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void remove(const value_type& value); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {1, 2, 3, 4}; + int a2[] = {1, 2, 4}; + std::list<int> c(a1, a1+4); + c.remove(3); + assert(c == std::list<int>(a2, a2+3)); +} diff --git a/libcxx/test/containers/sequences/list/list.ops/remove_if.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/remove_if.pass.cpp new file mode 100644 index 00000000000..e35984fc51a --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/remove_if.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class Pred> void remove_if(Pred pred); + +#include <list> +#include <cassert> +#include <functional> + +bool g(int i) +{ + return i < 3; +} + +int main() +{ + int a1[] = {1, 2, 3, 4}; + int a2[] = {3, 4}; + std::list<int> c(a1, a1+4); + c.remove_if(g); + assert(c == std::list<int>(a2, a2+2)); +} diff --git a/libcxx/test/containers/sequences/list/list.ops/reverse.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/reverse.pass.cpp new file mode 100644 index 00000000000..2cdbcde9def --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/reverse.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void reverse(); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.reverse(); + assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); +} diff --git a/libcxx/test/containers/sequences/list/list.ops/sort.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/sort.pass.cpp new file mode 100644 index 00000000000..0c1ec4f2683 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/sort.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void sort(); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9}; + int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.sort(); + assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); +} diff --git a/libcxx/test/containers/sequences/list/list.ops/sort_comp.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/sort_comp.pass.cpp new file mode 100644 index 00000000000..1a7577834c9 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/sort_comp.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class Compare> sort(Compare comp); + +#include <list> +#include <functional> +#include <cassert> + +int main() +{ + int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9}; + int a2[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.sort(std::greater<int>()); + assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); +} diff --git a/libcxx/test/containers/sequences/list/list.ops/splice_pos_list.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/splice_pos_list.pass.cpp new file mode 100644 index 00000000000..9f7d299a8d0 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/splice_pos_list.pass.cpp @@ -0,0 +1,400 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void splice(const_iterator position, list& x); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {1, 2, 3}; + int a2[] = {4, 5, 6}; + { + std::list<int> l1; + std::list<int> l2; + l1.splice(l1.end(), l2); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + } + { + std::list<int> l1; + std::list<int> l2(a2, a2+1); + l1.splice(l1.end(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + } + { + std::list<int> l1; + std::list<int> l2(a2, a2+2); + l1.splice(l1.end(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list<int> l1; + std::list<int> l2(a2, a2+3); + l1.splice(l1.end(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2; + l1.splice(l1.begin(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2; + l1.splice(l1.end(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2(a2, a2+1); + l1.splice(l1.begin(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2(a2, a2+1); + l1.splice(l1.end(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2(a2, a2+2); + l1.splice(l1.begin(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2(a2, a2+2); + l1.splice(l1.end(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2(a2, a2+3); + l1.splice(l1.begin(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2(a2, a2+3); + l1.splice(l1.end(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2; + l1.splice(l1.begin(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2; + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2; + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2(a2, a2+1); + l1.splice(l1.begin(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2(a2, a2+1); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2(a2, a2+1); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2(a2, a2+2); + l1.splice(l1.begin(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2(a2, a2+2); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + std::list<int> l2(a2, a2+2); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list<int> l1(a1, a1+3); + std::list<int> l2(a2, a2+3); + l1.splice(l1.begin(), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list<int> l1(a1, a1+3); + std::list<int> l2(a2, a2+3); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list<int> l1(a1, a1+3); + std::list<int> l2(a2, a2+3); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); + } + { + std::list<int> l1(a1, a1+3); + std::list<int> l2(a2, a2+3); + l1.splice(next(l1.begin(), 3), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } +} diff --git a/libcxx/test/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp new file mode 100644 index 00000000000..429c43d3900 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp @@ -0,0 +1,177 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void splice(const_iterator position, list<T,Allocator>& x, iterator i); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {1, 2, 3}; + int a2[] = {4, 5, 6}; + { + std::list<int> l1; + std::list<int> l2(a2, a2+1); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + } + { + std::list<int> l1; + std::list<int> l2(a2, a2+2); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 1); + assert(distance(l2.begin(), l2.end()) == 1); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + i = l2.begin(); + assert(*i == 5); + } + { + std::list<int> l1; + std::list<int> l2(a2, a2+2); + l1.splice(l1.end(), l2, next(l2.begin())); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 1); + assert(distance(l2.begin(), l2.end()) == 1); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 5); + i = l2.begin(); + assert(*i == 4); + } + { + std::list<int> l1; + std::list<int> l2(a2, a2+3); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + i = l2.begin(); + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list<int> l1; + std::list<int> l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin())); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 5); + i = l2.begin(); + assert(*i == 4); + ++i; + assert(*i == 6); + } + { + std::list<int> l1; + std::list<int> l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 6); + i = l2.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list<int> l1(a1, a1+1); + l1.splice(l1.begin(), l1, l1.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2(a2, a2+1); + l1.splice(l1.begin(), l2, l2.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+1); + std::list<int> l2(a2, a2+1); + l1.splice(next(l1.begin()), l2, l2.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + } + { + std::list<int> l1(a1, a1+2); + l1.splice(l1.begin(), l1, l1.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + l1.splice(l1.begin(), l1, next(l1.begin())); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+2); + l1.splice(next(l1.begin()), l1, l1.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int> l1(a1, a1+2); + l1.splice(next(l1.begin()), l1, next(l1.begin())); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } +} diff --git a/libcxx/test/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp new file mode 100644 index 00000000000..82fa37fb75b --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp @@ -0,0 +1,117 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void splice(const_iterator position, list& x, iterator first, iterator last); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {1, 2, 3}; + int a2[] = {4, 5, 6}; + { + std::list<int> l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin())); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list<int> l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin(), 2)); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 1); + ++i; + assert(*i == 3); + } + { + std::list<int> l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin(), 3)); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 1); + } + { + std::list<int> l1(a1, a1+3); + std::list<int> l2(a2, a2+3); + l1.splice(l1.begin(), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } + { + std::list<int> l1(a1, a1+3); + std::list<int> l2(a2, a2+3); + l1.splice(next(l1.begin()), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } + { + std::list<int> l1(a1, a1+3); + std::list<int> l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list<int>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } +} diff --git a/libcxx/test/containers/sequences/list/list.ops/unique.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/unique.pass.cpp new file mode 100644 index 00000000000..9a547f19d65 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/unique.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void unique(); + +#include <list> +#include <cassert> + +int main() +{ + int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; + int a2[] = {2, 1, 4, 3}; + std::list<int> c(a1, a1+sizeof(a1)/sizeof(a1[0])); + c.unique(); + assert(c == std::list<int>(a2, a2+4)); +} diff --git a/libcxx/test/containers/sequences/list/list.ops/unique_pred.pass.cpp b/libcxx/test/containers/sequences/list/list.ops/unique_pred.pass.cpp new file mode 100644 index 00000000000..2800baa2b3a --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.ops/unique_pred.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class BinaryPred> void unique(BinaryPred pred); + +#include <list> +#include <cassert> + +bool g(int x, int y) +{ + return x == y; +} + +int main() +{ + int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; + int a2[] = {2, 1, 4, 3}; + std::list<int> c(a1, a1+sizeof(a1)/sizeof(a1[0])); + c.unique(g); + assert(c == std::list<int>(a2, a2+4)); +} diff --git a/libcxx/test/containers/sequences/list/list.special/swap.pass.cpp b/libcxx/test/containers/sequences/list/list.special/swap.pass.cpp new file mode 100644 index 00000000000..6ca9c57a997 --- /dev/null +++ b/libcxx/test/containers/sequences/list/list.special/swap.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class T, class Alloc> +// void swap(list<T,Alloc>& x, list<T,Alloc>& y); + + +#include <list> +#include <cassert> +#include "../../../test_allocator.h" + +int main() +{ + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2 == std::list<int>(a1, a1+sizeof(a1)/sizeof(a1[0]))); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list<int> c1(a1, a1); + std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int> c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2 == std::list<int>(a1, a1+sizeof(a1)/sizeof(a1[0]))); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list<int> c1(a1, a1); + std::list<int> c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef test_allocator<int> A; + std::list<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::list<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::list<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(1)); + assert((c2 == std::list<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef other_allocator<int> A; + std::list<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::list<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::list<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(2)); + assert((c2 == std::list<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(1)); + } +} diff --git a/libcxx/test/containers/sequences/list/types.pass.cpp b/libcxx/test/containers/sequences/list/types.pass.cpp new file mode 100644 index 00000000000..7834b1cff2b --- /dev/null +++ b/libcxx/test/containers/sequences/list/types.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class T, class Alloc = allocator<T> > +// class list +// { +// public: +// +// // types: +// typedef T value_type; +// typedef Alloc allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; + +#include <list> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::list<int>::value_type, int>::value), ""); + static_assert((std::is_same<std::list<int>::allocator_type, std::allocator<int> >::value), ""); + static_assert((std::is_same<std::list<int>::reference, std::allocator<int>::reference>::value), ""); + static_assert((std::is_same<std::list<int>::const_reference, std::allocator<int>::const_reference>::value), ""); + static_assert((std::is_same<std::list<int>::pointer, std::allocator<int>::pointer>::value), ""); + static_assert((std::is_same<std::list<int>::const_pointer, std::allocator<int>::const_pointer>::value), ""); +} diff --git a/libcxx/test/containers/sequences/list/version.pass.cpp b/libcxx/test/containers/sequences/list/version.pass.cpp new file mode 100644 index 00000000000..9c386f364a6 --- /dev/null +++ b/libcxx/test/containers/sequences/list/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +#include <list> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/nothing_to_do.pass.cpp b/libcxx/test/containers/sequences/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..fa4d462f18d --- /dev/null +++ b/libcxx/test/containers/sequences/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/containers/sequences/vector.bool/assign_copy.pass.cpp b/libcxx/test/containers/sequences/vector.bool/assign_copy.pass.cpp new file mode 100644 index 00000000000..149fca69f0f --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/assign_copy.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(const vector& c); + +#include <vector> +#include <cassert> +#include "../../test_allocator.h" + +int main() +{ + { + std::vector<bool, test_allocator<bool> > l(3, 2, test_allocator<bool>(5)); + std::vector<bool, test_allocator<bool> > l2(l, test_allocator<bool>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<bool>(3)); + } + { + std::vector<bool, other_allocator<bool> > l(3, 2, other_allocator<bool>(5)); + std::vector<bool, other_allocator<bool> > l2(l, other_allocator<bool>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<bool>(5)); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/assign_initializer_list.pass.cpp b/libcxx/test/containers/sequences/vector.bool/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..387b227fa88 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/assign_initializer_list.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void assign(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<int> d; + d.assign({true, false, false, true}); + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/assign_move.pass.cpp b/libcxx/test/containers/sequences/vector.bool/assign_move.pass.cpp new file mode 100644 index 00000000000..41cbc1ffa6b --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/assign_move.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(vector&& c); + +#include <vector> +#include <cassert> +#include "../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5)); + std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, test_allocator<bool> > l2(test_allocator<bool>(5)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5)); + std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, test_allocator<bool> > l2(test_allocator<bool>(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator<bool>(6)); + } + { + std::vector<bool, other_allocator<bool> > l(other_allocator<bool>(5)); + std::vector<bool, other_allocator<bool> > lo(other_allocator<bool>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, other_allocator<bool> > l2(other_allocator<bool>(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/capacity.pass.cpp b/libcxx/test/containers/sequences/vector.bool/capacity.pass.cpp new file mode 100644 index 00000000000..0263ec43727 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/capacity.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// size_type capacity() const; + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<bool> v; + assert(v.capacity() == 0); + } + { + std::vector<bool> v(100); + assert(v.capacity() >= 100); + v.push_back(0); + assert(v.capacity() >= 101); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/construct_default.pass.cpp b/libcxx/test/containers/sequences/vector.bool/construct_default.pass.cpp new file mode 100644 index 00000000000..45368c647ae --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/construct_default.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// vector(const Alloc& = Alloc()); + +#include <vector> +#include <cassert> + +#include "../../test_allocator.h" + +template <class C> +void +test0() +{ + C c; + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == typename C::allocator_type()); +} + +template <class C> +void +test1(const typename C::allocator_type& a) +{ + C c(a); + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == a); +} + +int main() +{ + { + test0<std::vector<bool> >(); + test1<std::vector<bool, test_allocator<bool> > >(test_allocator<bool>(3)); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/construct_iter_iter.pass.cpp b/libcxx/test/containers/sequences/vector.bool/construct_iter_iter.pass.cpp new file mode 100644 index 00000000000..5cc617cd074 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/construct_iter_iter.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// template <class InputIter> vector(InputIter first, InputIter last); + +#include <vector> +#include <cassert> + +#include "../../iterators.h" + +template <class C, class Iterator> +void +test(Iterator first, Iterator last) +{ + C c(first, last); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +int main() +{ + bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; + bool* an = a + sizeof(a)/sizeof(a[0]); + test<std::vector<bool> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an)); + test<std::vector<bool> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an)); + test<std::vector<bool> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an)); + test<std::vector<bool> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an)); + test<std::vector<bool> >(a, an); +} diff --git a/libcxx/test/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp b/libcxx/test/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..56d884fcc07 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// template <class InputIter> vector(InputIter first, InputIter last, +// const allocator_type& a); + +#include <vector> +#include <cassert> + +#include "../../iterators.h" + +template <class C, class Iterator> +void +test(Iterator first, Iterator last, const typename C::allocator_type& a) +{ + C c(first, last, a); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +int main() +{ + bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; + bool* an = a + sizeof(a)/sizeof(a[0]); + std::allocator<bool> alloc; + test<std::vector<bool> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an), alloc); + test<std::vector<bool> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an), alloc); + test<std::vector<bool> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an), alloc); + test<std::vector<bool> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an), alloc); + test<std::vector<bool> >(a, an, alloc); +} diff --git a/libcxx/test/containers/sequences/vector.bool/construct_size.pass.cpp b/libcxx/test/containers/sequences/vector.bool/construct_size.pass.cpp new file mode 100644 index 00000000000..f4e54007032 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/construct_size.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// explicit vector(size_type n); + +#include <vector> +#include <cassert> + +template <class C> +void +test(typename C::size_type n) +{ + C c(n); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == typename C::allocator_type()); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +} + +int main() +{ + test<std::vector<bool> >(50); +} diff --git a/libcxx/test/containers/sequences/vector.bool/construct_size_value.pass.cpp b/libcxx/test/containers/sequences/vector.bool/construct_size_value.pass.cpp new file mode 100644 index 00000000000..0411292147a --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/construct_size_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// vector(size_type n, const value_type& x); + +#include <vector> +#include <cassert> + +template <class C> +void +test(typename C::size_type n, const typename C::value_type& x) +{ + C c(n, x); + assert(c.__invariants()); + assert(c.size() == n); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test<std::vector<bool> >(50, 3); +} diff --git a/libcxx/test/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp b/libcxx/test/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp new file mode 100644 index 00000000000..9f404e90d98 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// vector(size_type n, const value_type& x, const allocator_type& a); + +#include <vector> +#include <cassert> + +template <class C> +void +test(typename C::size_type n, const typename C::value_type& x, + const typename C::allocator_type& a) +{ + C c(n, x, a); + assert(c.__invariants()); + assert(a == c.get_allocator()); + assert(c.size() == n); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test<std::vector<bool> >(50, 3, std::allocator<bool>()); +} diff --git a/libcxx/test/containers/sequences/vector.bool/copy.pass.cpp b/libcxx/test/containers/sequences/vector.bool/copy.pass.cpp new file mode 100644 index 00000000000..41de81871c4 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/copy.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// vector(const vector& v); + +#include <vector> +#include <cassert> +#include "../../test_allocator.h" + +template <class C> +void +test(const C& x) +{ + unsigned s = x.size(); + C c(x); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); +} + +int main() +{ + { + bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; + bool* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector<bool>(a, an)); + } + { + std::vector<bool, test_allocator<bool> > v(3, 2, test_allocator<bool>(5)); + std::vector<bool, test_allocator<bool> > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::vector<bool, other_allocator<bool> > v(3, 2, other_allocator<bool>(5)); + std::vector<bool, other_allocator<bool> > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == other_allocator<bool>(-2)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/copy_alloc.pass.cpp b/libcxx/test/containers/sequences/vector.bool/copy_alloc.pass.cpp new file mode 100644 index 00000000000..8134c67d5b9 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/copy_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(const vector& v, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "../../test_allocator.h" + +template <class C> +void +test(const C& x, const typename C::allocator_type& a) +{ + unsigned s = x.size(); + C c(x, a); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); +} + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector<bool>(a, an), std::allocator<bool>()); + } + { + std::vector<bool, test_allocator<bool> > l(3, 2, test_allocator<bool>(5)); + std::vector<bool, test_allocator<bool> > l2(l, test_allocator<bool>(3)); + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<bool>(3)); + } + { + std::vector<bool, other_allocator<bool> > l(3, 2, other_allocator<bool>(5)); + std::vector<bool, other_allocator<bool> > l2(l, other_allocator<bool>(3)); + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<bool>(3)); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/erase_iter.pass.cpp b/libcxx/test/containers/sequences/vector.bool/erase_iter.pass.cpp new file mode 100644 index 00000000000..700d567ce28 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/erase_iter.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// iterator erase(const_iterator position); + +#include <vector> +#include <cassert> + +int main() +{ + bool a1[] = {1, 0, 1}; + std::vector<bool> l1(a1, a1+3); + std::vector<bool>::const_iterator i = l1.begin(); + ++i; + std::vector<bool>::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == true); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == true); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == true); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); +} diff --git a/libcxx/test/containers/sequences/vector.bool/erase_iter_iter.pass.cpp b/libcxx/test/containers/sequences/vector.bool/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..0f82b431655 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/erase_iter_iter.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// iterator erase(const_iterator first, const_iterator last); + +#include <vector> +#include <cassert> + +int main() +{ + bool a1[] = {1, 0, 1}; + { + std::vector<bool> l1(a1, a1+3); + std::vector<bool>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + } + { + std::vector<bool> l1(a1, a1+3); + std::vector<bool>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert(l1 == std::vector<bool>(a1+1, a1+3)); + } + { + std::vector<bool> l1(a1, a1+3); + std::vector<bool>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert(l1 == std::vector<bool>(a1+2, a1+3)); + } + { + std::vector<bool> l1(a1, a1+3); + std::vector<bool>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/initializer_list.pass.cpp b/libcxx/test/containers/sequences/vector.bool/initializer_list.pass.cpp new file mode 100644 index 00000000000..c7c29ac342c --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/initializer_list.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<int> d = {true, false, false, true}; + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp b/libcxx/test/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..34edd55dedc --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <vector> +#include <cassert> + +#include "../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<int, test_allocator<int>> d({true, false, false, true}, test_allocator<int>(3)); + assert(d.get_allocator() == test_allocator<int>(3)); + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp b/libcxx/test/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..ab85aaf6bb8 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<bool> d(10, true); + std::vector<bool>::iterator i = d.insert(d.cbegin() + 2, {false, true, true, false}); + assert(d.size() == 14); + assert(i == d.begin() + 2); + assert(d[0] == true); + assert(d[1] == true); + assert(d[2] == false); + assert(d[3] == true); + assert(d[4] == true); + assert(d[5] == false); + assert(d[6] == true); + assert(d[7] == true); + assert(d[8] == true); + assert(d[9] == true); + assert(d[10] == true); + assert(d[11] == true); + assert(d[12] == true); + assert(d[13] == true); +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp b/libcxx/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..9b275a9b47b --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// template <class Iter> +// iterator insert(const_iterator position, Iter first, Iter last); + +#include <vector> +#include <cassert> +#include "../../iterators.h" + +int main() +{ + { + std::vector<bool> v(100); + bool a[] = {1, 0, 0, 1, 1}; + const bool N = sizeof(a)/sizeof(a[0]); + std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const bool*>(a), + input_iterator<const bool*>(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<bool> v(100); + bool a[] = {1, 0, 0, 1, 1}; + const bool N = sizeof(a)/sizeof(a[0]); + std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const bool*>(a), + forward_iterator<const bool*>(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp b/libcxx/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..47f55d222e9 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<bool> v(100); + std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp b/libcxx/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..6ab35a3694c --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/insert_iter_value.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// iterator insert(const_iterator position, const value_type& x); + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<bool> v(100); + std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/move.pass.cpp b/libcxx/test/containers/sequences/vector.bool/move.pass.cpp new file mode 100644 index 00000000000..f1d4ce3f87b --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/move.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&& c); + +#include <vector> +#include <cassert> +#include "../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5)); + std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, test_allocator<bool> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::vector<bool, other_allocator<bool> > l(other_allocator<bool>(5)); + std::vector<bool, other_allocator<bool> > lo(other_allocator<bool>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, other_allocator<bool> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/move_alloc.pass.cpp b/libcxx/test/containers/sequences/vector.bool/move_alloc.pass.cpp new file mode 100644 index 00000000000..d07102f031d --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/move_alloc.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&& c, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5)); + std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, test_allocator<bool> > l2(std::move(l), test_allocator<bool>(6)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator<bool>(6)); + } + { + std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5)); + std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, test_allocator<bool> > l2(std::move(l), test_allocator<bool>(5)); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == test_allocator<bool>(5)); + } + { + std::vector<bool, other_allocator<bool> > l(other_allocator<bool>(5)); + std::vector<bool, other_allocator<bool> > lo(other_allocator<bool>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, other_allocator<bool> > l2(std::move(l), other_allocator<bool>(4)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == other_allocator<bool>(4)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp b/libcxx/test/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..bd9e1945375 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<bool> d; + d = {true, false, false, true}; + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); +#endif +} diff --git a/libcxx/test/containers/sequences/vector.bool/push_back.pass.cpp b/libcxx/test/containers/sequences/vector.bool/push_back.pass.cpp new file mode 100644 index 00000000000..af8199bb79e --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/push_back.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void push_back(const value_type& x); + +#include <vector> +#include <cassert> + +int main() +{ + { + bool a[] = {0, 1, 1, 0, 1, 0, 0}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector<int> c; + for (unsigned i = 0; i < N; ++i) + { + c.push_back(a[i]); + assert(c.size() == i+1); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == a[j]); + } + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/reserve.pass.cpp b/libcxx/test/containers/sequences/vector.bool/reserve.pass.cpp new file mode 100644 index 00000000000..576198073ee --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/reserve.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void reserve(size_type n); + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<bool> v; + v.reserve(10); + assert(v.capacity() >= 10); + } + { + std::vector<bool> v(100); + assert(v.capacity() >= 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() >= 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() >= 150); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/resize_size.pass.cpp b/libcxx/test/containers/sequences/vector.bool/resize_size.pass.cpp new file mode 100644 index 00000000000..3d573d11135 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/resize_size.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void resize(size_type sz); + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<bool> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() >= 100); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/resize_size_value.pass.cpp b/libcxx/test/containers/sequences/vector.bool/resize_size_value.pass.cpp new file mode 100644 index 00000000000..ccf06c0c5ac --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/resize_size_value.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void resize(size_type sz, const value_type& x); + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<bool> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() >= 100); + assert(v == std::vector<bool>(50)); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + for (unsigned i = 0; i < 50; ++i) + assert(v[i] == 0); + for (unsigned i = 50; i < 200; ++i) + assert(v[i] == 1); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/shrink_to_fit.pass.cpp b/libcxx/test/containers/sequences/vector.bool/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..8e609fb4051 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/shrink_to_fit.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void shrink_to_fit(); + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<bool> v(100); + v.push_back(1); + v.shrink_to_fit(); + assert(v.capacity() >= 101); + assert(v.size() >= 101); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/swap.pass.cpp b/libcxx/test/containers/sequences/vector.bool/swap.pass.cpp new file mode 100644 index 00000000000..31708314cbf --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/swap.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void swap(vector& x); + +#include <vector> +#include <cassert> +#include "../../test_allocator.h" + +int main() +{ + { + std::vector<bool> v1(100); + std::vector<bool> v2(200); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + } + { + typedef test_allocator<bool> A; + std::vector<bool, A> v1(100, true, A(1)); + std::vector<bool, A> v2(200, false, A(2)); + swap(v1, v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + assert(v1.get_allocator() == A(1)); + assert(v2.get_allocator() == A(2)); + } + { + typedef other_allocator<bool> A; + std::vector<bool, A> v1(100, true, A(1)); + std::vector<bool, A> v2(200, false, A(2)); + swap(v1, v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + assert(v1.get_allocator() == A(2)); + assert(v2.get_allocator() == A(1)); + } +} diff --git a/libcxx/test/containers/sequences/vector.bool/types.pass.cpp b/libcxx/test/containers/sequences/vector.bool/types.pass.cpp new file mode 100644 index 00000000000..1713740c659 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/types.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Test nested types and default template args: + +// template <class Allocator> +// class vector<bool, Allocator +// { +// public: +// typedef T value_type; +// typedef Allocator allocator_type; +// typedef implementation-defined iterator; +// typedef implementation-defined const_iterator; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef std::reverse_iterator<iterator> reverse_iterator; +// typedef std::reverse_iterator<const_iterator> const_reverse_iterator; +// }; + +#include <vector> +#include <iterator> +#include <type_traits> + +#include "../../test_allocator.h" +#include "../../Copyable.h" + +template <class Allocator> +void +test() +{ + typedef std::vector<bool, Allocator> C; + + static_assert((std::is_same<typename C::value_type, bool>::value), ""); + static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), ""); + static_assert((std::is_same<typename C::allocator_type, Allocator>::value), ""); + static_assert((std::is_same<typename C::size_type, typename Allocator::size_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename C::iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename C::const_iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename C::reverse_iterator, + std::reverse_iterator<typename C::iterator> >::value), ""); + static_assert((std::is_same< + typename C::const_reverse_iterator, + std::reverse_iterator<typename C::const_iterator> >::value), ""); +} + +int main() +{ + test<test_allocator<bool> >(); + test<std::allocator<bool> >(); + static_assert((std::is_same<std::vector<bool>::allocator_type, + std::allocator<bool> >::value), ""); +} diff --git a/libcxx/test/containers/sequences/vector.bool/vector_bool.pass.cpp b/libcxx/test/containers/sequences/vector.bool/vector_bool.pass.cpp new file mode 100644 index 00000000000..03df8e0f7d4 --- /dev/null +++ b/libcxx/test/containers/sequences/vector.bool/vector_bool.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <functional> + +// template <class T> +// struct hash +// : public unary_function<T, size_t> +// { +// size_t operator()(T val) const; +// }; + +// Not very portable + +#include <vector> +#include <cassert> +#include <type_traits> + +int main() +{ + typedef std::vector<bool> T; + typedef std::hash<T> H; + static_assert((std::is_base_of<std::unary_function<T, std::size_t>, + H>::value), ""); + bool ba[] = {true, false, true, true, false}; + T vb(std::begin(ba), std::end(ba)); + H h; + assert(h(vb) != 0); +} diff --git a/libcxx/test/containers/sequences/vector/types.pass.cpp b/libcxx/test/containers/sequences/vector/types.pass.cpp new file mode 100644 index 00000000000..f7f2503aa94 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/types.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Test nested types and default template args: + +// template <class T, class Allocator = allocator<T> > +// class vector +// { +// public: +// typedef T value_type; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef implementation-defined iterator; +// typedef implementation-defined const_iterator; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef std::reverse_iterator<iterator> reverse_iterator; +// typedef std::reverse_iterator<const_iterator> const_reverse_iterator; +// }; + +#include <vector> +#include <iterator> +#include <type_traits> + +#include "../../test_allocator.h" +#include "../../Copyable.h" + +template <class T, class Allocator> +void +test() +{ + typedef std::vector<T, Allocator> C; + + static_assert((std::is_same<typename C::value_type, T>::value), ""); + static_assert((std::is_same<typename C::value_type, typename Allocator::value_type>::value), ""); + static_assert((std::is_same<typename C::allocator_type, Allocator>::value), ""); + static_assert((std::is_same<typename C::size_type, typename Allocator::size_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, typename Allocator::difference_type>::value), ""); + static_assert((std::is_same<typename C::reference, typename Allocator::reference>::value), ""); + static_assert((std::is_same<typename C::const_reference, typename Allocator::const_reference>::value), ""); + static_assert((std::is_same<typename C::pointer, typename Allocator::pointer>::value), ""); + static_assert((std::is_same<typename C::const_pointer, typename Allocator::const_pointer>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename C::iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename C::const_iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename C::reverse_iterator, + std::reverse_iterator<typename C::iterator> >::value), ""); + static_assert((std::is_same< + typename C::const_reverse_iterator, + std::reverse_iterator<typename C::const_iterator> >::value), ""); +} + +int main() +{ + test<int, test_allocator<int> >(); + test<int*, std::allocator<int*> >(); + test<Copyable, test_allocator<Copyable> >(); + static_assert((std::is_same<std::vector<char>::allocator_type, + std::allocator<char> >::value), ""); +} diff --git a/libcxx/test/containers/sequences/vector/vector.capacity/capacity.pass.cpp b/libcxx/test/containers/sequences/vector/vector.capacity/capacity.pass.cpp new file mode 100644 index 00000000000..d8c2f363350 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.capacity/capacity.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// size_type capacity() const; + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<int> v; + assert(v.capacity() == 0); + } + { + std::vector<int> v(100); + assert(v.capacity() == 100); + v.push_back(0); + assert(v.capacity() > 101); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.capacity/reserve.pass.cpp b/libcxx/test/containers/sequences/vector/vector.capacity/reserve.pass.cpp new file mode 100644 index 00000000000..e57dc8491cf --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.capacity/reserve.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void reserve(size_type n); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +int main() +{ + { + std::vector<int> v; + v.reserve(10); + assert(v.capacity() >= 10); + } + { + std::vector<int> v(100); + assert(v.capacity() == 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() == 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() == 150); + } + { + std::vector<int, stack_allocator<int, 250> > v(100); + assert(v.capacity() == 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() == 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() == 150); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.capacity/resize_size.pass.cpp b/libcxx/test/containers/sequences/vector/vector.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..07ad1285245 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.capacity/resize_size.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void resize(size_type sz); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<MoveOnly> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + } + { + std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + } +#else + { + std::vector<int> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp b/libcxx/test/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..9c5d818227a --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void resize(size_type sz, const value_type& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +int main() +{ + { + std::vector<int> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(v == std::vector<int>(50)); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + for (unsigned i = 0; i < 50; ++i) + assert(v[i] == 0); + for (unsigned i = 50; i < 200; ++i) + assert(v[i] == 1); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp b/libcxx/test/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..e0dd07fe5b5 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void shrink_to_fit(); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +int main() +{ + { + std::vector<int> v(100); + v.push_back(1); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + } + { + std::vector<int, stack_allocator<int, 401> > v(100); + v.push_back(1); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + } + { + std::vector<int, stack_allocator<int, 400> > v(100); + v.push_back(1); + v.shrink_to_fit(); + assert(v.capacity() == 200); + assert(v.size() == 101); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.capacity/swap.pass.cpp b/libcxx/test/containers/sequences/vector/vector.capacity/swap.pass.cpp new file mode 100644 index 00000000000..a4677966d5a --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.capacity/swap.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void swap(vector& x); + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<int> v1(100); + std::vector<int> v2(200); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() == 200); + assert(v2.size() == 100); + assert(v2.capacity() == 100); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/assign_copy.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..7a41e7e5f70 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/assign_copy.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(const vector& c); + +#include <vector> +#include <cassert> +#include "../../../test_allocator.h" + +int main() +{ + { + std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5)); + std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<int>(3)); + } + { + std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5)); + std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<int>(5)); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..75d11f4b111 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void assign(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<int> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/assign_move.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..2a22c2b7536 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/assign_move.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(vector&& c); + +#include <vector> +#include <cassert> +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(5)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<MoveOnly, test_allocator<MoveOnly> > l2(test_allocator<MoveOnly>(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<MoveOnly, other_allocator<MoveOnly> > l2(other_allocator<MoveOnly>(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/construct_default.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/construct_default.pass.cpp new file mode 100644 index 00000000000..a2bdbff6c29 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/construct_default.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(const Alloc& = Alloc()); + +#include <vector> +#include <cassert> + +#include "../../../test_allocator.h" +#include "../../../NotConstructible.h" +#include "../../../stack_allocator.h" + +template <class C> +void +test0() +{ + C c; + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == typename C::allocator_type()); +} + +template <class C> +void +test1(const typename C::allocator_type& a) +{ + C c(a); + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == a); +} + +int main() +{ + { + test0<std::vector<int> >(); + test0<std::vector<NotConstructible> >(); + test1<std::vector<int, test_allocator<int> > >(test_allocator<int>(3)); + test1<std::vector<NotConstructible, test_allocator<NotConstructible> > > + (test_allocator<NotConstructible>(5)); + } + { + std::vector<int, stack_allocator<int, 10> > v; + assert(v.empty()); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp new file mode 100644 index 00000000000..305b48442fa --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class InputIter> vector(InputIter first, InputIter last); + +#include <vector> +#include <cassert> + +#include "../../../iterators.h" +#include "../../../stack_allocator.h" + +template <class C, class Iterator> +void +test(Iterator first, Iterator last) +{ + C c(first, last); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +int main() +{ + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an)); + test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an)); + test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an)); + test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an)); + test<std::vector<int> >(a, an); + + test<std::vector<int, stack_allocator<int, 63> > >(input_iterator<const int*>(a), input_iterator<const int*>(an)); + test<std::vector<int, stack_allocator<int, 18> > >(forward_iterator<const int*>(a), forward_iterator<const int*>(an)); + test<std::vector<int, stack_allocator<int, 18> > >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an)); + test<std::vector<int, stack_allocator<int, 18> > >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an)); + test<std::vector<int, stack_allocator<int, 18> > >(a, an); +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..eea5103ffe3 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class InputIter> vector(InputIter first, InputIter last, +// const allocator_type& a); + +#include <vector> +#include <cassert> + +#include "../../../iterators.h" +#include "../../../stack_allocator.h" + +template <class C, class Iterator> +void +test(Iterator first, Iterator last, const typename C::allocator_type& a) +{ + C c(first, last, a); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +int main() +{ + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + std::allocator<int> alloc; + test<std::vector<int> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); + test<std::vector<int> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); + test<std::vector<int> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); + test<std::vector<int> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); + test<std::vector<int> >(a, an, alloc); +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp new file mode 100644 index 00000000000..3ebdc07fa73 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/construct_size.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// explicit vector(size_type n); + +#include <vector> +#include <cassert> + +#include "../../../DefaultOnly.h" + +template <class C> +void +test(typename C::size_type n) +{ + C c(n); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == typename C::allocator_type()); +#ifdef _LIBCPP_MOVE + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif +} + +int main() +{ + test<std::vector<int> >(50); + test<std::vector<DefaultOnly> >(500); + assert(DefaultOnly::count == 0); +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp new file mode 100644 index 00000000000..0755b59c9b2 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(size_type n, const value_type& x); + +#include <vector> +#include <cassert> + +#include "../../../stack_allocator.h" + +template <class C> +void +test(typename C::size_type n, const typename C::value_type& x) +{ + C c(n, x); + assert(c.__invariants()); + assert(c.size() == n); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test<std::vector<int> >(50, 3); + test<std::vector<int, stack_allocator<int, 50> > >(50, 5); +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp new file mode 100644 index 00000000000..b9a6477d478 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(size_type n, const value_type& x, const allocator_type& a); + +#include <vector> +#include <cassert> + +template <class C> +void +test(typename C::size_type n, const typename C::value_type& x, + const typename C::allocator_type& a) +{ + C c(n, x, a); + assert(c.__invariants()); + assert(a == c.get_allocator()); + assert(c.size() == n); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test<std::vector<int> >(50, 3, std::allocator<int>()); +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/copy.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/copy.pass.cpp new file mode 100644 index 00000000000..04c6efc19f7 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/copy.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(const vector& v); + +#include <vector> +#include <cassert> +#include "../../../test_allocator.h" + +template <class C> +void +test(const C& x) +{ + unsigned s = x.size(); + C c(x); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); +} + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector<int>(a, an)); + } + { + std::vector<int, test_allocator<int> > v(3, 2, test_allocator<int>(5)); + std::vector<int, test_allocator<int> > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::vector<int, other_allocator<int> > v(3, 2, other_allocator<int>(5)); + std::vector<int, other_allocator<int> > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == other_allocator<int>(-2)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..74d179b8403 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(const vector& v, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "../../../test_allocator.h" + +template <class C> +void +test(const C& x, const typename C::allocator_type& a) +{ + unsigned s = x.size(); + C c(x, a); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); +} + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector<int>(a, an), std::allocator<int>()); + } + { + std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5)); + std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3)); + assert(l2 == l); + assert(l2.get_allocator() == test_allocator<int>(3)); + } + { + std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5)); + std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3)); + assert(l2 == l); + assert(l2.get_allocator() == other_allocator<int>(3)); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/initializer_list.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..4ad07ca3002 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/initializer_list.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<int> d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..77b1103ace4 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <vector> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<int, test_allocator<int>> d({3, 4, 5, 6}, test_allocator<int>(3)); + assert(d.get_allocator() == test_allocator<int>(3)); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/move.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/move.pass.cpp new file mode 100644 index 00000000000..cc313df44d5 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/move.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&& c); + +#include <vector> +#include <cassert> +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/move_alloc.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..7218ce91d5a --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/move_alloc.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&& c, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "../../../MoveOnly.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(6)); + } + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5)); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == test_allocator<MoveOnly>(5)); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<MoveOnly, other_allocator<MoveOnly> > l2(std::move(l), other_allocator<MoveOnly>(4)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == other_allocator<MoveOnly>(4)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..72ac2d318bf --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<int> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.data/data.pass.cpp b/libcxx/test/containers/sequences/vector/vector.data/data.pass.cpp new file mode 100644 index 00000000000..e24be722d0e --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.data/data.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// pointer data(); + +#include <vector> +#include <cassert> + +int main() +{ + { + std::vector<int> v; + assert(v.data() == 0); + } + { + std::vector<int> v(100); + assert(v.data() == &v.front()); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.data/data_const.pass.cpp b/libcxx/test/containers/sequences/vector/vector.data/data_const.pass.cpp new file mode 100644 index 00000000000..1de53c05884 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.data/data_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// const_pointer data() const; + +#include <vector> +#include <cassert> + +int main() +{ + { + const std::vector<int> v; + assert(v.data() == 0); + } + { + const std::vector<int> v(100); + assert(v.data() == &v.front()); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/emplace.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..762b16d5db1 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/emplace.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class... Args> iterator emplace(const_iterator pos, Args&&... args); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +#ifdef _LIBCPP_MOVE + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + A(A&& a) + : i_(a.i_), + d_(a.d_) + { + a.i_ = 0; + a.d_ = 0; + } + + A& operator=(A&& a) + { + i_ = a.i_; + d_ = a.d_; + a.i_ = 0; + a.d_ = 0; + return *this; + } + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<A> c; + std::vector<A>::iterator i = c.emplace(c.cbegin(), 2, 3.5); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + i = c.emplace(c.cend(), 3, 4.5); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + i = c.emplace(c.cbegin()+1, 4, 6.5); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c[1].geti() == 4); + assert(c[1].getd() == 6.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } + { + std::vector<A, stack_allocator<A, 7> > c; + std::vector<A, stack_allocator<A, 7> >::iterator i = c.emplace(c.cbegin(), 2, 3.5); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + i = c.emplace(c.cend(), 3, 4.5); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + i = c.emplace(c.cbegin()+1, 4, 6.5); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c[1].geti() == 4); + assert(c[1].getd() == 6.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..86b28a1093a --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class... Args> void emplace_back(Args&&... args); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +#ifdef _LIBCPP_MOVE + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + A(A&& a) + : i_(a.i_), + d_(a.d_) + { + a.i_ = 0; + a.d_ = 0; + } + + A& operator=(A&& a) + { + i_ = a.i_; + d_ = a.d_; + a.i_ = 0; + a.d_ = 0; + return *this; + } + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +#endif + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<A> c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } + { + std::vector<A, stack_allocator<A, 4> > c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..1cfa63f6673 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator erase(const_iterator position); + +#include <vector> +#include <cassert> + +int main() +{ + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int>::const_iterator i = l1.begin(); + ++i; + std::vector<int>::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == 3); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == 3); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..edfcdac963b --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator erase(const_iterator first, const_iterator last); + +#include <vector> +#include <cassert> + +int main() +{ + int a1[] = {1, 2, 3}; + { + std::vector<int> l1(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + } + { + std::vector<int> l1(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert(l1 == std::vector<int>(a1+1, a1+3)); + } + { + std::vector<int> l1(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert(l1 == std::vector<int>(a1+2, a1+3)); + } + { + std::vector<int> l1(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..58e397f5bc5 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + std::vector<int> d(10, 1); + std::vector<int>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(i == d.begin() + 2); + assert(d[0] == 1); + assert(d[1] == 1); + assert(d[2] == 3); + assert(d[3] == 4); + assert(d[4] == 5); + assert(d[5] == 6); + assert(d[6] == 1); + assert(d[7] == 1); + assert(d[8] == 1); + assert(d[9] == 1); + assert(d[10] == 1); + assert(d[11] == 1); + assert(d[12] == 1); + assert(d[13] == 1); +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..59fb546a511 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class Iter> +// iterator insert(const_iterator position, Iter first, Iter last); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "../../../iterators.h" + +int main() +{ + { + std::vector<int> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), + forward_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int, stack_allocator<int, 308> > v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a), + forward_iterator<const int*>(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp new file mode 100644 index 00000000000..6262f751ebb --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator position, value_type&& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<MoveOnly> v(100); + std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == MoveOnly()); + assert(v[j] == MoveOnly(3)); + for (++j; j < 101; ++j) + assert(v[j] == MoveOnly()); + } + { + std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100); + std::vector<MoveOnly, stack_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == MoveOnly()); + assert(v[j] == MoveOnly(3)); + for (++j; j < 101; ++j) + assert(v[j] == MoveOnly()); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..1312caffc06 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +int main() +{ + { + std::vector<int> v(100); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..2d6ee2ce5c5 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator position, const value_type& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +int main() +{ + { + std::vector<int> v(100); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/push_back.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..22197e5e086 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/push_back.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void push_back(const value_type& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" + +int main() +{ + { + std::vector<int> c; + c.push_back(0); + assert(c.size() == 1); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } + { + std::vector<int, stack_allocator<int, 15> > c; + c.push_back(0); + assert(c.size() == 1); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } +} diff --git a/libcxx/test/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..69b61e52fdc --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void push_back(value_type&& x); + +#include <vector> +#include <cassert> +#include "../../../MoveOnly.h" +#include "../../../stack_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + std::vector<MoveOnly> c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } + { + std::vector<MoveOnly, stack_allocator<MoveOnly, 15> > c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } +#endif +} diff --git a/libcxx/test/containers/sequences/vector/vector.special/swap.pass.cpp b/libcxx/test/containers/sequences/vector/vector.special/swap.pass.cpp new file mode 100644 index 00000000000..b1d489c12f4 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/vector.special/swap.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class T, class Alloc> +// void swap(vector<T,Alloc>& x, vector<T,Alloc>& y); + + +#include <vector> +#include <cassert> +#include "../../../test_allocator.h" + +int main() +{ + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert(c1 == std::vector<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2 == std::vector<int>(a1, a1+sizeof(a1)/sizeof(a1[0]))); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1); + std::vector<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert(c1 == std::vector<int>(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int> c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2 == std::vector<int>(a1, a1+sizeof(a1)/sizeof(a1[0]))); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int> c1(a1, a1); + std::vector<int> c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef test_allocator<int> A; + std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(1)); + assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef other_allocator<int> A; + std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(2)); + assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(1)); + } +} diff --git a/libcxx/test/containers/sequences/vector/version.pass.cpp b/libcxx/test/containers/sequences/vector/version.pass.cpp new file mode 100644 index 00000000000..370033777a0 --- /dev/null +++ b/libcxx/test/containers/sequences/vector/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +#include <vector> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |