diff --git a/include/forfun/container/forward_list.hpp b/include/forfun/container/forward_list.hpp index bb5002f..872e871 100644 --- a/include/forfun/container/forward_list.hpp +++ b/include/forfun/container/forward_list.hpp @@ -10,6 +10,7 @@ #ifndef FORFUN_CONTAINER_FORWARD_LIST_HPP_ #define FORFUN_CONTAINER_FORWARD_LIST_HPP_ +#include #include #include @@ -59,12 +60,10 @@ class forward_list final { head_->next = aux; } + /// The behavior is undefined when popping the front of an empty container. auto pop_front() noexcept -> void { - if (head_ == nullptr) - { - return; - } + assert(head_ != nullptr); internal::forward_list_node* const aux{head_}; head_ = head_->next; diff --git a/src/forfun/container/list.cpp b/src/forfun/container/list.cpp index c8b0e3a..5837346 100644 --- a/src/forfun/container/list.cpp +++ b/src/forfun/container/list.cpp @@ -54,16 +54,10 @@ auto list::push_back(list::value_type value) noexcept(false) -> void end_->previous_ = n; } +/// The behavior is undefined when popping the back of an empty container. auto list::pop_back() noexcept -> void { - if (tail_ == end_) [[unlikely]] - { - assert(head_ == end_); - assert(size_ == size_type{}); - - return; - } - + assert(tail_ != end_); assert(size_ > size_type{}); assert(head_ != end_); diff --git a/test/container/forward_list_test.cpp b/test/container/forward_list_test.cpp index 0f2b533..49cafc0 100644 --- a/test/container/forward_list_test.cpp +++ b/test/container/forward_list_test.cpp @@ -91,15 +91,6 @@ TEST_CASE("Forward list", "[container][forward_list][dynamic_allocation]") REQUIRE_FALSE(forward_list.empty()); } - SECTION("Pop back one element out of empty list") - { - forfun::experimental::container::forward_list forward_list{}; - - forward_list.pop_front(); - - REQUIRE(forward_list.empty()); - } - SECTION("Pop back one element out of list of one element") { forfun::experimental::container::forward_list forward_list{}; diff --git a/test/container/list_test.cpp b/test/container/list_test.cpp index 4d42608..d591e25 100644 --- a/test/container/list_test.cpp +++ b/test/container/list_test.cpp @@ -151,16 +151,6 @@ TEST_CASE("Linked list", "[container][list][dynamic_allocation]") REQUIRE_FALSE(list.empty()); } - SECTION("Pop back one element out of empty list") - { - forfun::experimental::container::list list{}; - - list.pop_back(); - - REQUIRE(list.empty()); - REQUIRE(list.size() == std::size_t{0U}); - } - SECTION("Pop back one element out of list of one element") { forfun::experimental::container::list list{};