diff options
Diffstat (limited to 'test/std/containers/sequences/deque/deque.modifiers')
22 files changed, 2188 insertions, 0 deletions
diff --git a/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp new file mode 100644 index 0000000000000..7a0a2512ee2f2 --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp new file mode 100644 index 0000000000000..cf717c2e2f27e --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp new file mode 100644 index 0000000000000..becf94ffb4ef3 --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/erase_iter.invalidation.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/erase_iter.invalidation.pass.cpp new file mode 100644 index 0000000000000..49465cddaef7d --- /dev/null +++ b/test/std/containers/sequences/deque/deque.modifiers/erase_iter.invalidation.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. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator erase(const_iterator f) + +// Erasing items from the beginning or the end of a deque shall not invalidate iterators +// to items that were not erased. + +#include <deque> +#include <cassert> + +template <typename C> +void del_at_start(C c) +{ + typename C::iterator first = c.begin(); + typename C::iterator it1 = first + 1; + typename C::iterator it2 = c.end() - 1; + + c.erase (first); + + typename C::iterator it3 = c.begin(); + typename C::iterator it4 = c.end() - 1; + assert( it1 == it3); + assert( *it1 == *it3); + assert(&*it1 == &*it3); + assert( it2 == it4); + assert( *it2 == *it4); + assert(&*it2 == &*it4); +} + +template <typename C> +void del_at_end(C c) +{ + typename C::iterator first = c.end() - 1; + typename C::iterator it1 = c.begin(); + typename C::iterator it2 = first - 1; + + c.erase (first); + + typename C::iterator it3 = c.begin(); + typename C::iterator it4 = c.end() - 1; + assert( it1 == it3); + assert( *it1 == *it3); + assert(&*it1 == &*it3); + assert( it2 == it4); + assert( *it2 == *it4); + assert(&*it2 == &*it4); +} + +int main() +{ + std::deque<int> queue; + for (int i = 0; i < 20; ++i) + queue.push_back(i); + + while (queue.size() > 1) + { + del_at_start(queue); + del_at_end(queue); + queue.pop_back(); + } +} diff --git a/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp new file mode 100644 index 0000000000000..a45b75d25c9c2 --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.invalidation.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.invalidation.pass.cpp new file mode 100644 index 0000000000000..c785e264db06a --- /dev/null +++ b/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.invalidation.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. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// iterator erase(const_iterator f, const_iterator l) + +// Erasing items from the beginning or the end of a deque shall not invalidate iterators +// to items that were not erased. + + +#include <deque> +#include <cstdint> +#include <cassert> + +template <typename C> +void del_at_start(C c, size_t num) +{ + typename C::iterator first = c.begin(); + typename C::iterator last = first + num; + typename C::iterator it1 = last; + typename C::iterator it2 = c.end() - 1; + + c.erase (first, last); + + typename C::iterator it3 = c.begin(); + typename C::iterator it4 = c.end() - 1; + assert( it1 == it3); + assert( *it1 == *it3); + assert(&*it1 == &*it3); + assert( it2 == it4); + assert( *it2 == *it4); + assert(&*it2 == &*it4); +} + +template <typename C> +void del_at_end(C c, size_t num) +{ + typename C::iterator last = c.end(); + typename C::iterator first = last - num; + typename C::iterator it1 = c.begin(); + typename C::iterator it2 = first - 1; + + c.erase (first, last); + + typename C::iterator it3 = c.begin(); + typename C::iterator it4 = c.end() - 1; + assert( it1 == it3); + assert( *it1 == *it3); + assert(&*it1 == &*it3); + assert( it2 == it4); + assert( *it2 == *it4); + assert(&*it2 == &*it4); +} + + +int main() +{ + std::deque<int> queue; + for (int i = 0; i < 20; ++i) + queue.push_back(i); + + while (queue.size() > 1) + { + for (size_t i = 1; i < queue.size(); ++i) + { + del_at_start(queue, i); + del_at_end (queue, i); + } + queue.pop_back(); + } +} diff --git a/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 0000000000000..0576aca5c1a8c --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 0000000000000..5f7804023c7fe --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 0000000000000..ecb95d72a21ef --- /dev/null +++ b/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,295 @@ +//===----------------------------------------------------------------------===// +// +// The 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, const C& c0, const C& c2) +{ + { + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef input_iterator<CI> BCI; + C c1 = c0; + 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); + } + { + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef forward_iterator<CI> BCI; + C c1 = c0; + 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); + } + { + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef bidirectional_iterator<CI> BCI; + C c1 = c0; + 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/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp new file mode 100644 index 0000000000000..b7e73f2650281 --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp new file mode 100644 index 0000000000000..2737dfba7739a --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp new file mode 100644 index 0000000000000..fbbaad4f89e5e --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/pop_back.invalidation.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/pop_back.invalidation.pass.cpp new file mode 100644 index 0000000000000..1d84f73ccb56d --- /dev/null +++ b/test/std/containers/sequences/deque/deque.modifiers/pop_back.invalidation.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. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void pop_back() + +// Erasing items from the beginning or the end of a deque shall not invalidate iterators +// to items that were not erased. + +#include <deque> +#include <cassert> + +template <typename C> +void test(C c) +{ + typename C::iterator it1 = c.begin(); + typename C::iterator it2 = c.end() - 2; + + c.pop_back(); + + typename C::iterator it3 = c.begin(); + typename C::iterator it4 = c.end() - 1; + assert( it1 == it3); + assert( *it1 == *it3); + assert(&*it1 == &*it3); + assert( it2 == it4); + assert( *it2 == *it4); + assert(&*it2 == &*it4); +} + +int main() +{ + std::deque<int> queue; + for (int i = 0; i < 20; ++i) + queue.push_back(i); + + while (queue.size() > 1) + { + test(queue); + queue.pop_back(); + } +} diff --git a/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp new file mode 100644 index 0000000000000..b345faaf89e9f --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/pop_front.invalidation.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/pop_front.invalidation.pass.cpp new file mode 100644 index 0000000000000..78317f3a3f9ce --- /dev/null +++ b/test/std/containers/sequences/deque/deque.modifiers/pop_front.invalidation.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. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void pop_front() + +// Erasing items from the beginning or the end of a deque shall not invalidate iterators +// to items that were not erased. + +#include <deque> +#include <cassert> + +template <typename C> +void test(C c) +{ + typename C::iterator it1 = c.begin() + 1; + typename C::iterator it2 = c.end() - 1; + + c.pop_front(); + + typename C::iterator it3 = c.begin(); + typename C::iterator it4 = c.end() - 1; + assert( it1 == it3); + assert( *it1 == *it3); + assert(&*it1 == &*it3); + assert( it2 == it4); + assert( *it2 == *it4); + assert(&*it2 == &*it4); +} + +int main() +{ + std::deque<int> queue; + for (int i = 0; i < 20; ++i) + queue.push_back(i); + + while (queue.size() > 1) + { + test(queue); + queue.pop_back(); + } +} diff --git a/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp new file mode 100644 index 0000000000000..d570ec333715b --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp new file mode 100644 index 0000000000000..96df6097d9940 --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp new file mode 100644 index 0000000000000..8ad6b53f1b5fd --- /dev/null +++ b/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.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. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_back(const value_type& x); + +#include <deque> +#include "test_allocator.h" +#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); + assert(false); + } + catch (...) { + gCopyConstructorShouldThow = false; + assert(vec==vec2); + } + } + + { + typedef std::deque<CMyClass, test_allocator<CMyClass> > C; + C vec; + C vec2(vec); + + C::allocator_type::throw_after = 1; + try { + vec.push_back(instance); + assert(false); + } + catch (...) { + assert(vec==vec2); + } + } +} diff --git a/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 0000000000000..d4ab0d3e2f266 --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp new file mode 100644 index 0000000000000..4d6443b1f967e --- /dev/null +++ b/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/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp new file mode 100644 index 0000000000000..e01b2a224ffd3 --- /dev/null +++ b/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.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. +// +//===----------------------------------------------------------------------===// + +// <deque> + +// void push_front(const value_type& x); + +#include <deque> +#include <cassert> +#include "test_allocator.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::deque<CMyClass> vec; + + vec.push_front(instance); + std::deque<CMyClass> vec2(vec); + + gCopyConstructorShouldThow = true; + try { + vec.push_front(instance); + assert(false); + } + catch (...) { + gCopyConstructorShouldThow = false; + assert(vec==vec2); + } + } + + { + typedef std::deque<CMyClass, test_allocator<CMyClass> > C; + C vec; + C vec2(vec); + + C::allocator_type::throw_after = 1; + try { + vec.push_front(instance); + assert(false); + } + catch (...) { + assert(vec==vec2); + } + } +} diff --git a/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp b/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp new file mode 100644 index 0000000000000..ea91ec1b0a44c --- /dev/null +++ b/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 +} |
