Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarfovich committed Sep 14, 2024
1 parent 2520da5 commit 799be5b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
47 changes: 38 additions & 9 deletions HW3/cc_lib/include/cc/forward_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,31 @@ class ForwardListIterator
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = typename ForwardList::value_type;
using pointer = typename ForwardList::pointer;
using reference = typename ForwardList::reference;

public: // methods
ForwardListIterator() = default;
ForwardListIterator(const ForwardList* list);
ForwardListIterator(const ForwardList* list, details::Node* node);
//ForwardListIterator(ForwardList* list, details::Node* node);

bool operator==(const ForwardListIterator& rhs) const;
auto operator<=>(const ForwardListIterator&) const = default;
operator ForwardListIterator<const ForwardList>() const
{
return {list, node};
}


const ForwardList* getList() const{
return list;
}
bool operator==(const ForwardListIterator<const ForwardList>& rhs) const
{
return node == rhs.getNode() && list == rhs.getList();
}
//bool operator==(const ForwardListIterator<ForwardList>& rhs) { return node == rhs.node && list == rhs.list; }

//auto operator<=>(const ForwardListIterator&) const = default;
const value_type& operator*() const { return static_cast<details::DataNode<ForwardList::value_type>*>(node)->data; }
value_type& operator*() { return static_cast<details::DataNode<ForwardList::value_type>*>(node)->data; }
ForwardListIterator& operator++();
Expand Down Expand Up @@ -88,6 +105,19 @@ class ForwardList
std::size_t listSize = 0;
};

//template<typename T, typename U>
//bool operator==(const ForwardListIterator<ForwardList<T>>& lhs, const ForwardListIterator<ForwardList<U>>& rhs)
//{
// return lhs.node == rhs.node && lhs.list == rhs.list;
//}

//template<typename T, typename U>
//bool operator==(const ForwardListIterator<const ForwardList<T>>& lhs,
// const ForwardListIterator<const ForwardList<U>>& rhs)
//{
// return lhs.node == rhs.node && lhs.list == rhs.list;
//}

template<class ForwardList>
ForwardListIterator<ForwardList>& ForwardListIterator<ForwardList>::operator++()
{
Expand All @@ -114,11 +144,7 @@ ForwardListIterator<ForwardList>::ForwardListIterator(const ForwardList* aList,
{
}

template<class ForwardList>
bool ForwardListIterator<ForwardList>::operator==(const ForwardListIterator& rhs) const
{
return node == rhs.node && list == rhs.list;
}


template<typename T, typename Allocator>
ForwardList<T, Allocator>::ForwardList()
Expand Down Expand Up @@ -177,7 +203,10 @@ auto ForwardList<T, Allocator>::before_begin() noexcept -> iterator
template<typename T, typename Allocator>
auto ForwardList<T, Allocator>::cbefore_begin() const noexcept -> const_iterator
{
return { this, &head };
return {};
// return { this, &head };
//return ForwardListIterator<decltype(this)>{ this, &head };
//return { this, &head };
}

template<typename T, typename Allocator>
Expand All @@ -189,7 +218,7 @@ auto ForwardList<T, Allocator>::begin() noexcept -> iterator
template<typename T, typename Allocator>
auto ForwardList<T, Allocator>::cbegin() const noexcept -> const_iterator
{
return begin();
return std::next(cbefore_begin());
}

template<typename T, typename Allocator>
Expand Down
3 changes: 3 additions & 0 deletions HW3/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ int main()
}

cc::ForwardList<int> list;
if (list.cbegin() == list.begin() && list.begin() == list.cbegin()){
std::cout << "Yes\n";
}
//auto iter = list.begin();
//list.insert_after(iter, 77);

Expand Down
3 changes: 3 additions & 0 deletions HW3/tests/forward_list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ TEST(ForwardListTest, EraseInMiddle)
EXPECT_EQ(*std::next(iter), i );
list.erase_after(iter);
}

auto t = list.cbegin();
iter == t;
}

0 comments on commit 799be5b

Please sign in to comment.