diff options
Diffstat (limited to 'test/std/containers/container.adaptors/stack/stack.defn')
12 files changed, 396 insertions, 0 deletions
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; +} |