Skip to content

Commit

Permalink
refactor: Remove forward_list dependency on GSL
Browse files Browse the repository at this point in the history
  • Loading branch information
oboukli committed Nov 10, 2024
1 parent a053c11 commit d53cc4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
17 changes: 8 additions & 9 deletions include/forfun/container/forward_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#define FORFUN_CONTAINER_FORWARD_LIST_HPP_

#include <concepts>

#include <gsl/pointers>
#include <utility>

#include "forfun/container/internal/forward_list_node.hpp"

Expand Down Expand Up @@ -48,11 +47,12 @@ class forward_list final {
return head_ == nullptr;
}

auto push_front(T&& value) noexcept -> void
auto push_front(T&& value) -> void
{
internal::forward_list_node<T>* const aux{head_};

head_ = new internal::forward_list_node<T>(value);
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
head_ = new internal::forward_list_node<T>(std::move(value));

head_->next = aux;
}
Expand All @@ -64,21 +64,20 @@ class forward_list final {
return;
}

gsl::owner<internal::forward_list_node<T>*> const aux{head_};
internal::forward_list_node<T>* const aux{head_};
head_ = head_->next;

// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
delete aux;
}

auto clear() noexcept -> void
{
// clang-format off
for (gsl::owner<internal::forward_list_node<T>*> node = head_;
node != nullptr;)
// clang-format on
for (internal::forward_list_node<T>* node{head_}; node != nullptr;)
{
internal::forward_list_node<T>* const next = node->next;

// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
delete node;

node = next;
Expand Down
3 changes: 0 additions & 3 deletions test/container/forward_list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

// SPDX-License-Identifier: MIT

#include <cstddef>
#include <iterator>

#include <catch2/catch_test_macros.hpp>

#include "forfun/container/forward_list.hpp"
Expand Down

0 comments on commit d53cc4f

Please sign in to comment.