diff options
Diffstat (limited to 'test/std/containers/container.adaptors/stack')
31 files changed, 1129 insertions, 0 deletions
diff --git a/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp new file mode 100644 index 0000000000000..94899d4f1b540 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// explicit stack(const Alloc& a); + +#include <stack> +#include <cassert> + +#include "test_allocator.h" + +struct test + : private std::stack<int, std::deque<int, test_allocator<int> > > +{ + typedef std::stack<int, std::deque<int, test_allocator<int> > > base; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const container_type& c, const test_allocator<int>& a) : base(c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator<int> get_allocator() {return c.get_allocator();} +}; + +int main() +{ + test q(test_allocator<int>(3)); + assert(q.get_allocator() == test_allocator<int>(3)); +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp new file mode 100644 index 0000000000000..fe8622751c95c --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// stack(const container_type& c, const Alloc& a); + +#include <stack> +#include <cassert> + +#include "test_allocator.h" + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +typedef std::deque<int, test_allocator<int> > C; + +struct test + : public std::stack<int, C> +{ + typedef std::stack<int, C> base; + + explicit test(const test_allocator<int>& a) : base(a) {} + test(const container_type& c, const test_allocator<int>& a) : base(c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator<int> get_allocator() {return c.get_allocator();} +}; + +int main() +{ + C d = make<C>(5); + test q(d, test_allocator<int>(4)); + assert(q.get_allocator() == test_allocator<int>(4)); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.top() == d[d.size() - i - 1]); + q.pop(); + } +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp new file mode 100644 index 0000000000000..33cb4dd52b3c0 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// stack(const stack& q, const Alloc& a); + +#include <stack> +#include <cassert> + +#include "test_allocator.h" + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(int(i)); + return c; +} + +typedef std::deque<int, test_allocator<int> > C; + +template <class T> +struct test + : public std::stack<T, C> +{ + typedef std::stack<T, C> base; + typedef test_allocator<int> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(const test& q, const allocator_type& a) : base(q, a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +int main() +{ + test<int> q(make<C>(5), test_allocator<int>(4)); + test<int> q2(q, test_allocator<int>(5)); + assert(q2.get_allocator() == test_allocator<int>(5)); + assert(q2.size() == 5); +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp new file mode 100644 index 0000000000000..374aa996ffe3d --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// stack(const container_type& c, const Alloc& a); + +#include <stack> +#include <cassert> + +#include "test_allocator.h" +#include "MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque<MoveOnly, test_allocator<MoveOnly> > C; + +template <class T> +struct test + : public std::stack<T, C> +{ + typedef std::stack<T, C> base; + typedef test_allocator<MoveOnly> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test<MoveOnly> q(make<C>(5), test_allocator<MoveOnly>(4)); + assert(q.get_allocator() == test_allocator<MoveOnly>(4)); + assert(q.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp new file mode 100644 index 0000000000000..5fa5bd2a8bd21 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class Alloc> +// stack(stack&& q, const Alloc& a); + +#include <stack> +#include <cassert> + +#include "test_allocator.h" +#include "MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque<MoveOnly, test_allocator<MoveOnly> > C; + +template <class T> +struct test + : public std::stack<T, C> +{ + typedef std::stack<T, C> base; + typedef test_allocator<MoveOnly> allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test<MoveOnly> q(make<C>(5), test_allocator<MoveOnly>(4)); + test<MoveOnly> q2(std::move(q), test_allocator<MoveOnly>(5)); + assert(q2.get_allocator() == test_allocator<MoveOnly>(5)); + assert(q2.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/ctor_container.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/ctor_container.pass.cpp new file mode 100644 index 0000000000000..9dc05013e3dd4 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/ctor_container.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// explicit stack(const container_type& c); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::deque<int> d = make<std::deque<int> >(5); + std::stack<int> q(d); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.top() == d[d.size() - i - 1]); + q.pop(); + } +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp new file mode 100644 index 0000000000000..8673e06ce9306 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/ctor_copy.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack(const stack&) = default; + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::stack<int> q(make<std::deque<int> >(5)); + std::stack<int> q2 = q; + assert(q2 == q); +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/ctor_default.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/ctor_default.pass.cpp new file mode 100644 index 0000000000000..523cd6811893a --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/ctor_default.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack(); + +#include <stack> +#include <vector> +#include <cassert> + +#include "../../../stack_allocator.h" + +int main() +{ + std::stack<int, std::vector<int, stack_allocator<int, 10> > > q; + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/ctor_move.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/ctor_move.pass.cpp new file mode 100644 index 0000000000000..44fab41a6c557 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/ctor_move.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack(stack&& q); + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + std::stack<MoveOnly> q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp new file mode 100644 index 0000000000000..ab08da93831e6 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/ctor_rcontainer.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// explicit stack(container_type&& c); + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + assert(q.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp new file mode 100644 index 0000000000000..bab55863b55f4 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack() +// noexcept(is_nothrow_default_constructible<container_type>::value); + +// This tests a conforming extension + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp new file mode 100644 index 0000000000000..477bd57a6d102 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// ~stack() // implied noexcept; + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 0000000000000..dd836796dc170 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack& operator=(stack&& c) +// noexcept(is_nothrow_move_assignable<container_type>::value); + +// This tests a conforming extension + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp b/test/std/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp new file mode 100644 index 0000000000000..cfc660b36def0 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack(stack&&) +// noexcept(is_nothrow_move_constructible<container_type>::value); + +// This tests a conforming extension + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/assign_copy.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/assign_copy.pass.cpp new file mode 100644 index 0000000000000..38769e3fb0265 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/assign_copy.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack& operator=(const stack& q); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::stack<int> q(make<std::deque<int> >(5)); + std::stack<int> q2; + q2 = q; + assert(q2 == q); +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/assign_move.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/assign_move.pass.cpp new file mode 100644 index 0000000000000..75cbec1c47c8a --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/assign_move.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// stack& operator=(stack&& q); + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack<MoveOnly> q(make<std::deque<MoveOnly> >(5)); + std::stack<MoveOnly> q2; + q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp new file mode 100644 index 0000000000000..3573c220ece9f --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/emplace.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class... Args> void emplace(Args&&... args); + +#include <stack> +#include <cassert> + +#include "../../../Emplaceable.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack<Emplaceable> q; + q.emplace(1, 2.5); + q.emplace(2, 3.5); + q.emplace(3, 4.5); + assert(q.size() == 3); + assert(q.top() == Emplaceable(3, 4.5)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/empty.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/empty.pass.cpp new file mode 100644 index 0000000000000..a4f728174132e --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/empty.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// bool empty() const; + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.empty()); + q.push(1); + assert(!q.empty()); + q.pop(); + assert(q.empty()); +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/pop.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/pop.pass.cpp new file mode 100644 index 0000000000000..7ec1bf187ceae --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/pop.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void pop(); + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + assert(q.size() == 3); + assert(q.top() == 3); + q.pop(); + assert(q.size() == 2); + assert(q.top() == 2); + q.pop(); + assert(q.size() == 1); + assert(q.top() == 1); + q.pop(); + assert(q.size() == 0); +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/push.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/push.pass.cpp new file mode 100644 index 0000000000000..6d5c90890d2ee --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/push.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void push(const value_type& v); + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + q.push(1); + assert(q.size() == 1); + assert(q.top() == 1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); + q.push(3); + assert(q.size() == 3); + assert(q.top() == 3); +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/push_rv.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/push_rv.pass.cpp new file mode 100644 index 0000000000000..67d0ea3385f66 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/push_rv.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void push(value_type&& v); + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack<MoveOnly> q; + q.push(MoveOnly(1)); + assert(q.size() == 1); + assert(q.top() == MoveOnly(1)); + q.push(MoveOnly(2)); + assert(q.size() == 2); + assert(q.top() == MoveOnly(2)); + q.push(MoveOnly(3)); + assert(q.size() == 3); + assert(q.top() == MoveOnly(3)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/size.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/size.pass.cpp new file mode 100644 index 0000000000000..2d8024729332f --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/size.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// size_type size() const; + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.size() == 0); + q.push(1); + assert(q.size() == 1); +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/swap.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/swap.pass.cpp new file mode 100644 index 0000000000000..50a29c48aa2f2 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/swap.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void swap(stack& q); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack<int> q1 = make<std::stack<int> >(5); + std::stack<int> q2 = make<std::stack<int> >(10); + std::stack<int> q1_save = q1; + std::stack<int> q2_save = q2; + q1.swap(q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/top.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/top.pass.cpp new file mode 100644 index 0000000000000..6bde162e3ebb1 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/top.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// reference top(); + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + int& ir = q.top(); + assert(ir == 3); +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/top_const.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/top_const.pass.cpp new file mode 100644 index 0000000000000..8e43d05fc682a --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/top_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// const_reference top() const; + +#include <stack> +#include <cassert> + +int main() +{ + std::stack<int> q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + const std::stack<int>& cqr = q; + const int& cir = cqr.top(); + assert(cir == 3); +} diff --git a/test/std/containers/container.adaptors/stack/stack.defn/types.pass.cpp b/test/std/containers/container.adaptors/stack/stack.defn/types.pass.cpp new file mode 100644 index 0000000000000..afc5ebd537538 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.defn/types.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class T, class Container = deque<T>> +// class stack +// { +// public: +// typedef Container container_type; +// typedef typename container_type::value_type value_type; +// typedef typename container_type::reference reference; +// typedef typename container_type::const_reference const_reference; +// typedef typename container_type::size_type size_type; +// +// protected: +// container_type c; +// ... +// }; + +#include <stack> +#include <vector> +#include <type_traits> + +struct test + : private std::stack<int> +{ + test() + { + c.push_back(1); + } +}; + +struct C +{ + typedef int value_type; + typedef int& reference; + typedef const int& const_reference; + typedef int size_type; +}; + +int main() +{ + static_assert((std::is_same<std::stack<int>::container_type, std::deque<int> >::value), ""); + static_assert((std::is_same<std::stack<double, std::vector<int> >::container_type, std::vector<int> >::value), ""); + static_assert((std::is_same<std::stack<double, std::vector<int> >::value_type, int>::value), ""); + static_assert((std::is_same<std::stack<int>::reference, std::deque<int>::reference>::value), ""); + static_assert((std::is_same<std::stack<int>::const_reference, std::deque<int>::const_reference>::value), ""); + static_assert((std::is_same<std::stack<int>::size_type, std::deque<int>::size_type>::value), ""); + static_assert((std::uses_allocator<std::stack<int>, std::allocator<int> >::value), ""); + static_assert((!std::uses_allocator<std::stack<int, C>, std::allocator<int> >::value), ""); + test t; +} diff --git a/test/std/containers/container.adaptors/stack/stack.ops/eq.pass.cpp b/test/std/containers/container.adaptors/stack/stack.ops/eq.pass.cpp new file mode 100644 index 0000000000000..9b041f7f8d158 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.ops/eq.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class T, class Container> +// bool operator==(const stack<T, Container>& x,const stack<T, Container>& y); +// +// template <class T, class Container> +// bool operator!=(const stack<T, Container>& x,const stack<T, Container>& y); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack<int> q1 = make<std::stack<int> >(5); + std::stack<int> q2 = make<std::stack<int> >(10); + std::stack<int> q1_save = q1; + std::stack<int> q2_save = q2; + assert(q1 == q1_save); + assert(q1 != q2); + assert(q2 == q2_save); +} diff --git a/test/std/containers/container.adaptors/stack/stack.ops/lt.pass.cpp b/test/std/containers/container.adaptors/stack/stack.ops/lt.pass.cpp new file mode 100644 index 0000000000000..beb937d4c12e0 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.ops/lt.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class T, class Container> +// bool operator< (const stack<T, Container>& x,const stack<T, Container>& y); +// +// template <class T, class Container> +// bool operator> (const stack<T, Container>& x,const stack<T, Container>& y); +// +// template <class T, class Container> +// bool operator>=(const stack<T, Container>& x,const stack<T, Container>& y); +// +// template <class T, class Container> +// bool operator<=(const stack<T, Container>& x,const stack<T, Container>& y); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack<int> q1 = make<std::stack<int> >(5); + std::stack<int> q2 = make<std::stack<int> >(10); + assert(q1 < q2); + assert(q2 > q1); + assert(q1 <= q2); + assert(q2 >= q1); +} diff --git a/test/std/containers/container.adaptors/stack/stack.special/swap.pass.cpp b/test/std/containers/container.adaptors/stack/stack.special/swap.pass.cpp new file mode 100644 index 0000000000000..90371146dc0b7 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.special/swap.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// template <class T, class Container> +// void swap(stack<T, Container>& x, stack<T, Container>& y); + +#include <stack> +#include <cassert> + +template <class C> +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack<int> q1 = make<std::stack<int> >(5); + std::stack<int> q2 = make<std::stack<int> >(10); + std::stack<int> q1_save = q1; + std::stack<int> q2_save = q2; + swap(q1, q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp b/test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp new file mode 100644 index 0000000000000..80e024f5f1e07 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +// void swap(stack& c) +// noexcept(__is_nothrow_swappable<container_type>::value); + +// This tests a conforming extension + +#include <stack> +#include <cassert> + +#include "MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/test/std/containers/container.adaptors/stack/version.pass.cpp b/test/std/containers/container.adaptors/stack/version.pass.cpp new file mode 100644 index 0000000000000..339d0f4dda8f7 --- /dev/null +++ b/test/std/containers/container.adaptors/stack/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. +// +//===----------------------------------------------------------------------===// + +// <stack> + +#include <stack> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} |