38#include <gtest/gtest.h>
51 static_assert(S::capacity() == 8);
52 static_assert(
sizeof(S) >= 8 *
sizeof(
int *));
53 static_assert(std::is_nothrow_default_constructible_v<S>);
54 static_assert(std::is_nothrow_copy_constructible_v<S>);
55 static_assert(std::is_nothrow_copy_assignable_v<S>);
56 static_assert(std::is_nothrow_move_constructible_v<S>);
57 static_assert(std::is_nothrow_move_assignable_v<S>);
58 static_assert(std::is_nothrow_swappable_v<S>);
63 int a = 1, b = 2, c = 3;
66 EXPECT_EQ(s.
size(), 0u);
68 EXPECT_EQ(s.
push(&a), &a);
72 EXPECT_EQ(s.
size(), 3u);
73 EXPECT_EQ(s.
top(), &c);
74 EXPECT_EQ(s.
top(0), &c);
75 EXPECT_EQ(s.
top(1), &b);
76 EXPECT_EQ(s.
top(2), &a);
77 EXPECT_EQ(s.
base(), &a);
80 EXPECT_EQ(cs.
top(), &c);
81 EXPECT_EQ(cs.
top(1), &b);
82 EXPECT_EQ(cs.
base(), &a);
84 EXPECT_EQ(s.
pop(), &c);
85 EXPECT_EQ(s.
top(), &b);
87 EXPECT_EQ(s.
pop(), &c);
88 EXPECT_EQ(s.
pop(), &a);
95 for (
int i = 1; i <= 5; ++i)
97 EXPECT_EQ(s.
popn(3), 3);
98 EXPECT_EQ(s.
size(), 2u);
99 EXPECT_EQ(s.
top(), 2);
100 EXPECT_EQ(s.
popn(2), 1);
111 EXPECT_EQ(s.
top(), 3);
115 EXPECT_EQ(s.
top(), 4);
127 EXPECT_EQ(b.
size(), 2u);
128 EXPECT_EQ(b.
pop(), 2);
129 EXPECT_EQ(a.
size(), 2u);
130 EXPECT_EQ(a.
top(), 2);
135 EXPECT_EQ(c.
size(), 2u);
136 EXPECT_EQ(c.
top(1), 1);
138 EXPECT_EQ(c.
size(), 2u);
150 EXPECT_EQ(a.
size(), 1u);
151 EXPECT_EQ(a.
top(), 9);
152 EXPECT_EQ(b.
size(), 3u);
153 EXPECT_EQ(b.
top(), 3);
154 EXPECT_EQ(b.
base(), 1);
157 EXPECT_EQ(b.
size(), 3u);
158 EXPECT_EQ(b.
top(), 3);
163 EXPECT_EQ(empty.
size(), 3u);
Stack of fixed capacity whose storage is inside the object.
size_t size() const noexcept
Return the number of items.
static constexpr size_t capacity() noexcept
Maximum number of items.
T pop() noexcept
Pop the top; the stack must not be empty.
T & push(const T &data) noexcept
Push a copy of data.
T & top() noexcept
Return a modifiable reference to the top; the stack must not be empty.
void clear() noexcept
See empty().
T popn(const size_t n) noexcept
Perform n pops in constant time.
bool is_empty() const noexcept
Return true if the stack is empty.
T & base() noexcept
Return a modifiable reference to the bottom; the stack must not be empty.
void empty() noexcept
Empty the stack.
void swap(InlineStack &s) noexcept
Exchange the items in use of s and this, in time O(size()).
Main namespace for Aleph-w library functions.
Stack implementations backed by dynamic or fixed arrays.