diff options
Diffstat (limited to 'libcxx/test/std/containers/sequences')
337 files changed, 24483 insertions, 0 deletions
diff --git a/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp new file mode 100644 index 00000000000..7bc62b759c3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/array/array.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..b9775eef067 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/array/array.data/data.pass.cpp b/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp new file mode 100644 index 00000000000..08e4fd39d37 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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(); + (void)p; // to placate scan-build + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp new file mode 100644 index 00000000000..8eb9762dcb8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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(); + (void)p; // to placate scan-build + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp b/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp new file mode 100644 index 00000000000..675f4950062 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/array/array.size/size.pass.cpp b/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp new file mode 100644 index 00000000000..fe5a0d5c8db --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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); + assert(c.max_size() == 3); + assert(!c.empty()); + } + { + typedef double T; + typedef std::array<T, 0> C; + C c = {}; + assert(c.size() == 0); + assert(c.max_size() == 0); + assert(c.empty()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef double T; + typedef std::array<T, 3> C; + constexpr C c = {1, 2, 3.5}; + static_assert(c.size() == 3, ""); + static_assert(c.max_size() == 3, ""); + static_assert(!c.empty(), ""); + } + { + typedef double T; + typedef std::array<T, 0> C; + constexpr C c = {}; + static_assert(c.size() == 0, ""); + static_assert(c.max_size() == 0, ""); + static_assert(c.empty(), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp new file mode 100644 index 00000000000..08e437739ee --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/array/array.swap/swap.pass.cpp b/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp new file mode 100644 index 00000000000..c7a4cb8df38 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/array/array.tuple/get.fail.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp new file mode 100644 index 00000000000..4f4fbcf93af --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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<3>(c) = 5.5; // Can't get element 3! + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp new file mode 100644 index 00000000000..d9e242cd420 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <size_t I, class T, size_t N> T& get(array<T, N>& a); + +#include <array> +#include <cassert> + +#if __cplusplus > 201103L +struct S { + std::array<int, 3> a; + int k; + constexpr S() : a{1,2,3}, k(std::get<2>(a)) {} + }; + +constexpr std::array<int, 2> getArr () { return { 3, 4 }; } +#endif + +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); + } +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array<T, 3> C; + constexpr C c = {1, 2, 3.5}; + static_assert(std::get<0>(c) == 1, ""); + static_assert(std::get<1>(c) == 2, ""); + static_assert(std::get<2>(c) == 3.5, ""); + } + { + static_assert(S().k == 3, ""); + static_assert(std::get<1>(getArr()) == 4, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp new file mode 100644 index 00000000000..1cbdfa4ff39 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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); + } +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array<T, 3> C; + constexpr const C c = {1, 2, 3.5}; + static_assert(std::get<0>(c) == 1, ""); + static_assert(std::get<1>(c) == 2, ""); + static_assert(std::get<2>(c) == 3.5, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp new file mode 100644 index 00000000000..869c1ec9c2d --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// template <size_t I, class T, size_t N> T&& get(array<T, N>&& a); + +#include <array> +#include <memory> +#include <cassert> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unique_ptr<double> T; + typedef std::array<T, 1> C; + C c = {std::unique_ptr<double>(new double(3.5))}; + T t = std::get<0>(std::move(c)); + assert(*t == 3.5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp new file mode 100644 index 00000000000..cd1dad60ade --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp new file mode 100644 index 00000000000..83394b1e0c9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp b/libcxx/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp new file mode 100644 index 00000000000..0aa2f50d8b4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// support for zero-sized array + +#include <array> + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/array/at.pass.cpp b/libcxx/test/std/containers/sequences/array/at.pass.cpp new file mode 100644 index 00000000000..b5cf8a5aaa8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/at.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// reference operator[] (size_type) +// const_reference operator[] (size_type); // constexpr in C++14 +// reference at (size_type) +// const_reference at (size_type); // constexpr in C++14 + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + C::reference r1 = c.at(0); + assert(r1 == 1); + r1 = 5.5; + assert(c.front() == 5.5); + + C::reference r2 = c.at(2); + assert(r2 == 3.5); + r2 = 7.5; + assert(c.back() == 7.5); + + try { (void) c.at(3); } + catch (const std::out_of_range &) {} + } + { + typedef double T; + typedef std::array<T, 3> C; + const C c = {1, 2, 3.5}; + C::const_reference r1 = c.at(0); + assert(r1 == 1); + + C::const_reference r2 = c.at(2); + assert(r2 == 3.5); + + try { (void) c.at(3); } + catch (const std::out_of_range &) {} + } + +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array<T, 3> C; + constexpr C c = {1, 2, 3.5}; + + constexpr T t1 = c.at(0); + static_assert (t1 == 1, ""); + + constexpr T t2 = c.at(2); + static_assert (t2 == 3.5, ""); + } +#endif + +} diff --git a/libcxx/test/std/containers/sequences/array/begin.pass.cpp b/libcxx/test/std/containers/sequences/array/begin.pass.cpp new file mode 100644 index 00000000000..9cba0d6fceb --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/begin.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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; + i = c.begin(); + assert(*i == 1); + assert(&*i == c.data()); + *i = 5.5; + assert(c[0] == 5.5); + } + { + } +} diff --git a/libcxx/test/std/containers/sequences/array/front_back.pass.cpp b/libcxx/test/std/containers/sequences/array/front_back.pass.cpp new file mode 100644 index 00000000000..45a963b9947 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/front_back.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// reference front(); +// reference back(); +// const_reference front(); // constexpr in C++14 +// const_reference back(); // constexpr in C++14 + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + + C::reference r1 = c.front(); + assert(r1 == 1); + r1 = 5.5; + assert(c[0] == 5.5); + + C::reference r2 = c.back(); + assert(r2 == 3.5); + r2 = 7.5; + assert(c[2] == 7.5); + } + { + typedef double T; + typedef std::array<T, 3> C; + const C c = {1, 2, 3.5}; + C::const_reference r1 = c.front(); + assert(r1 == 1); + + C::const_reference r2 = c.back(); + assert(r2 == 3.5); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array<T, 3> C; + constexpr C c = {1, 2, 3.5}; + + constexpr T t1 = c.front(); + static_assert (t1 == 1, ""); + + constexpr T t2 = c.back(); + static_assert (t2 == 3.5, ""); + } +#endif + +} diff --git a/libcxx/test/std/containers/sequences/array/indexing.pass.cpp b/libcxx/test/std/containers/sequences/array/indexing.pass.cpp new file mode 100644 index 00000000000..e4dda0dc5cf --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/indexing.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// reference operator[] (size_type) +// const_reference operator[] (size_type); // constexpr in C++14 +// reference at (size_type) +// const_reference at (size_type); // constexpr in C++14 + +#include <array> +#include <cassert> + +int main() +{ + { + typedef double T; + typedef std::array<T, 3> C; + C c = {1, 2, 3.5}; + C::reference r1 = c[0]; + assert(r1 == 1); + r1 = 5.5; + assert(c.front() == 5.5); + + C::reference r2 = c[2]; + assert(r2 == 3.5); + r2 = 7.5; + assert(c.back() == 7.5); + } + { + typedef double T; + typedef std::array<T, 3> C; + const C c = {1, 2, 3.5}; + C::const_reference r1 = c[0]; + assert(r1 == 1); + C::const_reference r2 = c[2]; + assert(r2 == 3.5); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array<T, 3> C; + constexpr C c = {1, 2, 3.5}; + + constexpr T t1 = c[0]; + static_assert (t1 == 1, ""); + + constexpr T t2 = c[2]; + static_assert (t2 == 3.5, ""); + } +#endif + +} diff --git a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp new file mode 100644 index 00000000000..98997d8c26d --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +// iterator, const_iterator + +#include <array> +#include <iterator> +#include <cassert> + +int main() +{ + { + typedef std::array<int, 5> C; + C c; + C::iterator i; + i = c.begin(); + C::const_iterator j; + j = c.cbegin(); + assert(i == j); + } + { + typedef std::array<int, 0> C; + C c; + C::iterator i; + i = c.begin(); + C::const_iterator j; + j = c.cbegin(); + assert(i == j); + } + +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + { + typedef std::array<int, 5> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + assert ( ii1 == cii ); + + assert ( !(ii1 != ii2 )); + assert ( !(ii1 != cii )); + + C c; + assert ( c.begin() == std::begin(c)); + assert ( c.cbegin() == std::cbegin(c)); + assert ( c.rbegin() == std::rbegin(c)); + assert ( c.crbegin() == std::crbegin(c)); + assert ( c.end() == std::end(c)); + assert ( c.cend() == std::cend(c)); + assert ( c.rend() == std::rend(c)); + assert ( c.crend() == std::crend(c)); + + assert ( std::begin(c) != std::end(c)); + assert ( std::rbegin(c) != std::rend(c)); + assert ( std::cbegin(c) != std::cend(c)); + assert ( std::crbegin(c) != std::crend(c)); + } + { + typedef std::array<int, 0> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + + C c; + assert ( c.begin() == std::begin(c)); + assert ( c.cbegin() == std::cbegin(c)); + assert ( c.rbegin() == std::rbegin(c)); + assert ( c.crbegin() == std::crbegin(c)); + assert ( c.end() == std::end(c)); + assert ( c.cend() == std::cend(c)); + assert ( c.rend() == std::rend(c)); + assert ( c.crend() == std::crend(c)); + + assert ( std::begin(c) == std::end(c)); + assert ( std::rbegin(c) == std::rend(c)); + assert ( std::cbegin(c) == std::cend(c)); + assert ( std::crbegin(c) == std::crend(c)); + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/array/types.pass.cpp b/libcxx/test/std/containers/sequences/array/types.pass.cpp new file mode 100644 index 00000000000..065ade959d0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/types.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/array/version.pass.cpp b/libcxx/test/std/containers/sequences/array/version.pass.cpp new file mode 100644 index 00000000000..b89a8dd8cca --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <array> + +#include <array> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp new file mode 100644 index 00000000000..77aaf3c131e --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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<std::deque<int> >(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<std::deque<int> >(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); + } +#if __cplusplus >= 201103L + { + std::deque<int, min_allocator<int>> c = make<std::deque<int, min_allocator<int>> >(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, min_allocator<int>> c = make<std::deque<int, min_allocator<int>> >(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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..8f732a06c7c --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void resize(size_type n); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1, int size) +{ + typedef typename C::const_iterator CI; + typename C::size_type 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); +} + +template <class C> +void +testN(int start, int N, int M) +{ + typedef typename C::const_iterator CI; + C c1 = make<C>(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<std::deque<int> >(rng[i], rng[j], rng[k]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>>>(rng[i], rng[j], rng[k]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..1d1522cbcb3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void resize(size_type n, const value_type& v); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1, int size, int x) +{ + typedef typename C::const_iterator CI; + typename C::size_type 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); +} + +template <class C> +void +testN(int start, int N, int M) +{ + typedef typename C::const_iterator CI; + C c1 = make<C>(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<std::deque<int> >(rng[i], rng[j], rng[k]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>>>(rng[i], rng[j], rng[k]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..0ac1d5a680c --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void shrink_to_fit(); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1) +{ + C s = c1; + c1.shrink_to_fit(); + assert(c1 == s); +} + +template <class C> +void +testN(int start, int N) +{ + typedef typename C::const_iterator CI; + C c1 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/alloc.pass.cpp new file mode 100644 index 00000000000..841bfd9f8a7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/alloc.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// explicit deque(const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "test_allocator.h" +#include "../../../NotConstructible.h" +#include "min_allocator.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)); +#if __cplusplus >= 201103L + test<int>(min_allocator<int>()); + test<NotConstructible>(min_allocator<NotConstructible>{}); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..c760b437244 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void assign(initializer_list<value_type> il); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::deque<int, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp new file mode 100644 index 00000000000..6594984fc0d --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class InputIterator> +// void assign(InputIterator f, InputIterator l); + +#include <deque> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1, const C& 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); +} + +template <class C> +void +testN(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + C c1 = make<C>(N, start); + C c2 = make<C>(M); + test(c1, c2); +} + +template <class C> +void +testI(C& c1, const C& c2) +{ + typedef typename 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); +} + +template <class C> +void +testNI(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + C c1 = make<C>(N, start); + C c2 = make<C>(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<std::deque<int> >(rng[i], rng[j], rng[k]); + testNI<std::deque<int> >(1500, 2000, 1000); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]); + testNI<std::deque<int, min_allocator<int>> >(1500, 2000, 1000); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp new file mode 100644 index 00000000000..fd6dd6e4ab6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void assign(size_type n, const value_type& v); + +#include <deque> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1, int size, int v) +{ + typedef typename 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); +} + +template <class C> +void +testN(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + C c1 = make<C>(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<std::deque<int> >(rng[i], rng[j], rng[k]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp new file mode 100644 index 00000000000..fa0c1203ede --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(const deque&); + +#include <deque> +#include <cassert> +#include "test_allocator.h" +#include "min_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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + 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, min_allocator<int>>(ab, an)); + } + { + std::deque<int, min_allocator<int> > v(3, 2, min_allocator<int>()); + std::deque<int, min_allocator<int> > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..efea4948eba --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(const deque& c, const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<int> >(ab, an, min_allocator<int>()), + min_allocator<int>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/default.pass.cpp new file mode 100644 index 00000000000..b725dade70b --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/default.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque() + +#include <deque> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "../../../NotConstructible.h" +#include "min_allocator.h" + +template <class T, class Allocator> +void +test() +{ + std::deque<T, Allocator> d; + assert(d.size() == 0); +#if __cplusplus >= 201103L + std::deque<T, Allocator> d1 = {}; + assert(d1.size() == 0); +#endif +} + +int main() +{ + test<int, std::allocator<int> >(); + test<NotConstructible, stack_allocator<NotConstructible, 1> >(); +#if __cplusplus >= 201103L + test<int, min_allocator<int> >(); + test<NotConstructible, min_allocator<NotConstructible> >(); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..3605a1b636f --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque() +// noexcept(is_nothrow_default_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..0f459b2c919 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// ~deque() // implied noexcept; + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..a9e0218e2e0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(initializer_list<value_type> il); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::deque<int, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..36c5af60ee3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <deque> +#include <cassert> + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::deque<int, min_allocator<int>> d({3, 4, 5, 6}, min_allocator<int>()); + assert(d.get_allocator() == min_allocator<int>()); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..faadf2b1a1d --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class InputIterator> deque(InputIterator f, InputIterator l); + +#include <deque> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "test_iterators.h" +#include "min_allocator.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); +#if __cplusplus >= 201103L + test<min_allocator<int> >(ab, an); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..b8c3e889929 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class InputIterator> +// deque(InputIterator f, InputIterator l, const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "test_iterators.h" +#include "test_allocator.h" +#include "min_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)); +#if __cplusplus >= 201103L + test(input_iterator<const int*>(ab), input_iterator<const int*>(an), min_allocator<int>()); + test(forward_iterator<const int*>(ab), forward_iterator<const int*>(an), min_allocator<int>()); + test(bidirectional_iterator<const int*>(ab), bidirectional_iterator<const int*>(an), min_allocator<int>()); + test(random_access_iterator<const int*>(ab), random_access_iterator<const int*>(an), min_allocator<int>()); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp new file mode 100644 index 00000000000..a20ad4cecbd --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(deque&&); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A{}); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A{}); + 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..0ba4a2da330 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move_alloc.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(deque&& c, const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A{}); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A{}); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3(std::move(c1), A()); + assert(c2 == c3); + assert(c3.get_allocator() == A()); + assert(c1.size() == 0); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..bb01dc5c54b --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque& operator=(deque&& c); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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)); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<MoveOnly> A; + std::deque<MoveOnly, A> c1(A{}); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c2(A{}); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque<MoveOnly, A> c3(A{}); + c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == A()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..c2bb40a8b6f --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque& operator=(deque&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value); + +// This tests a conforming extension + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::deque<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..36f780703c0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(deque&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal.pass.cpp new file mode 100644 index 00000000000..3a6ec8370b8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque& operator=(const deque& c); + +#include <deque> +#include <cassert> +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<int>>(ab, an)); + } + { + std::deque<int, min_allocator<int> > l(3, 2, min_allocator<int>()); + std::deque<int, min_allocator<int> > l2(l, min_allocator<int>()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<int>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..6468e4329bd --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque& operator=(initializer_list<value_type> il); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::deque<int, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/size.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/size.pass.cpp new file mode 100644 index 00000000000..d2e324b0e3f --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/size.pass.cpp @@ -0,0 +1,113 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// explicit deque(size_type n); + +#include <deque> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +template <class T, class Allocator> +void +test2(unsigned n) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::deque<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + assert(DefaultOnly::count == 0); + { + C d(n, Allocator()); + assert(DefaultOnly::count == n); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == T()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } + assert(DefaultOnly::count == 0); +#endif +} + +template <class T, class Allocator> +void +test1(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()); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == T()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } + assert(DefaultOnly::count == 0); +} + +template <class T, class Allocator> +void +test3(unsigned n, Allocator const &alloc = Allocator()) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::deque<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + { + C d(n, alloc); + assert(d.size() == n); + assert(d.get_allocator() == alloc); + } +#endif +} + +template <class T, class Allocator> +void +test(unsigned n) +{ + test1<T, Allocator> ( n ); + test2<T, Allocator> ( n ); +} + +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); + + test1<DefaultOnly, stack_allocator<DefaultOnly, 4096> >(4095); + +#if __cplusplus >= 201103L + test<DefaultOnly, min_allocator<DefaultOnly> >(4095); +#endif + +#if _LIBCPP_STD_VER > 11 + test3<DefaultOnly, std::allocator<DefaultOnly>> (1023); + test3<int, std::allocator<int>>(1); + test3<int, min_allocator<int>> (3); +#endif + +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp new file mode 100644 index 00000000000..859deba1e1a --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(size_type n, const value_type& v); + +#include <deque> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "min_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); +#if __cplusplus >= 201103L + test<int, min_allocator<int> >(4095, 90); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..5693be702de --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// deque(size_type n, const value_type& v, const allocator_type& a); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + min_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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..806f7280332 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class... Args> iterator emplace(const_iterator p, Args&&... args); + +#include <deque> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(int P, C& c1) +{ + typedef typename C::iterator I; + typedef typename 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)); +} + +template <class C> +void +testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + test(i, c1); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + test(i, c1); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + test(i, c1); + } + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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<std::deque<Emplaceable> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..aa977eb84bf --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class... Args> void emplace_back(Args&&... args); + +#include <deque> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1) +{ + typedef typename 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)); +} + +template <class C> +void +testN(int start, int N) +{ + C c1 = make<C>(N, start); + test(c1); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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<std::deque<Emplaceable> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..cf09d6e19b6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class... Args> void emplace_front(Args&&... args); + +#include <deque> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1) +{ + typedef typename 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)); +} + +template <class C> +void +testN(int start, int N) +{ + C c1 = make<C>(N, start); + test(c1); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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<std::deque<Emplaceable> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..bfab2a3a4fc --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator erase(const_iterator p) + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(int P, C& c1) +{ + typedef typename 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); +} + +template <class C> +void +testN(int start, int N) +{ + int pstep = std::max(N / std::max(std::min(N, 10), 1), 1); + for (int p = 0; p < N; p += pstep) + { + C c1 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..6e937ac0c4e --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,96 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// REQUIRES: long_tests + +// <deque> + +// iterator erase(const_iterator f, const_iterator l) + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(int P, C& c1, int size) +{ + typedef typename 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); +} + +template <class C> +void +testN(int start, int N) +{ + 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<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..5f7804023c7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } + { + std::deque<int, min_allocator<int>> d(10, 1); + std::deque<int, min_allocator<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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..2bc37c34ce4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,256 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// REQUIRES: long_tests + +// <deque> + +// template <class InputIterator> +// iterator insert (const_iterator p, InputIterator f, InputIterator l); + +#include <deque> +#include <cassert> + +#include "test_iterators.h" +#include "../../../MoveOnly.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(int P, C& c1, const C& c2) +{ + typedef typename C::iterator I; + typedef typename 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); +} + +template <class C> +void +testN(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + test(i, c1, c2); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + test(i, c1, c2); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + test(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + test(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + test(i, c1, c2); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + test(i, c1, c2); + } + } +} + +template <class C> +void +testI(int P, C& c1, const C& c2) +{ + typedef typename C::iterator I; + typedef typename 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); +} + +template <class C> +void +testNI(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + testI(i, c1, c2); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + testI(i, c1, c2); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + testI(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + testI(i, c1, c2); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + C c2 = make<C>(M); + testI(i, c1, c2); + } + } +} + +template <class C> +void +test_move() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + C c; + typedef typename C::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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} + +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<std::deque<int> >(rng[i], rng[j], rng[k]); + testNI<std::deque<int> >(1500, 2000, 1000); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_move<std::deque<MoveOnly, stack_allocator<MoveOnly, 2000> > >(); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]); + testNI<std::deque<int> >(1500, 2000, 1000); + test_move<std::deque<MoveOnly, min_allocator<MoveOnly> > >(); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp new file mode 100644 index 00000000000..0bde7d9b7e3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator insert (const_iterator p, value_type&& v); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(int P, C& c1, int x) +{ + typedef typename C::iterator I; + typedef typename 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)); +} + +template <class C> +void +testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(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<C>(N, start); + test(i, c1, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + test(i, c1, -10); + } + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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<std::deque<MoveOnly> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp new file mode 100644 index 00000000000..3e7767209e5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// REQUIRES: long_tests + +// <deque> + +// iterator insert (const_iterator p, size_type n, const value_type& v); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(int P, C& c1, int size, int x) +{ + typedef typename C::iterator I; + typedef typename 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); +} + +template <class C> +void +testN(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + test(i, c1, M, -10); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(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<C>(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<C>(N, start); + test(i, c1, M, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + test(i, c1, M, -10); + } + } +} + +template <class C> +void +self_reference_test() +{ + typedef typename C::const_iterator CI; + for (int i = 0; i < 20; ++i) + { + for (int j = 0; j < 20; ++j) + { + C c = make<C>(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<std::deque<int> >(rng[i], rng[j], rng[k]); + self_reference_test<std::deque<int> >(); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]); + self_reference_test<std::deque<int, min_allocator<int>> >(); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp new file mode 100644 index 00000000000..97827c1183a --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp @@ -0,0 +1,139 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator insert (const_iterator p, const value_type& v); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(int P, C& c1, int x) +{ + typedef typename C::iterator I; + typedef typename 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); +} + +template <class C> +void +testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(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<C>(N, start); + test(i, c1, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make<C>(N, start); + test(i, c1, -10); + } + } +} + +template <class C> +void +self_reference_test() +{ + typedef typename C::const_iterator CI; + for (int i = 0; i < 20; ++i) + { + for (int j = 0; j < 20; ++j) + { + C c = make<C>(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<std::deque<int> >(rng[i], rng[j]); + self_reference_test<std::deque<int> >(); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + self_reference_test<std::deque<int, min_allocator<int>> >(); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..e642f7132f5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void pop_back() + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1) +{ + typedef typename 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); +} + +template <class C> +void +testN(int start, int N) +{ + if (N != 0) + { + C c1 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..e27edf51f79 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void pop_front() + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1) +{ + typedef typename 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); +} + +template <class C> +void +testN(int start, int N) +{ + if (N != 0) + { + C c1 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..444ab9ba955 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_back(const value_type& v); +// void pop_back(); +// void pop_front(); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class 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) + { + C c = make<C>(size, rng[j]); + typename C::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<std::deque<int> >(rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp new file mode 100644 index 00000000000..3e628791a9f --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_back(const value_type& x); + +#include <deque> +#include <cassert> + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(int tag); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + bool equal(const CMyClass &rhs) const + { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; } + private: + int fMagicValue; + int fTag; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass(int tag) : + fMagicValue(kStartedConstructionMagicValue), fTag(tag) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& iOther) : + fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); } + +int main() +{ + CMyClass instance(42); + std::deque<CMyClass> vec; + + vec.push_back(instance); + std::deque<CMyClass> vec2(vec); + + gCopyConstructorShouldThow = true; + try { + vec.push_back(instance); + } + catch (...) { + assert(vec==vec2); + } +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..d6c44391477 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_back(value_type&& v); +// void pop_back(); +// void pop_front(); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +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; + } + C 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; +}; + +template <class 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) + { + C c = make<C>(size, rng[j]); + typename C::const_iterator it = c.begin(); + for (int i = 0; i < size; ++i, ++it) + assert(*it == MoveOnly(i)); + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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<std::deque<MoveOnly> >(rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp new file mode 100644 index 00000000000..700edd3abdb --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_front(const value_type& v); + +#include <deque> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1, int x) +{ + typedef typename 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); +} + +template <class C> +void +testN(int start, int N) +{ + C c1 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp new file mode 100644 index 00000000000..6ae06db0bca --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_front(const value_type& x); + +#include <deque> +#include <cassert> + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(int tag); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + bool equal(const CMyClass &rhs) const + { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; } + private: + int fMagicValue; + int fTag; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass(int tag) : + fMagicValue(kStartedConstructionMagicValue), fTag(tag) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& iOther) : + fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); } + +int main() +{ + CMyClass instance(42); + std::deque<CMyClass> vec; + + vec.push_front(instance); + std::deque<CMyClass> vec2(vec); + + gCopyConstructorShouldThow = true; + try { + vec.push_front(instance); + } + catch (...) { + assert(vec==vec2); + } +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp new file mode 100644 index 00000000000..1670a44aa07 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_front(value_type&& v); + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void +test(C& c1, int x) +{ + typedef typename 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)); +} + +template <class C> +void +testN(int start, int N) +{ + C c1 = make<C>(N, start); + test(c1, -10); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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<std::deque<MoveOnly> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/copy.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/copy.pass.cpp new file mode 100644 index 00000000000..7dfb4bc5c2d --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/copy.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Optimization for deque::iterators + +// template <class InputIterator, class OutputIterator> +// OutputIterator +// copy(InputIterator first, InputIterator last, OutputIterator result); + +#include <deque> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef random_access_iterator<I> RAI; + typedef random_access_iterator<CI> RACI; + typedef input_iterator<CI> ICI; + C c1 = make<C>(N, start); + C c2 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/copy_backward.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/copy_backward.pass.cpp new file mode 100644 index 00000000000..b484a865c57 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/copy_backward.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Optimization for deque::iterators + +// template <class InputIterator, class OutputIterator> +// OutputIterator +// copy_backward(InputIterator first, InputIterator last, OutputIterator result); + +#include <deque> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef random_access_iterator<I> RAI; + typedef random_access_iterator<CI> RACI; + C c1 = make<C>(N, start); + C c2 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/move.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/move.pass.cpp new file mode 100644 index 00000000000..b100ba487ea --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/move.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Optimization for deque::iterators + +// template <class InputIterator, class OutputIterator> +// OutputIterator +// move(InputIterator first, InputIterator last, OutputIterator result); + +#include <deque> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef random_access_iterator<I> RAI; + typedef random_access_iterator<CI> RACI; + C c1 = make<C>(N, start); + C c2 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/move_backward.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/move_backward.pass.cpp new file mode 100644 index 00000000000..072d7a78a30 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/move_backward.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Optimization for deque::iterators + +// template <class InputIterator, class OutputIterator> +// OutputIterator +// move_backward(InputIterator first, InputIterator last, OutputIterator result); + +#include <deque> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef random_access_iterator<I> RAI; + typedef random_access_iterator<CI> RACI; + C c1 = make<C>(N, start); + C c2 = make<C>(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<std::deque<int> >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int> > >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/swap.pass.cpp new file mode 100644 index 00000000000..808144c9ebe --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/swap.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// template <class T, class A> +// void swap(deque<T, A>& x, deque<T, A>& y); + +#include <deque> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" + +template <class C> +C +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; + } + C 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; +}; + +template <class C> +void testN(int start, int N, int M) +{ + C c1 = make<C>(N, start); + C c2 = make<C>(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<std::deque<int> >(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)); + } +#if __cplusplus >= 201103L + { + 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<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef min_allocator<int> A; + std::deque<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A()); + std::deque<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A()); + swap(c1, c2); + assert((c1 == std::deque<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A()); + assert((c2 == std::deque<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..d55d719c762 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void swap(deque& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); + +// This tests a conforming extension + +#include <deque> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::deque<MoveOnly, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::deque<MoveOnly, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::deque<MoveOnly, some_alloc<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp b/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp new file mode 100644 index 00000000000..8ec491fae4d --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// Test nested types and default template args: + +// template <class T, class Allocator = allocator<T> > +// class deque; + +// iterator, const_iterator + +#include <deque> +#include <iterator> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::deque<int> C; + C c; + C::iterator i; + i = c.begin(); + C::const_iterator j; + j = c.cbegin(); + assert(i == j); + } +#if __cplusplus >= 201103L + { + typedef std::deque<int, min_allocator<int>> C; + C c; + C::iterator i; + i = c.begin(); + C::const_iterator j; + j = c.cbegin(); + assert(i == j); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + std::deque<int>::iterator ii1{}, ii2{}; + std::deque<int>::iterator ii4 = ii1; + std::deque<int>::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + +// std::deque<int> c; +// assert ( ii1 != c.cbegin()); +// assert ( cii != c.begin()); +// assert ( cii != c.cend()); +// assert ( ii1 != c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/types.pass.cpp b/libcxx/test/std/containers/sequences/deque/types.pass.cpp new file mode 100644 index 00000000000..da9470d8a6c --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/types.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_allocator.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), ""); +#if __cplusplus >= 201103L + { + typedef std::deque<short, min_allocator<short>> C; + static_assert((std::is_same<C::value_type, short>::value), ""); + static_assert((std::is_same<C::allocator_type, min_allocator<C::value_type> >::value), ""); + static_assert((std::is_same<C::reference, C::value_type&>::value), ""); + static_assert((std::is_same<C::const_reference, const C::value_type&>::value), ""); + static_assert((std::is_same<C::pointer, min_pointer<C::value_type>>::value), ""); + static_assert((std::is_same<C::const_pointer, min_pointer<const C::value_type>>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/version.pass.cpp b/libcxx/test/std/containers/sequences/deque/version.pass.cpp new file mode 100644 index 00000000000..22e663d9bc2 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <deque> + +#include <deque> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/alloc.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/alloc.pass.cpp new file mode 100644 index 00000000000..d274bc03088 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/alloc.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.cons + +// template <class Alloc> +// dynarray(size_type c, const Alloc& alloc); +// template <class Alloc> +// dynarray(size_type c, const T& v, const Alloc& alloc); +// template <class Alloc> +// dynarray(const dynarray& d, const Alloc& alloc); +// template <class Alloc> +// dynarray(initializer_list<T>, const Alloc& alloc); + +// ~dynarray(); + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> +#include "test_allocator.h" + +using std::experimental::dynarray; + +template <class T, class Allocator> +void check_allocator ( const dynarray<T> &dyn, const Allocator &alloc ) { + for ( int i = 0; i < dyn.size (); ++i ) + assert ( dyn[i].get_allocator() == alloc ); +} + +template <class T, class Allocator> +void test ( const std::initializer_list<T> &vals, const Allocator &alloc ) { + typedef dynarray<T> dynA; + + dynA d1 ( vals, alloc ); + assert ( d1.size () == vals.size() ); + assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ())); + check_allocator ( d1, alloc ); + } + + +template <class T, class Allocator> +void test ( const T &val, const Allocator &alloc1, const Allocator &alloc2 ) { + typedef dynarray<T> dynA; + + dynA d1 ( 4, alloc1 ); + assert ( d1.size () == 4 ); + assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } )); + check_allocator ( d1, alloc1 ); + + dynA d2 ( 7, val, alloc1 ); + assert ( d2.size () == 7 ); + assert ( std::all_of ( d2.begin (), d2.end (), [&val]( const T &item ){ return item == val; } )); + check_allocator ( d2, alloc1 ); + + dynA d3 ( d2, alloc2 ); + assert ( d3.size () == 7 ); + assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } )); + check_allocator ( d3, alloc2 ); + } + +int main() +{ +// This test is waiting on the resolution of LWG issue #2235 +// typedef test_allocator<char> Alloc; +// typedef std::basic_string<char, std::char_traits<char>, Alloc> nstr; +// +// test ( nstr("fourteen"), Alloc(3), Alloc(4) ); +// test ( { nstr("1"), nstr("1"), nstr("2"), nstr("3"), nstr("5"), nstr("8")}, Alloc(6)); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/default.pass.cpp new file mode 100644 index 00000000000..0effac2fc14 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/default.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.cons + +// explicit dynarray(size_type c); +// dynarray(size_type c, const T& v); +// dynarray(initializer_list<T>); +// dynarray(const dynarray& d); + +// ~dynarray(); + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void test ( const std::initializer_list<T> &vals ) { + typedef dynarray<T> dynA; + + dynA d1 ( vals ); + assert ( d1.size () == vals.size() ); + assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ())); + } + + +template <class T> +void test ( const T &val ) { + typedef dynarray<T> dynA; + + dynA d1 ( 4 ); + assert ( d1.size () == 4 ); + assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } )); + + dynA d2 ( 7, val ); + assert ( d2.size () == 7 ); + assert ( std::all_of ( d2.begin (), d2.end (), [&val]( const T &item ){ return item == val; } )); + + dynA d3 ( d2 ); + assert ( d3.size () == 7 ); + assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } )); + } + +void test_bad_length () { + try { dynarray<int> ( std::numeric_limits<size_t>::max() / sizeof ( int ) + 1 ); } + catch ( std::bad_array_length & ) { return ; } + assert ( false ); + } + +void test_bad_alloc () { + try { dynarray<int> ( std::numeric_limits<size_t>::max() / sizeof ( int ) - 1 ); } + catch ( std::bad_alloc & ) { return ; } + assert ( false ); + } + +int main() +{ +// test<int> ( 14 ); // ints don't get default initialized + test<long> ( 0 ); + test<double> ( 14.0 ); + test<std::complex<double>> ( std::complex<double> ( 14, 0 )); + test<std::string> ( "fourteen" ); + + test ( { 1, 1, 2, 3, 5, 8 } ); + test ( { 1., 1., 2., 3., 5., 8. } ); + test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), + std::string("5"), std::string("8")} ); + +// Make sure we don't pick up the Allocator version here + dynarray<long> d1 ( 20, 3 ); + assert ( d1.size() == 20 ); + assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return item == 3L; } )); + + test_bad_length (); + test_bad_alloc (); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.data/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.data/default.pass.cpp new file mode 100644 index 00000000000..b669f25948e --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.data/default.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.data + +// T* data() noexcept; +// const T* data() const noexcept; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void dyn_test_const ( const dynarray<T> &dyn ) { + const T *data = dyn.data (); + assert ( data != NULL ); + assert ( std::equal ( dyn.begin(), dyn.end(), data )); + } + +template <class T> +void dyn_test ( dynarray<T> &dyn ) { + T *data = dyn.data (); + assert ( data != NULL ); + assert ( std::equal ( dyn.begin(), dyn.end(), data )); + } + + + +template <class T> +void test ( const T &val ) { + typedef dynarray<T> dynA; + + dynA d1 ( 4 ); + dyn_test ( d1 ); + dyn_test_const ( d1 ); + + dynA d2 ( 7, val ); + dyn_test ( d2 ); + dyn_test_const ( d2 ); + } + +int main() +{ + test<int> ( 14 ); + test<double> ( 14.0 ); + test<std::complex<double>> ( std::complex<double> ( 14, 0 )); + test<std::string> ( "fourteen" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.mutate/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.mutate/default.pass.cpp new file mode 100644 index 00000000000..c57887ddaf9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.mutate/default.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.data + +// void fill(const T& v); +// const T* data() const noexcept; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void test ( const T &val ) { + typedef dynarray<T> dynA; + + dynA d1 ( 4 ); + d1.fill ( val ); + assert ( std::all_of ( d1.begin (), d1.end (), + [&val]( const T &item ){ return item == val; } )); + } + +int main() +{ + test<int> ( 14 ); + test<double> ( 14.0 ); + test<std::complex<double>> ( std::complex<double> ( 14, 0 )); + test<std::string> ( "fourteen" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/at.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/at.pass.cpp new file mode 100644 index 00000000000..4d77cf73275 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/at.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + +// const_reference at(size_type n) const; +// reference at(size_type n); + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void dyn_at_fail ( dynarray<T> &dyn, size_t sz ) { + try { dyn.at (sz); } + catch (const std::out_of_range &) { return; } + assert ( false ); + } + +template <class T> +void dyn_at_fail_const ( const dynarray<T> &dyn, size_t sz ) { + try { dyn.at (sz); } + catch (const std::out_of_range &) { return; } + assert ( false ); + } + + +template <class T> +void dyn_test_const ( const dynarray<T> &dyn, const std::initializer_list<T> &vals ) { + const T *data = dyn.data (); + auto it = vals.begin (); + for ( size_t i = 0; i < dyn.size(); ++i, ++it ) { + assert ( data + i == &dyn.at(i)); + assert ( *it == dyn.at(i)); + } + + dyn_at_fail_const ( dyn, dyn.size ()); + dyn_at_fail_const ( dyn, 2*dyn.size ()); + dyn_at_fail_const ( dyn, size_t (-1)); + } + +template <class T> +void dyn_test ( dynarray<T> &dyn, const std::initializer_list<T> &vals ) { + T *data = dyn.data (); + auto it = vals.begin (); + for ( size_t i = 0; i < dyn.size(); ++i, ++it ) { + assert ( data + i == &dyn.at(i)); + assert ( *it == dyn.at(i)); + } + + dyn_at_fail ( dyn, dyn.size ()); + dyn_at_fail ( dyn, 2*dyn.size ()); + dyn_at_fail ( dyn, size_t (-1)); + } + + +template <class T> +void test ( std::initializer_list<T> vals ) { + typedef dynarray<T> dynA; + + dynA d1 ( vals ); + dyn_test ( d1, vals ); + dyn_test_const ( d1, vals ); + } + +int main() +{ + test ( { 1, 1, 2, 3, 5, 8 } ); + test ( { 1., 1., 2., 3., 5., 8. } ); + test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), + std::string("5"), std::string("8")} ); + + test<int> ( {} ); + test<std::complex<double>> ( {} ); + test<std::string> ( {} ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/begin_end.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/begin_end.pass.cpp new file mode 100644 index 00000000000..695e1aa9f14 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/begin_end.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + + +// iterator begin() noexcept; +// const_iterator begin() const noexcept; +// const_iterator cbegin() const noexcept; +// iterator end() noexcept; +// const_iterator end() const noexcept; +// const_iterator cend() const noexcept; +// +// reverse_iterator rbegin() noexcept; +// const_reverse_iterator rbegin() const noexcept; +// const_reverse_iterator crbegin() const noexcept; +// reverse_iterator rend() noexcept; +// const_reverse_iterator rend() const noexcept; +// const_reverse_iterator crend() const noexcept; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void dyn_test_const ( const dynarray<T> &dyn ) { + const T *data = dyn.data (); + assert ( data == &*dyn.begin ()); + assert ( data == &*dyn.cbegin ()); + + assert ( data + dyn.size() - 1 == &*dyn.rbegin ()); + assert ( data + dyn.size() - 1 == &*dyn.crbegin ()); + + assert ( dyn.size () == std::distance ( dyn.begin(), dyn.end())); + assert ( dyn.size () == std::distance ( dyn.cbegin(), dyn.cend())); + assert ( dyn.size () == std::distance ( dyn.rbegin(), dyn.rend())); + assert ( dyn.size () == std::distance ( dyn.crbegin(), dyn.crend())); + + assert ( dyn.begin () == dyn.cbegin ()); + assert ( &*dyn.begin () == &*dyn.cbegin ()); + assert ( dyn.rbegin () == dyn.crbegin ()); + assert ( &*dyn.rbegin () == &*dyn.crbegin ()); + assert ( dyn.end () == dyn.cend ()); + assert ( dyn.rend () == dyn.crend ()); + } + +template <class T> +void dyn_test ( dynarray<T> &dyn ) { + T *data = dyn.data (); + assert ( data == &*dyn.begin ()); + assert ( data == &*dyn.cbegin ()); + + assert ( data + dyn.size() - 1 == &*dyn.rbegin ()); + assert ( data + dyn.size() - 1 == &*dyn.crbegin ()); + + assert ( dyn.size () == std::distance ( dyn.begin(), dyn.end())); + assert ( dyn.size () == std::distance ( dyn.cbegin(), dyn.cend())); + assert ( dyn.size () == std::distance ( dyn.rbegin(), dyn.rend())); + assert ( dyn.size () == std::distance ( dyn.crbegin(), dyn.crend())); + + assert ( dyn.begin () == dyn.cbegin ()); + assert ( &*dyn.begin () == &*dyn.cbegin ()); + assert ( dyn.rbegin () == dyn.crbegin ()); + assert ( &*dyn.rbegin () == &*dyn.crbegin ()); + assert ( dyn.end () == dyn.cend ()); + assert ( dyn.rend () == dyn.crend ()); + } + + +template <class T> +void test ( const T &val ) { + typedef dynarray<T> dynA; + + dynA d1 ( 4 ); + dyn_test ( d1 ); + dyn_test_const ( d1 ); + + dynA d2 ( 7, val ); + dyn_test ( d2 ); + dyn_test_const ( d2 ); + } + +int main() +{ + test<int> ( 14 ); + test<double> ( 14.0 ); + test<std::complex<double>> ( std::complex<double> ( 14, 0 )); + test<std::string> ( "fourteen" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/capacity.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/capacity.pass.cpp new file mode 100644 index 00000000000..6d28eef1b05 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/capacity.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + +// size_type size() const noexcept; +// size_type max_size() const noexcept; +// bool empty() const noexcept; + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void dyn_test ( const dynarray<T> &dyn, size_t sz ) { + assert ( dyn.size () == sz ); + assert ( dyn.max_size () == sz ); + assert ( dyn.empty () == ( sz == 0 )); + } + +template <class T> +void test ( std::initializer_list<T> vals ) { + typedef dynarray<T> dynA; + + dynA d1 ( vals ); + dyn_test ( d1, vals.size ()); + } + +int main() +{ + test ( { 1, 1, 2, 3, 5, 8 } ); + test ( { 1., 1., 2., 3., 5., 8. } ); + test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), + std::string("5"), std::string("8")} ); + + test<int> ( {} ); + test<std::complex<double>> ( {} ); + test<std::string> ( {} ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/front_back.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/front_back.pass.cpp new file mode 100644 index 00000000000..e82aa64b98b --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/front_back.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + +// reference front(); +// const_reference front() const; +// reference back(); +// const_reference back() const; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void dyn_test_const ( const dynarray<T> &dyn ) { + const T *data = dyn.data (); + assert ( *data == dyn.front ()); + assert ( *(data + dyn.size() - 1 ) == dyn.back ()); + } + +template <class T> +void dyn_test ( dynarray<T> &dyn ) { + T *data = dyn.data (); + assert ( *data == dyn.front ()); + assert ( *(data + dyn.size() - 1 ) == dyn.back ()); + } + + +template <class T> +void test ( const T &val ) { + typedef dynarray<T> dynA; + + dynA d1 ( 4 ); + dyn_test ( d1 ); + dyn_test_const ( d1 ); + + dynA d2 ( 7, val ); + dyn_test ( d2 ); + dyn_test_const ( d2 ); + } + +int main() +{ + test<int> ( 14 ); + test<double> ( 14.0 ); + test<std::complex<double>> ( std::complex<double> ( 14, 0 )); + test<std::string> ( "fourteen" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/indexing.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/indexing.pass.cpp new file mode 100644 index 00000000000..7317a2023cb --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/indexing.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + +// const_reference at(size_type n) const; +// reference at(size_type n); + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void dyn_test_const ( const dynarray<T> &dyn, const std::initializer_list<T> &vals ) { + const T *data = dyn.data (); + auto it = vals.begin (); + for ( size_t i = 0; i < dyn.size(); ++i, ++it ) { + assert ( data + i == &dyn[i]); + assert ( *it == dyn[i]); + } + } + +template <class T> +void dyn_test ( dynarray<T> &dyn, const std::initializer_list<T> &vals ) { + T *data = dyn.data (); + auto it = vals.begin (); + for ( size_t i = 0; i < dyn.size(); ++i, ++it ) { + assert ( data + i == &dyn[i]); + assert ( *it == dyn[i]); + } + } + + +template <class T> +void test ( std::initializer_list<T> vals ) { + typedef dynarray<T> dynA; + + dynA d1 ( vals ); + dyn_test ( d1, vals ); + dyn_test_const ( d1, vals ); + } + +int main() +{ + test ( { 1, 1, 2, 3, 5, 8 } ); + test ( { 1., 1., 2., 3., 5., 8. } ); + test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), + std::string("5"), std::string("8")} ); + + test<int> ( {} ); + test<std::complex<double>> ( {} ); + test<std::string> ( {} ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.traits/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.traits/default.pass.cpp new file mode 100644 index 00000000000..9b8240d4cd8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.traits/default.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.data + +// template <class Type, class Alloc> +// struct uses_allocator<dynarray<Type>, Alloc> : true_type { }; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include "test_allocator.h" + +using std::experimental::dynarray; + +int main() +{ + static_assert ( std::uses_allocator<dynarray<int>, test_allocator<int>>::value, "" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.zero/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.zero/default.pass.cpp new file mode 100644 index 00000000000..93f3b18f192 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.zero/default.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.zero + +// dynarray shall provide support for the special case of construction with a size of zero. +// In the case that the size is zero, begin() == end() == unique value. +// The return value of data() is unspecified. +// The effect of calling front() or back() for a zero-sized dynarray is undefined. + + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include <experimental/dynarray> +#include <cassert> + +#include <algorithm> +#include <complex> +#include <string> + +using std::experimental::dynarray; + +template <class T> +void test ( ) { + typedef dynarray<T> dynA; + + dynA d1 ( 0 ); + assert ( d1.size() == 0 ); + assert ( d1.begin() == d1.end ()); + } + +int main() +{ + test<int> (); + test<double> (); + test<std::complex<double>> (); + test<std::string> (); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/nothing_to_do.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp new file mode 100644 index 00000000000..2ec9b871332 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// reference front(); +// const_reference front() const; + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp new file mode 100644 index 00000000000..cd4d1ede120 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/std/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp new file mode 100644 index 00000000000..7aba906ec20 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// explicit forward_list(const allocator_type& a); + +#include <forward_list> +#include <cassert> + +#include "test_allocator.h" +#include "../../../NotConstructible.h" +#include "min_allocator.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()); + } +#if __cplusplus >= 201103L + { + typedef min_allocator<NotConstructible> A; + typedef A::value_type T; + typedef std::forward_list<T, A> C; + C c(A{}); + assert(c.get_allocator() == A()); + assert(c.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..0b9263db989 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list& operator=(const forward_list& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_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()); + C c1(std::begin(t1), std::end(t1), A()); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A()); + } + { + typedef int T; + typedef min_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()); + C c1(std::begin(t1), std::end(t1), A()); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp new file mode 100644 index 00000000000..e0382a10db4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void assign(initializer_list<value_type> il); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..a3d270f01d9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp @@ -0,0 +1,199 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list& operator=(forward_list&& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "test_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef min_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()); + C c1(I(std::begin(t1)), I(std::end(t1)), A()); + 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()); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef min_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()); + C c1(I(std::begin(t1)), I(std::end(t1)), A()); + 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()); + assert(c0.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp new file mode 100644 index 00000000000..551908fea16 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list& operator=(initializer_list<value_type> il); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp new file mode 100644 index 00000000000..0b348e6920c --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class InputIterator> +// void assign(InputIterator first, InputIterator last); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "test_iterators.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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, (void) ++n) + assert(*i == 10+n); + assert(n == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp new file mode 100644 index 00000000000..ea53e1c3732 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void assign(size_type n, const value_type& v); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp new file mode 100644 index 00000000000..2fc53bc3a51 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(const forward_list& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "test_allocator.h" +#include "min_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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_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()); + 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()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..bcc24e1cc68 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(const forward_list& x, const allocator_type& a); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_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()); + C c(c0, A()); + 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()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp new file mode 100644 index 00000000000..38e95fad839 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + C c; + assert(c.empty()); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<T>> C; + C c; + assert(c.empty()); + } + { + typedef int T; + typedef std::forward_list<T> C; + C c = {}; + assert(c.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..6b0233d65b6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list() +// noexcept(is_nothrow_default_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_recursive.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_recursive.pass.cpp new file mode 100644 index 00000000000..5ff00e6fe52 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_recursive.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// class forward_list + +// forward_list(); + +#include <forward_list> + +struct X +{ + std::forward_list<X> q; +}; + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..1f7b05efd66 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// ~forward_list() // implied noexcept; + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp new file mode 100644 index 00000000000..5b31c4dad0a --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(initializer_list<value_type> il); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp new file mode 100644 index 00000000000..750486b829f --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(initializer_list<value_type> il, const allocator_type& a); + +#include <forward_list> +#include <cassert> + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_allocator<T> A; + typedef std::forward_list<T, A> C; + C c({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, A()); + 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()); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp new file mode 100644 index 00000000000..164801a0b40 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(forward_list&& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "test_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef min_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()); + 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()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..ba0cb5d3beb --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef min_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()); + C c(std::move(c0), A()); + 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()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..cc5b9d54ed3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list& operator=(forward_list&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value); + +// This tests a conforming extension + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..3666c7d169d --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(forward_list&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::forward_list<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp new file mode 100644 index 00000000000..763952439f0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class InputIterator> +// forward_list(InputIterator first, InputIterator last); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "test_iterators.h" +#include "min_allocator.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)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp new file mode 100644 index 00000000000..d72c3581022 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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 "test_iterators.h" +#include "min_allocator.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)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_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()); + 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()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp new file mode 100644 index 00000000000..2d963a1be47 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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) +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(*i == T()); +#else + ; +#endif + assert(n == N); + } +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp new file mode 100644 index 00000000000..e02dcb4bf69 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// explicit forward_list(size_type n); +// explicit forward_list(size_type n, const Alloc& a); + +#include <forward_list> +#include <cassert> + +#include "DefaultOnly.h" +#include "min_allocator.h" + +template <class T, class Allocator> +void check_allocator(unsigned n, Allocator const &alloc = Allocator()) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::forward_list<T, Allocator> C; + C d(n, alloc); + assert(d.get_allocator() == alloc); + assert(std::distance(d.begin(), d.end()) == n); +#endif +} + +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) +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(*i == T()); +#else + ; +#endif + assert(n == N); + } +#if __cplusplus >= 201103L + { + typedef DefaultOnly T; + typedef std::forward_list<T, min_allocator<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) +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(*i == T()); +#else + ; +#endif + assert(n == N); + check_allocator<T, min_allocator<T>> ( 0 ); + check_allocator<T, min_allocator<T>> ( 3 ); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp new file mode 100644 index 00000000000..05ab98bb205 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(size_type n, const value_type& v); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..1d631ab12ba --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// forward_list(size_type n, const value_type& v, const allocator_type& a); + +#include <forward_list> +#include <cassert> + +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef min_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()); + 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()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp new file mode 100644 index 00000000000..083cec2886d --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator before_begin(); +// const_iterator before_begin() const; +// const_iterator cbefore_begin() const; + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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, min_allocator<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, min_allocator<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, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp new file mode 100644 index 00000000000..6f3ac548db8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +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; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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, min_allocator<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, min_allocator<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, min_allocator<T>> C; + C::iterator i; + C::const_iterator j; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + std::forward_list<int>::iterator ii1{}, ii2{}; + std::forward_list<int>::iterator ii4 = ii1; + std::forward_list<int>::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + +// std::forward_list<int> c; +// assert ( ii1 != c.cbegin()); +// assert ( cii != c.begin()); +// assert ( cii != c.cend()); +// assert ( ii1 != c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..2739b49d8eb --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void clear(); + +#include <forward_list> +#include <cassert> + +#include "../../../NotConstructible.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + typedef NotConstructible T; + typedef std::forward_list<T, min_allocator<T>> C; + C c; + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::forward_list<T, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp new file mode 100644 index 00000000000..e305c5b6ab5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class... Args> +// iterator emplace_after(const_iterator p, Args&&... args); + +#include <forward_list> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef Emplaceable T; + typedef std::forward_list<T, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..c02337e0562 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class... Args> void emplace_front(Args&&... args); + +#include <forward_list> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef Emplaceable T; + typedef std::forward_list<T, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp new file mode 100644 index 00000000000..bd9b15300ef --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator erase_after(const_iterator first, const_iterator last); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +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::iterator i = c.erase_after(next(c.cbefore_begin(), 4), next(c.cbefore_begin(), 4)); + assert(i == 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); + + i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 5)); + assert(i == next(c.begin(), 2)); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 3)); + assert(i == next(c.begin(), 2)); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 5), next(c.cbefore_begin(), 9)); + assert(i == c.end()); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 2)); + assert(i == c.begin()); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 5)); + assert(i == c.begin()); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 0); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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.erase_after(next(c.cbefore_begin(), 4), next(c.cbefore_begin(), 4)); + assert(i == 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); + + i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 5)); + assert(i == next(c.begin(), 2)); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 3)); + assert(i == next(c.begin(), 2)); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 5), next(c.cbefore_begin(), 9)); + assert(i == c.end()); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 2)); + assert(i == c.begin()); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 5)); + assert(i == c.begin()); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp new file mode 100644 index 00000000000..4f51498bc65 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator erase_after(const_iterator p); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.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::iterator i = c.erase_after(next(c.cbefore_begin(), 4)); + assert(i == c.end()); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 0)); + assert(i == c.begin()); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 1)); + assert(i == next(c.begin())); + assert(distance(c.begin(), c.end()) == 2); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 3); + + i = c.erase_after(next(c.cbefore_begin(), 1)); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 1); + assert(*next(c.begin(), 0) == 1); + + i = c.erase_after(next(c.cbefore_begin(), 0)); + assert(i == c.begin()); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 0); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<T>> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + C::iterator i = c.erase_after(next(c.cbefore_begin(), 4)); + assert(i == c.end()); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 0)); + assert(i == c.begin()); + 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); + + i = c.erase_after(next(c.cbefore_begin(), 1)); + assert(i == next(c.begin())); + assert(distance(c.begin(), c.end()) == 2); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 3); + + i = c.erase_after(next(c.cbefore_begin(), 1)); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 1); + assert(*next(c.begin(), 0) == 1); + + i = c.erase_after(next(c.cbefore_begin(), 0)); + assert(i == c.begin()); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp new file mode 100644 index 00000000000..ec650b69572 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator insert_after(const_iterator p, const value_type& v); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp new file mode 100644 index 00000000000..4d301819980 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator insert_after(const_iterator p, initializer_list<value_type> il); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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 == next(c.before_begin(), 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); + + i = c.insert_after(c.begin(), {3, 4}); + assert(i == next(c.begin(), 2)); + 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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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 == next(c.before_begin(), 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); + + i = c.insert_after(c.begin(), {3, 4}); + assert(i == next(c.begin(), 2)); + 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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp new file mode 100644 index 00000000000..103475f1eda --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class InputIterator> +// iterator insert_after(const_iterator p, +// InputIterator first, InputIterator last); + +#include <forward_list> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.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 == next(c.before_begin(), 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); + + i = c.insert_after(c.begin(), J(t+3), J(t+5)); + assert(i == next(c.begin(), 2)); + 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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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 == next(c.before_begin(), 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); + + i = c.insert_after(c.begin(), J(t+3), J(t+5)); + assert(i == next(c.begin(), 2)); + 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/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp new file mode 100644 index 00000000000..4f0be520c30 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator insert_after(const_iterator p, value_type&& v); + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef std::forward_list<T, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp new file mode 100644 index 00000000000..b2da2ecd3bb --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// iterator insert_after(const_iterator p, size_type n, const value_type& v); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +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 == next(c.before_begin(), 3)); + 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 == next(c.begin(), 2)); + 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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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 == next(c.before_begin(), 3)); + 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 == next(c.begin(), 2)); + 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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..276f2c9f8ed --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void pop_front(); + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.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); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<T>> C; + typedef std::forward_list<T, min_allocator<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); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly T; + typedef std::forward_list<T, min_allocator<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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp new file mode 100644 index 00000000000..85958afc1ce --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void push_front(const value_type& v); + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp new file mode 100644 index 00000000000..43c62eb00cb --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void push_front(const value_type& x); + +#include <forward_list> +#include <cassert> + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + private: int fMagicValue; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass() : + fMagicValue(kStartedConstructionMagicValue) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& /*iOther*/) : + fMagicValue(kStartedConstructionMagicValue) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +int main() +{ + CMyClass instance; + std::forward_list<CMyClass> vec; + + vec.push_front(instance); + + gCopyConstructorShouldThow = true; + try { + vec.push_front(instance); + } + catch (...) { + } +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp new file mode 100644 index 00000000000..53181ec881e --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void push_front(value_type&& v); + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef std::forward_list<T, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp new file mode 100644 index 00000000000..ef7ef82626d --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp @@ -0,0 +1,114 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void resize(size_type n); + +#include <forward_list> +#include <cassert> + +#include "DefaultOnly.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + typedef DefaultOnly T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp new file mode 100644 index 00000000000..d4bd6b4e011 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void resize(size_type n, const value_type& v); + +#include <forward_list> +#include <cassert> + +#include "DefaultOnly.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp new file mode 100644 index 00000000000..3b6f853c84c --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void merge(forward_list&& x); + +#include <forward_list> +#include <iterator> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp new file mode 100644 index 00000000000..7e873bdddd0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class Compare> void merge(forward_list&& x, Compare comp); + +#include <forward_list> +#include <iterator> +#include <functional> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp new file mode 100644 index 00000000000..18d4cae8cc6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void remove(const value_type& v); + +#include <forward_list> +#include <iterator> +#include <cassert> + +#include "min_allocator.h" + +struct S { + S(int i) : i_(new int(i)) {} + S(const S &rhs) : i_(new int(*rhs.i_)) {} + S& operator = (const S &rhs) { *i_ = *rhs.i_; return *this; } + ~S () { delete i_; i_ = NULL; } + bool operator == (const S &rhs) const { return *i_ == *rhs.i_; } + int get () const { return *i_; } + int *i_; + }; + + +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); + } + { // LWG issue #526 + typedef int T; + typedef std::forward_list<T> C; + int t1[] = {1, 2, 1, 3, 5, 8, 11}; + int t2[] = { 2, 3, 5, 8, 11}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(c1.front()); + assert(c1 == c2); + } + { + typedef S T; + typedef std::forward_list<T> C; + int t1[] = {1, 2, 1, 3, 5, 8, 11, 1}; + int t2[] = { 2, 3, 5, 8, 11 }; + C c; + for(int *ip = std::end(t1); ip != std::begin(t1);) + c.push_front(S(*--ip)); + c.remove(c.front()); + C::const_iterator it = c.begin(); + for(int *ip = std::begin(t2); ip != std::end(t2); ++ip, ++it) { + assert ( it != c.end()); + assert ( *ip == it->get()); + } + assert ( it == c.end ()); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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, min_allocator<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, min_allocator<T>> C; + C c1; + C c2; + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp new file mode 100644 index 00000000000..ed408fbd685 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class Predicate> void remove_if(Predicate pred); + +#include <forward_list> +#include <iterator> +#include <cassert> + +#include "min_allocator.h" +#include "counting_predicates.hpp" + + +bool g(int i) +{ + return i < 3; +} + +int main() +{ + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + 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)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + typedef std::forward_list<T> C; + const T t1[] = {0, 0, 0, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2; + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + 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)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + typedef std::forward_list<T> C; + C c1; + C c2; + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == 0); + } + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + 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)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + typedef std::forward_list<T, min_allocator<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)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + typedef std::forward_list<T, min_allocator<T>> C; + const T t1[] = {0, 0, 0, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2; + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + typedef std::forward_list<T, min_allocator<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)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + typedef std::forward_list<T, min_allocator<T>> C; + C c1; + C c2; + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == 0); + } + { + typedef int T; + typedef unary_counting_predicate<bool(*)(T), T> Predicate; + typedef std::forward_list<T, min_allocator<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)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp new file mode 100644 index 00000000000..9bf0d03a885 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void reverse(); + +#include <forward_list> +#include <iterator> +#include <algorithm> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +void test(int N) +{ + C c; + for (int i = 0; i < N; ++i) + c.push_front(i); + c.reverse(); + assert(distance(c.begin(), c.end()) == N); + typename 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<std::forward_list<int> >(i); +#if __cplusplus >= 201103L + for (int i = 0; i < 10; ++i) + test<std::forward_list<int, min_allocator<int>> >(i); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp new file mode 100644 index 00000000000..06e40c595ec --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void sort(); + +#include <forward_list> +#include <iterator> +#include <algorithm> +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +void test(int N) +{ + typedef typename C::value_type T; + 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); + typename 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<std::forward_list<int> >(i); +#if __cplusplus >= 201103L + for (int i = 0; i < 40; ++i) + test<std::forward_list<int, min_allocator<int>> >(i); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp new file mode 100644 index 00000000000..8b6ca39b2aa --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class Compare> void sort(Compare comp); + +#include <forward_list> +#include <iterator> +#include <algorithm> +#include <vector> +#include <functional> +#include <cassert> + +#include "min_allocator.h" + +template <class C> +void test(int N) +{ + typedef typename C::value_type T; + 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); + typename 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<std::forward_list<int> >(i); +#if __cplusplus >= 201103L + for (int i = 0; i < 40; ++i) + test<std::forward_list<int, min_allocator<int>> >(i); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp new file mode 100644 index 00000000000..51da651970c --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void splice_after(const_iterator p, forward_list&& x); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +typedef int T; +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); + +template <class C> +void +testd(const C& c, int p, int l) +{ + typename 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 + typedef std::forward_list<T> C; + 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); + } + } + } +#if __cplusplus >= 201103L + { + // splicing different containers + typedef std::forward_list<T, min_allocator<T>> C; + 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); + } + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp new file mode 100644 index 00000000000..296ffcd6955 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp @@ -0,0 +1,140 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void splice_after(const_iterator p, forward_list&& x, const_iterator i); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +typedef int T; +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); + +template <class C> +void +testd(const C& c, int p, int f) +{ + typename 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); +} + +template <class C> +void +tests(const C& c, int p, int f) +{ + typename 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 + typedef std::forward_list<T> C; + 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); + } + } + } +#if __cplusplus >= 201103L + { + // splicing different containers + typedef std::forward_list<T, min_allocator<T>> C; + 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); + } + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp new file mode 100644 index 00000000000..90a15995963 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp @@ -0,0 +1,169 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void splice_after(const_iterator p, forward_list&& x, +// const_iterator first, const_iterator last); + +#include <forward_list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +typedef int T; +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); + +template <class C> +void +testd(const C& c, int p, int f, int l) +{ + typename 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)); +} + +template <class C> +void +tests(const C& c, int p, int f, int l) +{ + typename 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 + typedef std::forward_list<T> C; + 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); + } + } + } + } +#if __cplusplus >= 201103L + { + // splicing different containers + typedef std::forward_list<T, min_allocator<T>> C; + 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); + } + } + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp new file mode 100644 index 00000000000..25db6e64b8a --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void unique(); + +#include <forward_list> +#include <iterator> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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, min_allocator<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, min_allocator<T>> C; + C c1; + C c2; + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp new file mode 100644 index 00000000000..b7dce20b709 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp @@ -0,0 +1,125 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// template <class BinaryPredicate> void unique(BinaryPredicate binary_pred); + +#include <forward_list> +#include <iterator> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<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, min_allocator<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, min_allocator<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, min_allocator<T>> C; + C c1; + C c2; + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list<T, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp new file mode 100644 index 00000000000..ca673b58368 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +template <class C> +void test(int N, int M) +{ + typedef typename C::value_type T; + 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<std::forward_list<int> >(i, j); +#if __cplusplus >= 201103L + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + test<std::forward_list<int, min_allocator<int>> >(i, j); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp new file mode 100644 index 00000000000..2b2be7b6c22 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp @@ -0,0 +1,259 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void swap(forward_list& x); + +#include <forward_list> +#include <cassert> + +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_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()); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A()); + 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()); + + 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()); + } + { + typedef int T; + typedef min_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()); + C c2(A{}); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A()); + + 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()); + } + { + typedef int T; + typedef min_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A{}); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A()); + 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()); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A{}); + C c2(A{}); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp new file mode 100644 index 00000000000..d6ba5a47cbe --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp @@ -0,0 +1,260 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_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()); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A()); + 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()); + + 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()); + } + { + typedef int T; + typedef min_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()); + C c2(A{}); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A()); + + 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()); + } + { + typedef int T; + typedef min_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A{}); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A()); + 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()); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator<T> A; + typedef std::forward_list<T, A> C; + C c1(A{}); + C c2(A{}); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp new file mode 100644 index 00000000000..42e245d007b --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +template <class C> +void test(int N, int M) +{ + typedef typename C::value_type T; + 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<std::forward_list<int> >(i, j); +#if __cplusplus >= 201103L + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + test<std::forward_list<int, min_allocator<int>> >(i, j); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..cde97d5f738 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// void swap(forward_list& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); + +// This tests a conforming extension + +#include <forward_list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::forward_list<MoveOnly, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::forward_list<MoveOnly, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::forward_list<MoveOnly, some_alloc<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/max_size.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/max_size.pass.cpp new file mode 100644 index 00000000000..be7ebaf44b0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +// size_type max_size() const; + +#include <forward_list> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list<T> C; + C c; + assert(c.max_size() > 0); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list<T, min_allocator<T>> C; + C c; + assert(c.max_size() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp new file mode 100644 index 00000000000..c95548710bc --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::forward_list<char> C; + static_assert((std::is_same<C::value_type, char>::value), ""); + static_assert((std::is_same<C::allocator_type, std::allocator<char> >::value), ""); + static_assert((std::is_same<C::reference, char&>::value), ""); + static_assert((std::is_same<C::const_reference, const char&>::value), ""); + static_assert((std::is_same<C::pointer, char*>::value), ""); + static_assert((std::is_same<C::const_pointer, const char*>::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), ""); + } +#if __cplusplus >= 201103L + { + typedef std::forward_list<char, min_allocator<char>> C; + static_assert((std::is_same<C::value_type, char>::value), ""); + static_assert((std::is_same<C::allocator_type, min_allocator<char> >::value), ""); + static_assert((std::is_same<C::reference, char&>::value), ""); + static_assert((std::is_same<C::const_reference, const char&>::value), ""); + static_assert((std::is_same<C::pointer, min_pointer<char>>::value), ""); + static_assert((std::is_same<C::const_pointer, min_pointer<const char>>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/version.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/version.pass.cpp new file mode 100644 index 00000000000..918c8dd5d73 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <forward_list> + +#include <forward_list> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/list/db_back.pass.cpp b/libcxx/test/std/containers/sequences/list/db_back.pass.cpp new file mode 100644 index 00000000000..b16c0e90701 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_back.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call back() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list<T> C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list<T, min_allocator<T>> C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_cback.pass.cpp b/libcxx/test/std/containers/sequences/list/db_cback.pass.cpp new file mode 100644 index 00000000000..ba3977e16f4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_cback.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call back() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list<T> C; + const C c; + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list<T, min_allocator<T>> C; + const C c; + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_cfront.pass.cpp b/libcxx/test/std/containers/sequences/list/db_cfront.pass.cpp new file mode 100644 index 00000000000..d42290c43c0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_cfront.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call front() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list<T> C; + const C c; + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list<T, min_allocator<T>> C; + const C c; + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_front.pass.cpp b/libcxx/test/std/containers/sequences/list/db_front.pass.cpp new file mode 100644 index 00000000000..037b16035c6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_front.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call front() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list<T> C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list<T, min_allocator<T>> C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_iterators_6.pass.cpp b/libcxx/test/std/containers/sequences/list/db_iterators_6.pass.cpp new file mode 100644 index 00000000000..a5b8020b373 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_iterators_6.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Decrement iterator prior to begin. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list<T> C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_iterators_7.pass.cpp b/libcxx/test/std/containers/sequences/list/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..76a491b1184 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_iterators_7.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list<T> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_iterators_8.pass.cpp b/libcxx/test/std/containers/sequences/list/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..1d1ee23a393 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list<T> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_iterators_9.pass.cpp b/libcxx/test/std/containers/sequences/list/db_iterators_9.pass.cpp new file mode 100644 index 00000000000..d02fcd6e449 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_iterators_9.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Operations on "NULL" iterators + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) do { if (!x) throw 1; } while(0) + +#include <list> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +struct S { int val; }; + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + unsigned lib_asserts; + + typedef S T; + typedef std::list<T> C; + C::iterator i{}; + C::const_iterator ci{}; + + lib_asserts = 0; + try { ++i; } catch (int) { ++lib_asserts; } + try { i++; } catch (int) { ++lib_asserts; } + try { ++ci; } catch (int) { ++lib_asserts; } + try { ci++; } catch (int) { ++lib_asserts; } + assert(lib_asserts == 4); + + lib_asserts = 0; + try { --i; } catch (int) { ++lib_asserts; } + try { i--; } catch (int) { ++lib_asserts; } + try { --ci; } catch (int) { ++lib_asserts; } + try { ci--; } catch (int) { ++lib_asserts; } + assert(lib_asserts == 4); + + lib_asserts = 0; + try { *i; } catch (int) { ++lib_asserts; } + try { *ci; } catch (int) { ++lib_asserts; } + try { (void) i->val; } catch (int) { ++lib_asserts; } + try { (void) ci->val; } catch (int) { ++lib_asserts; } + assert(lib_asserts == 4); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/iterators.pass.cpp b/libcxx/test/std/containers/sequences/list/iterators.pass.cpp new file mode 100644 index 00000000000..a33ee3ecd2d --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/iterators.pass.cpp @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include <list> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +struct A +{ + int first; + int second; +}; + +int main() +{ + { + typedef int T; + typedef std::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::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::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::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::list<T> C; + C::iterator i; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list<T, min_allocator<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::list<T, min_allocator<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::list<T, min_allocator<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::list<T, min_allocator<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::list<T, min_allocator<T>> C; + C::iterator i; + C::const_iterator j; + } + { + typedef A T; + typedef std::list<T, min_allocator<T>> C; + C c = {A{1, 2}}; + C::iterator i = c.begin(); + i->first = 3; + C::const_iterator j = i; + assert(j->first == 3); + } +#endif +#if _LIBCPP_STD_VER > 11 + { + std::list<int> c; + std::list<int>::iterator ii1{}, ii2{}; + std::list<int>::iterator ii4 = ii1; + std::list<int>::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + + assert ( ii1 != c.cbegin()); + assert ( cii != c.begin()); + } +#endif + +} diff --git a/libcxx/test/std/containers/sequences/list/list.capacity/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/list/list.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..14629b173a6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.capacity/resize_size.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void resize(size_type sz); + +#include <list> +#include <cassert> +#include "DefaultOnly.h" +#include "min_allocator.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 // __LIBCPP_MOVE +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l(5, 2); + l.resize(2); + assert(l.size() == 2); + assert(std::distance(l.begin(), l.end()) == 2); + assert((l == std::list<int, min_allocator<int>>(2, 2))); + } + { + std::list<int, min_allocator<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, min_allocator<DefaultOnly>> l(10); + l.resize(5); + assert(l.size() == 5); + assert(std::distance(l.begin(), l.end()) == 5); + } + { + std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10); + l.resize(20); + assert(l.size() == 20); + assert(std::distance(l.begin(), l.end()) == 20); + } +#endif // __LIBCPP_MOVE +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.capacity/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/list/list.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..2738ffbbefd --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.capacity/resize_size_value.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void resize(size_type sz, const value_type& x); + +#include <list> +#include <cassert> +#include "DefaultOnly.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + std::list<double, min_allocator<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, min_allocator<double>>(2, 2))); + } + { + std::list<double, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..b851eb9dc5a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list& operator=(const list& c); + +#include <list> +#include <cassert> +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int> > l(3, 2, min_allocator<int>()); + std::list<int, min_allocator<int> > l2(l, min_allocator<int>()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<int>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..24bd140c4e4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void assign(initializer_list<value_type> il); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + std::list<int, min_allocator<int>>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..99f0a98204f --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list& operator=(list&& c); + +#include <list> +#include <cassert> +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } +#if __cplusplus >= 201103L + { + std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{}); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/copy.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/copy.pass.cpp new file mode 100644 index 00000000000..530690a925d --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/copy.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(const list& c); + +#include <list> +#include <cassert> +#include "DefaultOnly.h" +#include "test_allocator.h" +#include "min_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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l(3, 2); + std::list<int, min_allocator<int>> l2 = l; + assert(l2 == l); + } + { + std::list<int, min_allocator<int> > l(3, 2, min_allocator<int>()); + std::list<int, min_allocator<int> > l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == l.get_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..99fe9f115f9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/copy_alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(const list& c, const allocator_type& a); + +#include <list> +#include <cassert> +#include "DefaultOnly.h" +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int> > l(3, 2, min_allocator<int>()); + std::list<int, min_allocator<int> > l2(l, min_allocator<int>()); + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<int>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/default.pass.cpp new file mode 100644 index 00000000000..c05bd74ca79 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/default.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// explicit list(const Alloc& = Alloc()); + +#include <list> +#include <cassert> +#include "DefaultOnly.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list<DefaultOnly, min_allocator<DefaultOnly>> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list<int, min_allocator<int>> l((min_allocator<int>())); + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list<int> l = {}; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..f821fb4e7bb --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/default_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list() +// noexcept(is_nothrow_default_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp new file mode 100644 index 00000000000..9d9946b6896 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// explicit list(const Alloc& = Alloc()); + +#include <list> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list<int, min_allocator<int>> l((min_allocator<int>())); + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..13c7e5b5797 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// ~list() // implied noexcept; + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..3307017989e --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(initializer_list<value_type> il); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> d = {3, 4, 5, 6}; + assert(d.size() == 4); + std::list<int, min_allocator<int>>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..4a85e378c1c --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <list> +#include <cassert> + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> d({3, 4, 5, 6}, min_allocator<int>()); + assert(d.get_allocator() == min_allocator<int>()); + assert(d.size() == 4); + std::list<int, min_allocator<int>>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp new file mode 100644 index 00000000000..09eae8ab43c --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class InputIterator> +// list(InputIterator first, InputIterator last, const Allocator& = Allocator()); + +#include <list> +#include <cassert> +#include "test_iterators.h" +#include "../../../stack_allocator.h" +#include "min_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); + } +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3}; + std::list<int, min_allocator<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, min_allocator<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, min_allocator<int>> l(input_iterator<const int*>(a), + input_iterator<const int*>(a + sizeof(a)/sizeof(a[0])), + min_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, min_allocator<int>>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/move.pass.cpp new file mode 100644 index 00000000000..44782b91075 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/move.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(list&& c); + +#include <list> +#include <cassert> +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } +#if __cplusplus >= 201103L + { + std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::list<int> l1 = {1, 2, 3}; + std::list<int>::iterator i = l1.begin(); + std::list<int> l2 = std::move(l1); + assert(*l2.erase(i) == 2); + assert(l2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..4730755db81 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/move_alloc.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(list&& c, const allocator_type& a); + +#include <list> +#include <cassert> +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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)); + } +#if __cplusplus >= 201103L + { + std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>()); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == min_allocator<MoveOnly>()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..d502e1c09c8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list& operator=(list&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value); + +// This tests a conforming extension + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::list<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::list<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::list<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..2c10443f76b --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/move_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(list&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::list<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..7b7b8a327b8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list& operator=(initializer_list<value_type> il); + +#include <list> +#include <cassert> +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + std::list<int, min_allocator<int>>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/size_type.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/size_type.pass.cpp new file mode 100644 index 00000000000..75b93a3dfb6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/size_type.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// explicit list(size_type n); + +#include <list> +#include <cassert> +#include "DefaultOnly.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +template <class T, class Allocator> +void +test3(unsigned n, Allocator const &alloc = Allocator()) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::list<T, Allocator> C; + typedef typename C::const_iterator const_iterator; + { + C d(n, alloc); + assert(d.size() == n); + assert(std::distance(d.begin(), d.end()) == n); + assert(d.get_allocator() == alloc); + } +#endif +} + + +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); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::list<int, min_allocator<int> > C; + C l(3, min_allocator<int> ()); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + C::const_iterator i = l.begin(); + assert(*i == 0); + ++i; + assert(*i == 0); + ++i; + assert(*i == 0); + test3<int, min_allocator<int>> (3); + } +#endif +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list<DefaultOnly> l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list<int, min_allocator<int>>::const_iterator i = l.begin(); + assert(*i == 0); + ++i; + assert(*i == 0); + ++i; + assert(*i == 0); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list<DefaultOnly, min_allocator<DefaultOnly>> l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..12da86da0a4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// list(size_type n, const T& value, const Allocator& = Allocator()); + +#include <list> +#include <cassert> +#include "DefaultOnly.h" +#include "../../../stack_allocator.h" +#include "min_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); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l(3, 2); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list<int, min_allocator<int>>::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<int>> l(3, 2, min_allocator<int>()); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list<int, min_allocator<int>>::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..38696b6eb50 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void clear(); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + int a[] = {1, 2, 3}; + std::list<int> c(a, a+3); + c.clear(); + assert(c.empty()); + } +#if __cplusplus >= 201103L + { + int a[] = {1, 2, 3}; + std::list<int, min_allocator<int>> c(a, a+3); + c.clear(); + assert(c.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..6476d1d6c6a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class... Args> void emplace(const_iterator p, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<A> c1; + std::list<A> c2; + std::list<A>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list<A, min_allocator<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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<A, min_allocator<A>> c1; + std::list<A, min_allocator<A>> c2; + std::list<A, min_allocator<A>>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..5983efc59ad --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_back.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class... Args> void emplace_back(Args&&... args); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + std::list<A, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_front.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..e2e68e33138 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_front.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class... Args> void emplace_front(Args&&... args); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + std::list<A, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..c1cc9004367 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator erase(const_iterator position); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<int>>::const_iterator i = l1.begin(); + ++i; + std::list<int, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..18c15eb02c8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <cstdlib> +#include <exception> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<int>>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..61ff8409c96 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <cstdlib> +#include <exception> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int> l2(a1, a1+3); + std::list<int>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<int>> l2(a1, a1+3); + std::list<int, min_allocator<int>>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..bd3f66b4116 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator erase(const_iterator first, const_iterator last); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<int>>(a1+1, a1+3))); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<int>>(a1+2, a1+3))); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..71ad497e7d9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int> l2(a1, a1+3); + std::list<int>::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<int>> l2(a1, a1+3); + std::list<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..db76b4de486 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int> l2(a1, a1+3); + std::list<int>::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<int>> l2(a1, a1+3); + std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..25c5c6147a0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int> l2(a1, a1+3); + std::list<int>::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<int>> l2(a1, a1+3); + std::list<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..35a4ceb4848 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <list> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list<int> l1(a1, a1+3); + std::list<int>::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<int>>::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..a82a2696e82 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> d(10, 1); + std::list<int, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..d69deac36a9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,185 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <InputIterator Iter> +// iterator insert(const_iterator position, Iter first, Iter last); + +// UNSUPPORTED: asan, msan + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cstdlib> +#include <cassert> +#include "test_iterators.h" +#include "min_allocator.h" + +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); + } + throw_next = 0xFFFF; +#if _LIBCPP_DEBUG >= 1 + { + std::list<int> v(100); + std::list<int> v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::list<int>::iterator i = v.insert(next(v2.cbegin(), 10), input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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); + } +#if _LIBCPP_DEBUG >= 1 + { + throw_next = 0xFFFF; + std::list<int, min_allocator<int>> v(100); + std::list<int, min_allocator<int>> v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::list<int, min_allocator<int>>::iterator i = v.insert(next(v2.cbegin(), 10), input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp new file mode 100644 index 00000000000..27d0411fb04 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator insert(const_iterator position, value_type&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + std::list<int> v1(3); + std::list<int> v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#if __cplusplus >= 201103L +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list<MoveOnly, min_allocator<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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + std::list<int, min_allocator<int>> v1(3); + std::list<int, min_allocator<int>> v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..a552e1f8360 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +// UNSUPPORTED: asan, msan + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cstdlib> +#include <cassert> + +#include "min_allocator.h" + +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)); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int> c1(100); + std::list<int> c2; + std::list<int>::iterator i = c1.insert(next(c2.cbegin(), 10), 5, 1); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + int a2[] = {1, 4, 4, 4, 4, 4, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<int>>::iterator i = l1.insert(next(l1.cbegin()), 5, 4); + assert(i == next(l1.begin())); + assert((l1 == std::list<int, min_allocator<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, min_allocator<int>>(a2, a2+8))); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int, min_allocator<int>> c1(100); + std::list<int, min_allocator<int>> c2; + std::list<int, min_allocator<int>>::iterator i = c1.insert(next(c2.cbegin(), 10), 5, 1); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..093ad423cf8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// iterator insert(const_iterator position, const value_type& x); + +// UNSUPPORTED: asan, msan + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cstdlib> +#include <cassert> + +#include "min_allocator.h" + +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)); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int> v1(3); + std::list<int> v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + int a2[] = {1, 4, 2, 3}; + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<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, min_allocator<int>>(a2, a2+4))); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int, min_allocator<int>> v1(3); + std::list<int, min_allocator<int>> v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/pop_back.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..3add8518809 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/pop_back.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void pop_back(); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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()); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#if __cplusplus >= 201103L + { + int a[] = {1, 2, 3}; + std::list<int, min_allocator<int>> c(a, a+3); + c.pop_back(); + assert((c == std::list<int, min_allocator<int>>(a, a+2))); + c.pop_back(); + assert((c == std::list<int, min_allocator<int>>(a, a+1))); + c.pop_back(); + assert(c.empty()); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/pop_front.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..aec17cc08f4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/pop_front.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void pop_front(); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + int a[] = {1, 2, 3}; + std::list<int, min_allocator<int>> c(a, a+3); + c.pop_front(); + assert((c == std::list<int, min_allocator<int>>(a+1, a+3))); + c.pop_front(); + assert((c == std::list<int, min_allocator<int>>(a+2, a+3))); + c.pop_front(); + assert(c.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_back.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..2638c541fa1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_back(const value_type& x); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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)); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<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, min_allocator<int>>(a, a+5))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp new file mode 100644 index 00000000000..9d3c05e26b1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_back(const value_type& x); + +#include <list> +#include <cassert> + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + private: int fMagicValue; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass() : + fMagicValue(kStartedConstructionMagicValue) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& /*iOther*/) : + fMagicValue(kStartedConstructionMagicValue) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +int main() +{ + CMyClass instance; + std::list<CMyClass> vec; + + vec.push_back(instance); + + gCopyConstructorShouldThow = true; + try { + vec.push_back(instance); + } + catch (...) { + } +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..070db9e8d6b --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_back(value_type&& x); + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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)); + } +#if __cplusplus >= 201103L + { + std::list<MoveOnly, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_front.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front.pass.cpp new file mode 100644 index 00000000000..b7f4febcd38 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_front(const value_type& x); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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)); + } +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<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, min_allocator<int>>(a, a+5))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp new file mode 100644 index 00000000000..6609005262e --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_front(const value_type& x); + +#include <list> +#include <cassert> + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + private: int fMagicValue; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass() : + fMagicValue(kStartedConstructionMagicValue) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& /*iOther*/) : + fMagicValue(kStartedConstructionMagicValue) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +int main() +{ + CMyClass instance; + std::list<CMyClass> vec; + + vec.push_front(instance); + + gCopyConstructorShouldThow = true; + try { + vec.push_front(instance); + } + catch (...) { + } +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp new file mode 100644 index 00000000000..8a3175504eb --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void push_front(value_type&& x); + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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)); + } +#if __cplusplus >= 201103L + { + std::list<MoveOnly, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp new file mode 100644 index 00000000000..d226ed5dc64 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void merge(list& x); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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]))); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + c1.merge(c2); + assert((c1 == std::list<int, min_allocator<int>>(a3, a3+sizeof(a3)/sizeof(a3[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp new file mode 100644 index 00000000000..ce861a5dcb8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class Compare> void merge(list& x, Compare comp); + +#include <list> +#include <functional> +#include <cassert> + +#include "min_allocator.h" + +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]))); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + c1.merge(c2, std::greater<int>()); + assert((c1 == std::list<int, min_allocator<int>>(a3, a3+sizeof(a3)/sizeof(a3[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp new file mode 100644 index 00000000000..f580c94ef48 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void remove(const value_type& value); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +struct S { + S(int i) : i_(new int(i)) {} + S(const S &rhs) : i_(new int(*rhs.i_)) {} + S& operator = (const S &rhs) { *i_ = *rhs.i_; return *this; } + ~S () { delete i_; i_ = NULL; } + bool operator == (const S &rhs) const { return *i_ == *rhs.i_; } + int get () const { return *i_; } + int *i_; + }; + + +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)); + } + { // LWG issue #526 + int a1[] = {1, 2, 1, 3, 5, 8, 11}; + int a2[] = { 2, 3, 5, 8, 11}; + std::list<int> c(a1, a1+7); + c.remove(c.front()); + assert(c == std::list<int>(a2, a2+5)); + } + { + int a1[] = {1, 2, 1, 3, 5, 8, 11, 1}; + int a2[] = { 2, 3, 5, 8, 11 }; + std::list<S> c; + for(int *ip = a1; ip < a1+8; ++ip) + c.push_back(S(*ip)); + c.remove(c.front()); + std::list<S>::const_iterator it = c.begin(); + for(int *ip = a2; ip < a2+5; ++ip, ++it) { + assert ( it != c.end()); + assert ( *ip == it->get()); + } + assert ( it == c.end ()); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {1, 2, 4}; + std::list<int, min_allocator<int>> c(a1, a1+4); + c.remove(3); + assert((c == std::list<int, min_allocator<int>>(a2, a2+3))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp new file mode 100644 index 00000000000..162919ed85d --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class Pred> void remove_if(Pred pred); + +#include <list> +#include <cassert> +#include <functional> + +#include "min_allocator.h" +#include "counting_predicates.hpp" + +bool even(int i) +{ + return i % 2 == 0; +} + +bool g(int i) +{ + return i < 3; +} + +typedef unary_counting_predicate<bool(*)(int), int> Predicate; + +int main() +{ + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {3, 4}; + std::list<int> c(a1, a1+4); + Predicate cp(g); + c.remove_if(std::ref(cp)); + assert(c == std::list<int>(a2, a2+2)); + assert(cp.count() == 4); + } + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {1, 3}; + std::list<int> c(a1, a1+4); + Predicate cp(even); + c.remove_if(std::ref(cp)); + assert(c == std::list<int>(a2, a2+2)); + assert(cp.count() == 4); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {3, 4}; + std::list<int, min_allocator<int>> c(a1, a1+4); + Predicate cp(g); + c.remove_if(std::ref(cp)); + assert((c == std::list<int, min_allocator<int>>(a2, a2+2))); + assert(cp.count() == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/reverse.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/reverse.pass.cpp new file mode 100644 index 00000000000..046453ae538 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/reverse.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void reverse(); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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]))); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.reverse(); + assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/sort.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/sort.pass.cpp new file mode 100644 index 00000000000..1c11227237a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/sort.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void sort(); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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]))); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.sort(); + assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/sort_comp.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/sort_comp.pass.cpp new file mode 100644 index 00000000000..28125ab83c0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/sort_comp.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class Compare> sort(Compare comp); + +#include <list> +#include <functional> +#include <cassert> + +#include "min_allocator.h" + +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]))); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.sort(std::greater<int>()); + assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list.pass.cpp new file mode 100644 index 00000000000..354871c20af --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list.pass.cpp @@ -0,0 +1,803 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void splice(const_iterator position, list& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int> v1(3); + std::list<int> v2(3); + v1.splice(v2.begin(), v2); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + } + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 1); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+2); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<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, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<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, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<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, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int, min_allocator<int>> v1(3); + std::list<int, min_allocator<int>> v2(3); + v1.splice(v2.begin(), v2); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp new file mode 100644 index 00000000000..5082c3f8517 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp @@ -0,0 +1,357 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void splice(const_iterator position, list<T,Allocator>& x, iterator i); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int> v1(3); + std::list<int> v2(3); + v1.splice(v1.begin(), v2, v1.begin()); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + } + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + i = l2.begin(); + assert(*i == 5); + } + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 5); + i = l2.begin(); + assert(*i == 4); + } + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + i = l2.begin(); + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 5); + i = l2.begin(); + assert(*i == 4); + ++i; + assert(*i == 6); + } + { + std::list<int, min_allocator<int>> l1; + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 6); + i = l2.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+1); + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + } + { + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 1); + } + { + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int, min_allocator<int>> v1(3); + std::list<int, min_allocator<int>> v2(3); + v1.splice(v1.begin(), v2, v1.begin()); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp new file mode 100644 index 00000000000..fcc4acceec5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp @@ -0,0 +1,237 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void splice(const_iterator position, list& x, iterator first, iterator last); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int> v1(3); + std::list<int> v2(3); + v1.splice(v1.begin(), v2, v2.begin(), v1.end()); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 1); + ++i; + assert(*i == 3); + } + { + std::list<int, min_allocator<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, min_allocator<int>>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 1); + } + { + std::list<int, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<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, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<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, min_allocator<int>> l1(a1, a1+3); + std::list<int, min_allocator<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, min_allocator<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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list<int, min_allocator<int>> v1(3); + std::list<int, min_allocator<int>> v2(3); + v1.splice(v1.begin(), v2, v2.begin(), v1.end()); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp new file mode 100644 index 00000000000..48cad1ddd15 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void unique(); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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)); + } +#if __cplusplus >= 201103L + { + int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; + int a2[] = {2, 1, 4, 3}; + std::list<int, min_allocator<int>> c(a1, a1+sizeof(a1)/sizeof(a1[0])); + c.unique(); + assert((c == std::list<int, min_allocator<int>>(a2, a2+4))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp new file mode 100644 index 00000000000..f8935b81f6a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class BinaryPred> void unique(BinaryPred pred); + +#include <list> +#include <cassert> + +#include "min_allocator.h" + +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)); + } +#if __cplusplus >= 201103L + { + int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; + int a2[] = {2, 1, 4, 3}; + std::list<int, min_allocator<int>> c(a1, a1+sizeof(a1)/sizeof(a1[0])); + c.unique(g); + assert((c == std::list<int, min_allocator<int>>(a2, a2+4))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.special/db_swap_1.pass.cpp b/libcxx/test/std/containers/sequences/list/list.special/db_swap_1.pass.cpp new file mode 100644 index 00000000000..f7171795cd5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.special/db_swap_1.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class T, class Alloc> +// void swap(list<T,Alloc>& x, list<T,Alloc>& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <list> +#include <cassert> + +#include <__debug> +#include "min_allocator.h" + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + 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])); + std::list<int>::iterator i1 = c1.begin(); + std::list<int>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::list<int>::iterator j = i1; + c1.erase(i1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::list<int, min_allocator<int>>::iterator i1 = c1.begin(); + std::list<int, min_allocator<int>>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::list<int, min_allocator<int>>::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/list/list.special/swap.pass.cpp new file mode 100644 index 00000000000..bc5f4857edc --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.special/swap.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// template <class T, class Alloc> +// void swap(list<T,Alloc>& x, list<T,Alloc>& y); + +#include <list> +#include <cassert> +#include "test_allocator.h" +#include "min_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); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + 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)); + } +#endif + { + 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)); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert((c2 == std::list<int, min_allocator<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, min_allocator<int>> c1(a1, a1); + std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert((c1 == std::list<int, min_allocator<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, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list<int, min_allocator<int>> c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert((c2 == std::list<int, min_allocator<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, min_allocator<int>> c1(a1, a1); + std::list<int, min_allocator<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); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef min_allocator<int> A; + std::list<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A()); + std::list<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A()); + swap(c1, c2); + assert((c1 == std::list<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A()); + assert((c2 == std::list<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A()); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..7a23398e80a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +// void swap(list& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); + +// This tests a conforming extension + +#include <list> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::list<MoveOnly, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::list<MoveOnly, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::list<MoveOnly, some_alloc<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/types.pass.cpp b/libcxx/test/std/containers/sequences/list/types.pass.cpp new file mode 100644 index 00000000000..95d7f5010f0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/types.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +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), ""); +#if __cplusplus >= 201103L + static_assert((std::is_same<std::list<int, min_allocator<int>>::value_type, int>::value), ""); + static_assert((std::is_same<std::list<int, min_allocator<int>>::allocator_type, min_allocator<int> >::value), ""); + static_assert((std::is_same<std::list<int, min_allocator<int>>::reference, int&>::value), ""); + static_assert((std::is_same<std::list<int, min_allocator<int>>::const_reference, const int&>::value), ""); + static_assert((std::is_same<std::list<int, min_allocator<int>>::pointer, min_pointer<int>>::value), ""); + static_assert((std::is_same<std::list<int, min_allocator<int>>::const_pointer, min_pointer<const int>>::value), ""); +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/version.pass.cpp b/libcxx/test/std/containers/sequences/list/version.pass.cpp new file mode 100644 index 00000000000..097c013f52c --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <list> + +#include <list> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/nothing_to_do.pass.cpp b/libcxx/test/std/containers/sequences/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/sequences/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/assign_copy.pass.cpp new file mode 100644 index 00000000000..9501799ae3d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/assign_copy.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(const vector& c); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool> > l(3, 2, min_allocator<bool>()); + std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<bool>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..2925fbc6674 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/assign_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void assign(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<bool> 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); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> 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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/assign_move.pass.cpp new file mode 100644 index 00000000000..df98c817fd5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/assign_move.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(vector&& c); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{}); + std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, min_allocator<bool> > l2(min_allocator<bool>{}); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/capacity.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/capacity.pass.cpp new file mode 100644 index 00000000000..63bff25f9f9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/capacity.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// size_type capacity() const; + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> v; + assert(v.capacity() == 0); + } + { + std::vector<bool, min_allocator<bool>> v(100); + assert(v.capacity() >= 100); + v.push_back(0); + assert(v.capacity() >= 101); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_default.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_default.pass.cpp new file mode 100644 index 00000000000..d3d6670bbf2 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_default.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// vector(const Alloc& = Alloc()); + +#include <vector> +#include <cassert> + +#include "test_allocator.h" +#include "min_allocator.h" + +template <class C> +void +test0() +{ + C c; + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == typename C::allocator_type()); +#if __cplusplus >= 201103L + C c1 = {}; + assert(c1.__invariants()); + assert(c1.empty()); + assert(c1.get_allocator() == typename C::allocator_type()); +#endif +} + +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)); + } +#if __cplusplus >= 201103L + { + test0<std::vector<bool, min_allocator<bool>> >(); + test1<std::vector<bool, min_allocator<bool> > >(min_allocator<bool>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter.pass.cpp new file mode 100644 index 00000000000..94e6801825d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// template <class InputIter> vector(InputIter first, InputIter last); + +#include <vector> +#include <cassert> + +#include "test_iterators.h" +#include "min_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() +{ + 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); +#if __cplusplus >= 201103L + test<std::vector<bool, min_allocator<bool>> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an)); + test<std::vector<bool, min_allocator<bool>> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an)); + test<std::vector<bool, min_allocator<bool>> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an)); + test<std::vector<bool, min_allocator<bool>> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an)); + test<std::vector<bool, min_allocator<bool>> >(a, an); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..ea9d41d342f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// template <class InputIter> vector(InputIter first, InputIter last, +// const allocator_type& a); + +#include <vector> +#include <cassert> + +#include "test_iterators.h" +#include "min_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() +{ + 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); + } +#if __cplusplus >= 201103L + { + min_allocator<bool> alloc; + test<std::vector<bool, min_allocator<bool>> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an), alloc); + test<std::vector<bool, min_allocator<bool>> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an), alloc); + test<std::vector<bool, min_allocator<bool>> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an), alloc); + test<std::vector<bool, min_allocator<bool>> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an), alloc); + test<std::vector<bool, min_allocator<bool>> >(a, an, alloc); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_size.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_size.pass.cpp new file mode 100644 index 00000000000..93ecbe87c38 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_size.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// explicit vector(size_type n); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "test_allocator.h" + +template <class C> +void +test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) +{ +#if _LIBCPP_STD_VER > 11 + C c(n, a); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} + +template <class C> +void +test1(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()); +} + +template <class C> +void +test(typename C::size_type n) +{ + test1<C> ( n ); + test2<C> ( n ); +} + +int main() +{ + test<std::vector<bool> >(50); +#if __cplusplus >= 201103L + test<std::vector<bool, min_allocator<bool>> >(50); + test2<std::vector<bool, test_allocator<bool>> >( 100, test_allocator<bool>(23)); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_size_value.pass.cpp new file mode 100644 index 00000000000..fc772f10dfc --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_size_value.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// vector(size_type n, const value_type& x); + +#include <vector> +#include <cassert> + +#include "min_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<bool> >(50, 3); +#if __cplusplus >= 201103L + test<std::vector<bool, min_allocator<bool>> >(50, 3); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp new file mode 100644 index 00000000000..6cca948ed83 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// vector(size_type n, const value_type& x, const allocator_type& a); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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>()); +#if __cplusplus >= 201103L + test<std::vector<bool, min_allocator<bool>> >(50, 3, min_allocator<bool>()); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/copy.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/copy.pass.cpp new file mode 100644 index 00000000000..58822782ff8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/copy.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// vector(const vector& v); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + 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, min_allocator<bool>>(a, an)); + } + { + std::vector<bool, min_allocator<bool> > v(3, 2, min_allocator<bool>()); + std::vector<bool, min_allocator<bool> > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp new file mode 100644 index 00000000000..2f0192b995a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(const vector& v, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<bool>>(a, an), min_allocator<bool>()); + } + { + std::vector<bool, min_allocator<bool> > l(3, 2, min_allocator<bool>()); + std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>()); + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<bool>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/default_noexcept.pass.cpp new file mode 100644 index 00000000000..b94588ead93 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/default_noexcept.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector<bool>() +// noexcept(is_nothrow_default_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<bool> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<bool, test_allocator<bool>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<bool, other_allocator<bool>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<bool, some_alloc<bool>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..682e74ef03c --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// ~vector<bool>() // implied noexcept; + +#include <vector> +#include <cassert> + +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<bool> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<bool, test_allocator<bool>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<bool, other_allocator<bool>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<bool, some_alloc<bool>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp new file mode 100644 index 00000000000..f3fd1e9926f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// template <class... Args> iterator emplace(const_iterator pos, Args&&... args); + +#include <vector> +#include <cassert> +#include "min_allocator.h" + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef std::vector<bool> C; + C c; + + C::iterator i = c.emplace(c.cbegin()); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front() == false); + + i = c.emplace(c.cend(), true); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front() == false); + assert(c.back() == true); + + i = c.emplace(c.cbegin()+1, 1 == 1); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front() == false); + assert(c[1] == true); + assert(c.back() == true); + } + { + typedef std::vector<bool, min_allocator<bool>> C; + C c; + + C::iterator i = c.emplace(c.cbegin()); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front() == false); + + i = c.emplace(c.cend(), true); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front() == false); + assert(c.back() == true); + + i = c.emplace(c.cbegin()+1, 1 == 1); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.size() == 3); + assert(c.front() == false); + assert(c[1] == true); + assert(c.back() == true); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp new file mode 100644 index 00000000000..57aa47822f8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector.bool + +// template <class... Args> void emplace_back(Args&&... args); + +#include <vector> +#include <cassert> +#include "min_allocator.h" + + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef std::vector<bool> C; + C c; + c.emplace_back(); + assert(c.size() == 1); + assert(c.front() == false); + c.emplace_back(true); + assert(c.size() == 2); + assert(c.front() == false); + assert(c.back() == true); + c.emplace_back(1 == 1); + assert(c.size() == 3); + assert(c.front() == false); + assert(c[1] == true); + assert(c.back() == true); + } + { + typedef std::vector<bool, min_allocator<bool>> C; + C c; + + c.emplace_back(); + assert(c.size() == 1); + assert(c.front() == false); + c.emplace_back(true); + assert(c.size() == 2); + assert(c.front() == false); + assert(c.back() == true); + c.emplace_back(1 == 1); + assert(c.size() == 3); + assert(c.front() == false); + assert(c[1] == true); + assert(c.back() == true); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/erase_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/erase_iter.pass.cpp new file mode 100644 index 00000000000..cbf26dd570a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/erase_iter.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// iterator erase(const_iterator position); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> l1(a1, a1+3); + std::vector<bool, min_allocator<bool>>::const_iterator i = l1.begin(); + ++i; + std::vector<bool, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..2c2c4cc4861 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/erase_iter_iter.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// iterator erase(const_iterator first, const_iterator last); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> l1(a1, a1+3); + std::vector<bool, min_allocator<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, min_allocator<bool>> l1(a1, a1+3); + std::vector<bool, min_allocator<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, min_allocator<bool>>(a1+1, a1+3))); + } + { + std::vector<bool, min_allocator<bool>> l1(a1, a1+3); + std::vector<bool, min_allocator<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, min_allocator<bool>>(a1+2, a1+3))); + } + { + std::vector<bool, min_allocator<bool>> l1(a1, a1+3); + std::vector<bool, min_allocator<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()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/find.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/find.pass.cpp new file mode 100644 index 00000000000..75567a9b7bb --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/find.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// std::find with vector<bool>::iterator + +// http://llvm.org/bugs/show_bug.cgi?id=16816 + +#include <vector> +#include <cassert> + +int main() +{ + { + for (unsigned i = 1; i < 256; ++i) + { + std::vector<bool> b(i,true); + std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), false); + assert(j-b.begin() == i); + assert(b.end() == j); + } + } + { + for (unsigned i = 1; i < 256; ++i) + { + std::vector<bool> b(i,false); + std::vector<bool>::iterator j = std::find(b.begin()+1, b.end(), true); + assert(j-b.begin() == i); + assert(b.end() == j); + } + } +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/initializer_list.pass.cpp new file mode 100644 index 00000000000..b9b46865449 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/initializer_list.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<bool> 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); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> 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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..aea3ad763cd --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <vector> +#include <cassert> + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<bool, test_allocator<bool>> d({true, false, false, true}, test_allocator<bool>(3)); + assert(d.get_allocator() == test_allocator<bool>(3)); + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> d({true, false, false, true}, min_allocator<bool>()); + assert(d.get_allocator() == min_allocator<bool>()); + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..c081cc81c59 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> d(10, true); + std::vector<bool, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..e51f8b589c7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,126 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// template <class Iter> +// iterator insert(const_iterator position, Iter first, Iter last); + +#include <vector> +#include <cassert> +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + std::vector<bool> v(100); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned 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 < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<bool> v(100); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned 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); + } + { + std::vector<bool> v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned 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() == sz + 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 < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<bool> v(100); + while(v.size() < v.capacity()) v.push_back(false); + v.pop_back(); v.pop_back(); v.pop_back(); + size_t sz = v.size(); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned 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() == sz + 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 < v.size(); ++j) + assert(v[j] == 0); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> v(100); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector<bool, min_allocator<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 < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<bool, min_allocator<bool>> v(100); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector<bool, min_allocator<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 < v.size(); ++j) + assert(v[j] == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..710ad4885f0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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 < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<bool> v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + 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 < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<bool> v(100); + while(v.size() < v.capacity()) v.push_back(false); + v.pop_back(); v.pop_back(); + size_t sz = v.size(); + std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + 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 < v.size(); ++j) + assert(v[j] == 0); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> v(100); + std::vector<bool, min_allocator<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 < v.size(); ++j) + assert(v[j] == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_iter_value.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..51c4626de0d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_value.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// iterator insert(const_iterator position, const value_type& x); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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 < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<bool> v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<bool> v(100); + while(v.size() < v.capacity()) v.push_back(false); + v.pop_back(); v.pop_back(); + size_t sz = v.size(); + std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> v(100); + std::vector<bool, min_allocator<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 < v.size(); ++j) + assert(v[j] == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp new file mode 100644 index 00000000000..c54fa4a80a9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include <vector> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +int main() +{ + { + typedef bool T; + typedef std::vector<T> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef bool T; + typedef std::vector<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 bool T; + typedef std::vector<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 bool T; + typedef std::vector<T> C; + C::iterator i; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef bool T; + typedef std::vector<T, min_allocator<T>> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef bool T; + typedef std::vector<T, min_allocator<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 bool T; + typedef std::vector<T, min_allocator<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 bool T; + typedef std::vector<T, min_allocator<T>> C; + C::iterator i; + C::const_iterator j; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + std::vector<bool>::iterator ii1{}, ii2{}; + std::vector<bool>::iterator ii4 = ii1; + std::vector<bool>::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp new file mode 100644 index 00000000000..e877292ced7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&& c); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{}); + std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, min_allocator<bool> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move_alloc.pass.cpp new file mode 100644 index 00000000000..deee9326197 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/move_alloc.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&& c, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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)); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{}); + std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector<bool, min_allocator<bool> > l2(std::move(l), min_allocator<bool>()); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == min_allocator<bool>()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..b580eb4ae3b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(vector&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<bool> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<bool, test_allocator<bool>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<bool, other_allocator<bool>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<bool, some_alloc<bool>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move_noexcept.pass.cpp new file mode 100644 index 00000000000..ab32bd0677b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/move_noexcept.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<bool> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<bool, test_allocator<bool>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<bool, other_allocator<bool>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<bool, some_alloc<bool>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..ef3dc5d1079 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/push_back.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/push_back.pass.cpp new file mode 100644 index 00000000000..c6b0fbf4185 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/push_back.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void push_back(const value_type& x); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + bool a[] = {0, 1, 1, 0, 1, 0, 0}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector<bool> 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]); + } + } +#if __cplusplus >= 201103L + { + bool a[] = {0, 1, 1, 0, 1, 0, 0}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector<bool, min_allocator<bool>> 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]); + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/reserve.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reserve.pass.cpp new file mode 100644 index 00000000000..be717a3be8a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/reserve.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void reserve(size_type n); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> v; + v.reserve(10); + assert(v.capacity() >= 10); + } + { + std::vector<bool, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/resize_size.pass.cpp new file mode 100644 index 00000000000..f75720c94ea --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/resize_size.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void resize(size_type sz); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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); + v.reserve(400); + v.resize(300); // check the case when resizing and we already have room + assert(v.size() == 300); + assert(v.capacity() >= 400); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<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); + v.reserve(400); + v.resize(300); // check the case when resizing and we already have room + assert(v.size() == 300); + assert(v.capacity() >= 400); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/resize_size_value.pass.cpp new file mode 100644 index 00000000000..8cecf44d2fb --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/resize_size_value.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void resize(size_type sz, const value_type& x); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() >= 100); + assert((v == std::vector<bool, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..1f9fcac3d9b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void shrink_to_fit(); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + std::vector<bool> v(100); + v.push_back(1); + v.shrink_to_fit(); + assert(v.capacity() >= 101); + assert(v.size() >= 101); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> v(100); + v.push_back(1); + v.shrink_to_fit(); + assert(v.capacity() >= 101); + assert(v.size() >= 101); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/swap.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/swap.pass.cpp new file mode 100644 index 00000000000..a92c6a6c165 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/swap.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// vector<bool> + +// void swap(vector& x); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_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)); + } + { + std::vector<bool> v(2); + std::vector<bool>::reference r1 = v[0]; + std::vector<bool>::reference r2 = v[1]; + r1 = true; + using std::swap; + swap(r1, r2); + assert(v[0] == false); + assert(v[1] == true); + } +#if __cplusplus >= 201103L + { + std::vector<bool, min_allocator<bool>> v1(100); + std::vector<bool, min_allocator<bool>> v2(200); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + } + { + typedef min_allocator<bool> A; + std::vector<bool, A> v1(100, true, A()); + std::vector<bool, A> v2(200, false, A()); + swap(v1, v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + assert(v1.get_allocator() == A()); + assert(v2.get_allocator() == A()); + } + { + std::vector<bool, min_allocator<bool>> v(2); + std::vector<bool, min_allocator<bool>>::reference r1 = v[0]; + std::vector<bool, min_allocator<bool>>::reference r2 = v[1]; + r1 = true; + using std::swap; + swap(r1, r2); + assert(v[0] == false); + assert(v[1] == true); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..bcaf161119f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void swap(vector& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<bool> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<bool, test_allocator<bool>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<bool, other_allocator<bool>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<bool, some_alloc<bool>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp new file mode 100644 index 00000000000..b266b3bbb92 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_allocator.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 std::allocator_traits<Allocator>::size_type>::value), ""); + static_assert((std::is_same<typename C::difference_type, typename std::allocator_traits<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), ""); +#if __cplusplus >= 201103L + test<min_allocator<bool> >(); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp new file mode 100644 index 00000000000..ea2262cd9c1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::vector<bool, min_allocator<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); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/asan.pass.cpp b/libcxx/test/std/containers/sequences/vector/asan.pass.cpp new file mode 100644 index 00000000000..86c02b29562 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/asan.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// reference operator[](size_type n); + +#include <vector> +#include <cassert> +#include <cstdlib> + +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_ASAN +extern "C" void __asan_set_error_exit_code(int); + +int main() +{ +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + c.reserve(2*c.size()); + T foo = c[c.size()]; // bad, but not caught by ASAN + } +#endif + + __asan_set_error_exit_code(0); + { + typedef int T; + typedef std::vector<T> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + c.reserve(2*c.size()); + assert(is_contiguous_container_asan_correct(c)); + assert(!__sanitizer_verify_contiguous_container ( c.data(), c.data() + 1, c.data() + c.capacity())); + T foo = c[c.size()]; // should trigger ASAN + assert(false); // if we got here, ASAN didn't trigger + } +} +#else +int main () { return 0; } +#endif diff --git a/libcxx/test/std/containers/sequences/vector/asan_throw.pass.cc b/libcxx/test/std/containers/sequences/vector/asan_throw.pass.cc new file mode 100644 index 00000000000..a1dce4a3b44 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/asan_throw.pass.cc @@ -0,0 +1,198 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Test asan vector annotations with a class that throws in a CTOR. + +#include <vector> +#include <cassert> + +#include "asan_testing.h" + +class X { +public: + X(const X &x) { Init(x.a); } + X(char arg) { Init(arg); } + X() { Init(42); } + X &operator=(const X &x) { + Init(x.a); + return *this; + } + void Init(char arg) { + if (arg == 42) + throw 0; + if (arg == 66) + arg = 42; + a = arg; + } + char get() const { return a; } + void set(char arg) { a = arg; } + +private: + char a; +}; + +void test_push_back() { + std::vector<X> v; + v.reserve(2); + v.push_back(X(2)); + assert(v.size() == 1); + try { + v.push_back(X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_emplace_back() { +#ifndef _LIBCPP_HAS_NO_VARIADICS + std::vector<X> v; + v.reserve(2); + v.push_back(X(2)); + assert(v.size() == 1); + try { + v.emplace_back(42); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +#endif // _LIBCPP_HAS_NO_VARIADICS +} + +void test_insert_range() { + std::vector<X> v; + v.reserve(4); + v.push_back(X(1)); + v.push_back(X(2)); + assert(v.size() == 2); + assert(v.capacity() >= 4); + try { + char a[2] = {21, 42}; + v.insert(v.end(), a, a + 2); + assert(0); + } catch (int e) { + assert(v.size() == 3); + } + assert(v.size() == 3); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_insert() { + std::vector<X> v; + v.reserve(3); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.insert(v.end(), X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 2); + } + assert(v.size() == 2); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_emplace() { +#ifndef _LIBCPP_HAS_NO_VARIADICS + std::vector<X> v; + v.reserve(3); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.emplace(v.end(), 42); + assert(0); + } catch (int e) { + assert(v.size() == 2); + } + assert(v.size() == 2); + assert(is_contiguous_container_asan_correct(v)); +#endif // _LIBCPP_HAS_NO_VARIADICS +} + +void test_insert_range2() { + std::vector<X> v; + v.reserve(4); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + assert(v.capacity() >= 4); + try { + char a[2] = {10, 42}; + v.insert(v.begin(), a, a + 2); + assert(0); + } catch (int e) { + assert(v.size() <= 4); + assert(is_contiguous_container_asan_correct(v)); + return; + } + assert(0); +} + +void test_insert_n() { + std::vector<X> v; + v.reserve(10); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.insert(v.begin(), 1, X(66)); + assert(0); + } catch (int e) { + assert(v.size() <= 3); + assert(is_contiguous_container_asan_correct(v)); + return; + } + assert(0); +} + +void test_resize() { + std::vector<X> v; + v.reserve(3); + v.push_back(X(0)); + try { + v.resize(3); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_resize_param() { + std::vector<X> v; + v.reserve(3); + v.push_back(X(0)); + try { + v.resize(3, X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +int main() { + test_push_back(); + test_emplace_back(); + test_insert_range(); + test_insert(); + test_emplace(); + test_insert_range2(); + test_insert_n(); + test_resize(); + test_resize_param(); +} diff --git a/libcxx/test/std/containers/sequences/vector/const_value_type.pass.cpp b/libcxx/test/std/containers/sequences/vector/const_value_type.pass.cpp new file mode 100644 index 00000000000..e16e439dec4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/const_value_type.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector<const int> v; // an extension + +#include <vector> +#include <type_traits> + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + std::vector<const int> v = {1, 2, 3}; +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/db_back.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_back.pass.cpp new file mode 100644 index 00000000000..05f3d07712e --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_back.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call back() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_cback.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_cback.pass.cpp new file mode 100644 index 00000000000..5eb1a353e8b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_cback.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call back() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + const C c; + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const C c; + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_cfront.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_cfront.pass.cpp new file mode 100644 index 00000000000..5e54da1d444 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_cfront.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call front() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + const C c; + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const C c; + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_cindex.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_cindex.pass.cpp new file mode 100644 index 00000000000..133aa565282 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_cindex.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Index const vector out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + const C c(1); + assert(c[0] == 0); + assert(c[1] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + const C c(1); + assert(c[0] == 0); + assert(c[1] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_front.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_front.pass.cpp new file mode 100644 index 00000000000..388058fb315 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_front.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call front() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_index.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_index.pass.cpp new file mode 100644 index 00000000000..1daf076da67 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_index.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Index vector out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + assert(c[0] == 0); + c.clear(); + assert(c[0] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + assert(c[0] == 0); + c.clear(); + assert(c[0] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_2.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_2.pass.cpp new file mode 100644 index 00000000000..2d43843067b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_2.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Compare iterators from different containers with <. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c1; + C c2; + bool b = c1.begin() < c2.begin(); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c1; + C c2; + bool b = c1.begin() < c2.begin(); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_3.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_3.pass.cpp new file mode 100644 index 00000000000..051d66c3339 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_3.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Subtract iterators from different containers. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c1; + C c2; + int i = c1.begin() - c2.begin(); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c1; + C c2; + int i = c1.begin() - c2.begin(); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_4.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_4.pass.cpp new file mode 100644 index 00000000000..4c2aa628de1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_4.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Index iterator out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.begin(); + assert(i[0] == 0); + assert(i[1] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.begin(); + assert(i[0] == 0); + assert(i[1] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_5.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_5.pass.cpp new file mode 100644 index 00000000000..1b1090499c2 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_5.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Add to iterator out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.begin(); + i += 1; + assert(i == c.end()); + i = c.begin(); + i += 2; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.begin(); + i += 1; + assert(i == c.end()); + i = c.begin(); + i += 2; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_6.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_6.pass.cpp new file mode 100644 index 00000000000..424bc939b13 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_6.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Decrement iterator prior to begin. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_7.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..72cdb10cbc8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_7.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_8.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..7b898533197 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <iterator> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector<T> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<T>> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp b/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp new file mode 100644 index 00000000000..75a08287a86 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp @@ -0,0 +1,165 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include <vector> +#include <cassert> +#include <iterator> + +#include "min_allocator.h" + +struct A +{ + int first; + int second; +}; + +int main() +{ + { + typedef int T; + typedef std::vector<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::vector<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::vector<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::vector<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::vector<T> C; + C::iterator i; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector<T, min_allocator<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::vector<T, min_allocator<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::vector<T, min_allocator<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::vector<T, min_allocator<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::vector<T, min_allocator<T>> C; + C::iterator i; + C::const_iterator j; + } + { + typedef A T; + typedef std::vector<T, min_allocator<T>> C; + C c = {A{1, 2}}; + C::iterator i = c.begin(); + i->first = 3; + C::const_iterator j = i; + assert(j->first == 3); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::vector<int> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/types.pass.cpp b/libcxx/test/std/containers/sequences/vector/types.pass.cpp new file mode 100644 index 00000000000..3504de6f75d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/types.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_allocator.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), ""); +#if __cplusplus >= 201103L + static_assert((std::is_same<std::vector<int, min_allocator<int>>::value_type, int>::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::allocator_type, min_allocator<int> >::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::reference, int&>::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::const_reference, const int&>::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::pointer, min_pointer<int>>::value), ""); + static_assert((std::is_same<std::vector<int, min_allocator<int>>::const_pointer, min_pointer<const int>>::value), ""); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp new file mode 100644 index 00000000000..21082c839f5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// size_type capacity() const; + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v; + assert(v.capacity() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int> v(100); + assert(v.capacity() == 100); + v.push_back(0); + assert(v.capacity() > 101); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v; + assert(v.capacity() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, min_allocator<int>> v(100); + assert(v.capacity() == 100); + v.push_back(0); + assert(v.capacity() > 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp new file mode 100644 index 00000000000..4df5702f2ad --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void reserve(size_type n); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v; + v.reserve(10); + assert(v.capacity() >= 10); + assert(is_contiguous_container_asan_correct(v)); + } + { + 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); + assert(is_contiguous_container_asan_correct(v)); + } + { + 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); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v; + v.reserve(10); + assert(v.capacity() >= 10); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, min_allocator<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); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..a47c5131d8a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void resize(size_type sz); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<int> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, stack_allocator<int, 300> > v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly>> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..de5126b03d1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void resize(size_type sz, const value_type& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.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); + assert(is_contiguous_container_asan_correct(v)); + 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); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + assert((v == std::vector<int, min_allocator<int>>(50))); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + 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, min_allocator<int>> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..49ab9cc71de --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void shrink_to_fit(); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, stack_allocator<int, 401> > v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + { + std::vector<int, stack_allocator<int, 400> > v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 200); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp new file mode 100644 index 00000000000..f3d9289c36e --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void swap(vector& x); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v1(100); + std::vector<int> v2(200); + assert(is_contiguous_container_asan_correct(v1)); + assert(is_contiguous_container_asan_correct(v2)); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() == 200); + assert(is_contiguous_container_asan_correct(v1)); + assert(v2.size() == 100); + assert(v2.capacity() == 100); + assert(is_contiguous_container_asan_correct(v2)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v1(100); + std::vector<int, min_allocator<int>> v2(200); + assert(is_contiguous_container_asan_correct(v1)); + assert(is_contiguous_container_asan_correct(v2)); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() == 200); + assert(is_contiguous_container_asan_correct(v1)); + assert(v2.size() == 100); + assert(v2.capacity() == 100); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..6f02c3b7bc2 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(const vector& c); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>()); + std::vector<int, min_allocator<int> > l2(l, min_allocator<int>()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<int>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..f5c06b1a1bd --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void assign(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..d87ac8636b0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(vector&& c); + +#include <vector> +#include <cassert> +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + 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()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + 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)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + 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()); + assert(is_contiguous_container_asan_correct(l2)); + } +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{}); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp new file mode 100644 index 00000000000..75772bef78a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(const Alloc& = Alloc()); + +#include <vector> +#include <cassert> + +#include "test_allocator.h" +#include "../../../NotConstructible.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C> +void +test0() +{ + C c; + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c)); +#if __cplusplus >= 201103L + C c1 = {}; + assert(c1.__invariants()); + assert(c1.empty()); + assert(c1.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c1)); +#endif +} + +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); + assert(is_contiguous_container_asan_correct(c)); +} + +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()); + } +#if __cplusplus >= 201103L + { + test0<std::vector<int, min_allocator<int>> >(); + test0<std::vector<NotConstructible, min_allocator<NotConstructible>> >(); + test1<std::vector<int, min_allocator<int> > >(min_allocator<int>{}); + test1<std::vector<NotConstructible, min_allocator<NotConstructible> > > + (min_allocator<NotConstructible>{}); + } + { + std::vector<int, min_allocator<int> > v; + assert(v.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp new file mode 100644 index 00000000000..36e231acce1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class InputIter> vector(InputIter first, InputIter last); + +#include <vector> +#include <cassert> + +#include "test_iterators.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.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)); + assert(is_contiguous_container_asan_correct(c)); + 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); +#if __cplusplus >= 201103L + test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an)); + test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an)); + test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an)); + test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an)); + test<std::vector<int> >(a, an); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..7fa748a90d7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class InputIter> vector(InputIter first, InputIter last, +// const allocator_type& a); + +#include <vector> +#include <cassert> + +#include "test_iterators.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template <class C, class Iterator, class A> +void +test(Iterator first, Iterator last, const A& a) +{ + C c(first, last, a); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +#if __cplusplus >= 201103L + +template <class T> +struct implicit_conv_allocator : min_allocator<T> +{ + implicit_conv_allocator(void* p) {} + implicit_conv_allocator(const implicit_conv_allocator&) = default; +}; + +#endif + +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); + } +#if __cplusplus >= 201103L + { + 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]); + min_allocator<int> alloc; + test<std::vector<int, min_allocator<int>> >(input_iterator<const int*>(a), input_iterator<const int*>(an), alloc); + test<std::vector<int, min_allocator<int>> >(forward_iterator<const int*>(a), forward_iterator<const int*>(an), alloc); + test<std::vector<int, min_allocator<int>> >(bidirectional_iterator<const int*>(a), bidirectional_iterator<const int*>(an), alloc); + test<std::vector<int, min_allocator<int>> >(random_access_iterator<const int*>(a), random_access_iterator<const int*>(an), alloc); + test<std::vector<int, min_allocator<int>> >(a, an, alloc); + test<std::vector<int, implicit_conv_allocator<int>> >(a, an, nullptr); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp new file mode 100644 index 00000000000..e03389593f1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// explicit vector(size_type n); + +#include <vector> +#include <cassert> + +#include "DefaultOnly.h" +#include "min_allocator.h" +#include "test_allocator.h" +#include "asan_testing.h" + +template <class C> +void +test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) +{ +#if _LIBCPP_STD_VER > 11 + C c(n, a); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == a); + assert(is_contiguous_container_asan_correct(c)); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} + +template <class C> +void +test1(typename C::size_type n) +{ + C c(n); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c)); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} + +template <class C> +void +test(typename C::size_type n) +{ + test1<C> ( n ); + test2<C> ( n ); +} + +int main() +{ + test<std::vector<int> >(50); + test<std::vector<DefaultOnly> >(500); + assert(DefaultOnly::count == 0); +#if __cplusplus >= 201103L + test<std::vector<int, min_allocator<int>> >(50); + test<std::vector<DefaultOnly, min_allocator<DefaultOnly>> >(500); + test2<std::vector<DefaultOnly, test_allocator<DefaultOnly>> >( 100, test_allocator<DefaultOnly>(23)); + assert(DefaultOnly::count == 0); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp new file mode 100644 index 00000000000..5b6c4985704 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(size_type n, const value_type& x); + +#include <vector> +#include <cassert> + +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.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); + assert(is_contiguous_container_asan_correct(c)); + 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); +#if __cplusplus >= 201103L + test<std::vector<int, min_allocator<int>> >(50, 3); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp new file mode 100644 index 00000000000..c62b84104ab --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(size_type n, const value_type& x, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "min_allocator.h" +#include "asan_testing.h" + +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); + assert(is_contiguous_container_asan_correct(c)); + 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>()); +#if __cplusplus >= 201103L + test<std::vector<int, min_allocator<int>> >(50, 3, min_allocator<int>()); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp new file mode 100644 index 00000000000..677963deeb8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(const vector& v); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.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); + assert(is_contiguous_container_asan_correct(c)); +} + +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(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#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(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == other_allocator<int>(-2)); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + 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, min_allocator<int>>(a, an)); + } + { + std::vector<int, min_allocator<int> > v(3, 2, min_allocator<int>()); + std::vector<int, min_allocator<int> > v2 = v; + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..128328c2a7d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(const vector& v, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.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); + assert(is_contiguous_container_asan_correct(c)); +} + +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)); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<int>>(a, an), min_allocator<int>()); + } + { + std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>()); + std::vector<int, min_allocator<int> > l2(l, min_allocator<int>()); + assert(l2 == l); + assert(l2.get_allocator() == min_allocator<int>()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp new file mode 100644 index 00000000000..1a4a1898cc6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> +// class vector +// vector(); + +#include <vector> + +struct X +{ + std::vector<X> q; +}; + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..3fc33b68d39 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector() +// noexcept(is_nothrow_default_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..0d73e9ef4d4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// ~vector() // implied noexcept; + +#include <vector> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..7eb834ff387 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(initializer_list<value_type> il); + +#include <vector> +#include <cassert> +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int> d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..5d7ae884e38 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(initializer_list<value_type> il, const Allocator& a = allocator_type()); + +#include <vector> +#include <cassert> + +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d({3, 4, 5, 6}, min_allocator<int>()); + assert(d.get_allocator() == min_allocator<int>()); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp new file mode 100644 index 00000000000..bb61d54948b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&& c); + +#include <vector> +#include <cassert> +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + assert(is_contiguous_container_asan_correct(c1)); + std::vector<int>::const_iterator i = c1.begin(); + std::vector<int> c2 = std::move(c1); + assert(is_contiguous_container_asan_correct(c2)); + std::vector<int>::iterator j = c2.erase(i); + assert(*j == 3); + assert(is_contiguous_container_asan_correct(c2)); + } +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + assert(is_contiguous_container_asan_correct(c1)); + std::vector<int, min_allocator<int>>::const_iterator i = c1.begin(); + std::vector<int, min_allocator<int>> c2 = std::move(c1); + assert(is_contiguous_container_asan_correct(c2)); + std::vector<int, min_allocator<int>>::iterator j = c2.erase(i); + assert(*j == 3); + assert(is_contiguous_container_asan_correct(c2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..1923e68f75e --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&& c, const allocator_type& a); + +#include <vector> +#include <cassert> +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + 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)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5)); + std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + 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)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5)); + std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + 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)); + assert(is_contiguous_container_asan_correct(l2)); + } +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{}); + std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>()); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == min_allocator<MoveOnly>()); + assert(is_contiguous_container_asan_correct(l2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..158370f4e1a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(vector&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..a2e36ccdf08 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector(vector&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..592b7146276 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// vector& operator=(initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.data/data.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.data/data.pass.cpp new file mode 100644 index 00000000000..aed56bc0931 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.data/data.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// pointer data(); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, min_allocator<int>> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp new file mode 100644 index 00000000000..cb6062694e4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// const_pointer data() const; + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + const std::vector<int> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + const std::vector<int> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + const std::vector<int, min_allocator<int>> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + const std::vector<int, min_allocator<int>> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..8af6bdacd0a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class... Args> iterator emplace(const_iterator pos, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + } + { + 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); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<A> c1; + std::vector<A> c2; + std::vector<A>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<A, min_allocator<A>> c; + std::vector<A, min_allocator<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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<A, min_allocator<A>> c1; + std::vector<A, min_allocator<A>> c2; + std::vector<A, min_allocator<A>>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..bbf91a4255d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class... Args> void emplace_back(Args&&... args); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + } + { + 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); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + } +#if __cplusplus >= 201103L + { + std::vector<A, min_allocator<A>> c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp new file mode 100644 index 00000000000..85a47073bcb --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class... Args> iterator emplace(const_iterator pos, Args&&... args); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector<int> v; + v.reserve(3); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int> v; + v.reserve(4); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v; + v.reserve(3); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector<int, min_allocator<int>> v; + v.reserve(4); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..7a850edda27 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator erase(const_iterator position); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int>::const_iterator i = l1.begin(); + assert(is_contiguous_container_asan_correct(l1)); + ++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); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(is_contiguous_container_asan_correct(l1)); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>>::const_iterator i = l1.begin(); + assert(is_contiguous_container_asan_correct(l1)); + ++i; + std::vector<int, min_allocator<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); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(is_contiguous_container_asan_correct(l1)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..0478d24c79f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <cstdlib> +#include <exception> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..c394f197402 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <cstdlib> +#include <exception> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int> l2(a1, a1+3); + std::vector<int>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>> l2(a1, a1+3); + std::vector<int, min_allocator<int>>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..bfc18bc4864 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator erase(const_iterator first, const_iterator last); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + int a1[] = {1, 2, 3}; + { + std::vector<int> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + 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()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + 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)); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + 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)); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + 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()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<std::vector<int> > outer(2, std::vector<int>(1)); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + outer.erase(outer.begin(), outer.begin()); + assert(outer.size() == 2); + assert(outer[0].size() == 1); + assert(outer[1].size() == 1); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int, min_allocator<int>> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int, min_allocator<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, min_allocator<int>>(a1+1, a1+3))); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int, min_allocator<int>> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int, min_allocator<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, min_allocator<int>>(a1+2, a1+3))); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<int, min_allocator<int>> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector<int, min_allocator<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()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector<std::vector<int, min_allocator<int>>, min_allocator<std::vector<int, min_allocator<int>>>> outer(2, std::vector<int, min_allocator<int>>(1)); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + outer.erase(outer.begin(), outer.begin()); + assert(outer.size() == 2); + assert(outer[0].size() == 1); + assert(outer[1].size() == 1); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..af6d0f75789 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int> l2(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>> l2(a1, a1+3); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..eee2c66c5c8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int> l2(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>> l2(a1, a1+3); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..505067d05a1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int> l2(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>> l2(a1, a1+3); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..c7e4131cb49 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include <vector> +#include <cassert> +#include <exception> +#include <cstdlib> + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector<int> l1(a1, a1+3); + std::vector<int>::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin()); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector<int, min_allocator<int>> l1(a1, a1+3); + std::vector<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin()); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..30b80178801 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator p, initializer_list<value_type> il); + +#include <vector> +#include <cassert> + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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(is_contiguous_container_asan_correct(d)); + 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); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> d(10, 1); + std::vector<int, min_allocator<int>>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(is_contiguous_container_asan_correct(d)); + 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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..782437be87f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,190 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class Iter> +// iterator insert(const_iterator position, Iter first, Iter last); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "test_iterators.h" +#include "min_allocator.h" +#include "asan_testing.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(is_contiguous_container_asan_correct(v)); + 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(is_contiguous_container_asan_correct(v)); + 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); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + int a[] = {1, 2, 3, 4, 5}; + const unsigned 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() == sz + 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 < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + v.reserve(128); // force no reallocation + size_t sz = v.size(); + int a[] = {1, 2, 3, 4, 5}; + const unsigned 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() == sz + 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 < v.size(); ++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(is_contiguous_container_asan_correct(v)); + 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(is_contiguous_container_asan_correct(v)); + 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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int> v(100); + std::vector<int> v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int>::iterator i = v.insert(v2.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int, min_allocator<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(is_contiguous_container_asan_correct(v)); + 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, min_allocator<int>> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int, min_allocator<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(is_contiguous_container_asan_correct(v)); + 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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int, min_allocator<int>> v(100); + std::vector<int, min_allocator<int>> v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v2.cbegin() + 10, input_iterator<const int*>(a), + input_iterator<const int*>(a+N)); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp new file mode 100644 index 00000000000..cf3715ccb6f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator position, value_type&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly> v(100); + std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + 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(is_contiguous_container_asan_correct(v)); + 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()); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int> v1(3); + std::vector<int> v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly>> v(100); + std::vector<MoveOnly, min_allocator<MoveOnly>>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + 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()); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int, min_allocator<int>> v1(3); + std::vector<int, min_allocator<int>> v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..6997284f258 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.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(is_contiguous_container_asan_correct(v)); + 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> v(100); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + assert(is_contiguous_container_asan_correct(v)); + 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 < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + v.reserve(128); // force no reallocation + size_t sz = v.size(); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + assert(is_contiguous_container_asan_correct(v)); + 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 < v.size(); ++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(is_contiguous_container_asan_correct(v)); + 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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int> c1(100); + std::vector<int> c2; + std::vector<int>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + 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, min_allocator<int>> v(100); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + 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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int, min_allocator<int>> c1(100); + std::vector<int, min_allocator<int>> c2; + std::vector<int, min_allocator<int>>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..782e752157a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp @@ -0,0 +1,116 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// iterator insert(const_iterator position, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> v(100); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + 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> v(100); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector<int> v(100); + while(v.size() < v.capacity()) v.push_back(0); + v.pop_back(); v.pop_back(); // force no reallocation + size_t sz = v.size(); + std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++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(is_contiguous_container_asan_correct(v)); + 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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int> v1(3); + std::vector<int> v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> v(100); + std::vector<int, min_allocator<int>>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + 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); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector<int, min_allocator<int>> v1(3); + std::vector<int, min_allocator<int>> v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..62fa60103ba --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void pop_back(); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +#if _LIBCPP_DEBUG >= 1 +#include <cstdlib> +#include <exception> + +#endif + +int main() +{ + { + std::vector<int> c; + c.push_back(1); + assert(c.size() == 1); + c.pop_back(); + assert(c.size() == 0); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> c; + c.push_back(1); + assert(c.size() == 1); + c.pop_back(); + assert(c.size() == 0); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..eeeba6242d9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void push_back(const value_type& x); + +#include <vector> +#include <cassert> +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector<int> c; + c.push_back(0); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } +#if __cplusplus >= 201103L + { + std::vector<int, min_allocator<int>> c; + c.push_back(0); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp new file mode 100644 index 00000000000..6615a25a620 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void push_back(const value_type& x); + +#include <vector> +#include <cassert> + +#include "asan_testing.h" + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(int tag); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + bool equal(const CMyClass &rhs) const + { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; } + private: + int fMagicValue; + int fTag; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass(int tag) : + fMagicValue(kStartedConstructionMagicValue), fTag(tag) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& iOther) : + fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); } + +int main() +{ + CMyClass instance(42); + std::vector<CMyClass> vec; + + vec.push_back(instance); + std::vector<CMyClass> vec2(vec); + assert(is_contiguous_container_asan_correct(vec)); + assert(is_contiguous_container_asan_correct(vec2)); + + gCopyConstructorShouldThow = true; + try { + vec.push_back(instance); + } + catch (...) { + assert(vec==vec2); + assert(is_contiguous_container_asan_correct(vec)); + } +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..be488931263 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,111 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void push_back(value_type&& x); + +#include <vector> +#include <cassert> +#include "../../../MoveOnly.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector<MoveOnly> c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + 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); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } +#if __cplusplus >= 201103L + { + std::vector<MoveOnly, min_allocator<MoveOnly>> c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp new file mode 100644 index 00000000000..e7f6a0011e1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class T, class Alloc> +// void swap(vector<T,Alloc>& x, vector<T,Alloc>& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include <vector> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + 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])); + std::vector<int>::iterator i1 = c1.begin(); + std::vector<int>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + c1.erase(i1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::vector<int, min_allocator<int>>::iterator i1 = c1.begin(); + std::vector<int, min_allocator<int>>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + c1.erase(i1); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.special/swap.pass.cpp new file mode 100644 index 00000000000..27001aef744 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.special/swap.pass.cpp @@ -0,0 +1,187 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// template <class T, class Alloc> +// void swap(vector<T,Alloc>& x, vector<T,Alloc>& y); + +#include <vector> +#include <cassert> +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.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])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + 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]))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + 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])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + 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); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + 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); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + 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]))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + 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); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + 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)); + } +#endif + { + 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)); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + 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)); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert((c2 == std::vector<int, min_allocator<int>>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1); + std::vector<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector<int, min_allocator<int>> c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert((c2 == std::vector<int, min_allocator<int>>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector<int, min_allocator<int>> c1(a1, a1); + std::vector<int, min_allocator<int>> c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef min_allocator<int> A; + std::vector<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A()); + std::vector<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A()); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A()); + assert((c2 == std::vector<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A()); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..996712a33aa --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +// void swap(vector& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); + +// This tests a conforming extension + +#include <vector> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/version.pass.cpp b/libcxx/test/std/containers/sequences/vector/version.pass.cpp new file mode 100644 index 00000000000..2c4fa1263de --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <vector> + +#include <vector> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |