diff options
Diffstat (limited to 'asl')
-rw-r--r-- | asl/containers/buffer_tests.cpp | 8 | ||||
-rw-r--r-- | asl/containers/chunked_buffer.hpp | 6 | ||||
-rw-r--r-- | asl/containers/chunked_buffer_tests.cpp | 42 | ||||
-rw-r--r-- | asl/tests/types.hpp | 2 |
4 files changed, 53 insertions, 5 deletions
diff --git a/asl/containers/buffer_tests.cpp b/asl/containers/buffer_tests.cpp index dbb8fa9..fc2d6ba 100644 --- a/asl/containers/buffer_tests.cpp +++ b/asl/containers/buffer_tests.cpp @@ -442,16 +442,16 @@ ASL_TEST(move_assign_inline_to_heap) ASL_TEST_EXPECT(buf2.size() == 2); ASL_TEST_EXPECT(d[0] == false); ASL_TEST_EXPECT(d[1] == false); - ASL_TEST_EXPECT(d[2] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[3] == false); // moved but not destroyed + ASL_TEST_EXPECT(d[2] == true); + ASL_TEST_EXPECT(d[3] == true); ASL_TEST_EXPECT(d[4] == true); ASL_TEST_EXPECT(d[5] == true); } ASL_TEST_EXPECT(d[0] == true); ASL_TEST_EXPECT(d[1] == true); - ASL_TEST_EXPECT(d[2] == false); // moved but not destroyed - ASL_TEST_EXPECT(d[3] == false); // moved but not destroyed + ASL_TEST_EXPECT(d[2] == true); + ASL_TEST_EXPECT(d[3] == true); ASL_TEST_EXPECT(d[4] == true); ASL_TEST_EXPECT(d[5] == true); } diff --git a/asl/containers/chunked_buffer.hpp b/asl/containers/chunked_buffer.hpp index 3af7aa2..152ddd2 100644 --- a/asl/containers/chunked_buffer.hpp +++ b/asl/containers/chunked_buffer.hpp @@ -335,6 +335,12 @@ public: resize_uninit_inner(new_size); } + void pop() + { + ASL_ASSERT(size() > 0); + resize_uninit_inner(size() - 1); + } + template<typename Chunk> class generic_iterator { diff --git a/asl/containers/chunked_buffer_tests.cpp b/asl/containers/chunked_buffer_tests.cpp index 797f7f1..ba29bfb 100644 --- a/asl/containers/chunked_buffer_tests.cpp +++ b/asl/containers/chunked_buffer_tests.cpp @@ -135,6 +135,48 @@ ASL_TEST(push) } } +ASL_TEST(pop) +{ + asl::chunked_buffer<int, 2> b; + + for (int i = 0; i < 8; ++i) + { + b.push(i); + } + ASL_TEST_EXPECT(b.size() == 8); + + b.pop(); + ASL_TEST_EXPECT(b.size() == 7); + for (int i = 0; i < 7; ++i) + { + ASL_TEST_EXPECT(b[i] == i); + } +} + +ASL_TEST(pop_destruct) +{ + asl::chunked_buffer<DestructorObserver, 16> b; + bool d[3]; + + b.push(&d[0]); + b.push(&d[1]); + b.push(&d[2]); + + ASL_TEST_EXPECT(!d[0]); + ASL_TEST_EXPECT(!d[1]); + ASL_TEST_EXPECT(!d[2]); + + b.pop(); + ASL_TEST_EXPECT(!d[0]); + ASL_TEST_EXPECT(!d[1]); + ASL_TEST_EXPECT(d[2]); + + b.pop(); + ASL_TEST_EXPECT(!d[0]); + ASL_TEST_EXPECT(d[1]); + ASL_TEST_EXPECT(d[2]); +} + ASL_TEST(clear_destroy) { bool destroyed[5]{}; diff --git a/asl/tests/types.hpp b/asl/tests/types.hpp index d47c237..d608e8e 100644 --- a/asl/tests/types.hpp +++ b/asl/tests/types.hpp @@ -77,7 +77,7 @@ struct DestructorObserver { if (this != &other) { - destroyed = asl::exchange(other.destroyed, nullptr); + asl::swap(destroyed, other.destroyed); } return *this; } |