Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions include/fast_io_dsal/impl/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ class list
}
[[nodiscard]] inline constexpr const_iterator end() const noexcept
{
return {__builtin_addressof(imp)};
return {const_cast<::fast_io::containers::details::list_node_common*>(__builtin_addressof(imp))};
}

[[nodiscard]] inline constexpr const_iterator cbegin() const noexcept
Expand All @@ -575,25 +575,26 @@ class list
}
[[nodiscard]] inline constexpr const_iterator cend() const noexcept
{
return {__builtin_addressof(imp)};
return {const_cast<::fast_io::containers::details::list_node_common*>(__builtin_addressof(imp))};
}

[[nodiscard]] inline constexpr reverse_iterator rend() noexcept
{
return reverse_iterator({imp.next});
}
[[nodiscard]] inline constexpr reverse_iterator rbegin() noexcept
{
return reverse_iterator({__builtin_addressof(imp)});
}

[[nodiscard]] inline constexpr reverse_iterator rend() noexcept
{
return reverse_iterator({imp.next});
}

[[nodiscard]] inline constexpr const_reverse_iterator rend() const noexcept
{
return const_reverse_iterator({imp.next});
}
[[nodiscard]] inline constexpr const_reverse_iterator rbegin() const noexcept
{
return const_reverse_iterator({__builtin_addressof(imp)});
return const_reverse_iterator({const_cast<::fast_io::containers::details::list_node_common*>(__builtin_addressof(imp))});
}

[[nodiscard]] inline constexpr const_reverse_iterator crend() const noexcept
Expand All @@ -602,7 +603,7 @@ class list
}
[[nodiscard]] inline constexpr const_reverse_iterator crbegin() const noexcept
{
return const_reverse_iterator({__builtin_addressof(imp)});
return const_reverse_iterator({const_cast<::fast_io::containers::details::list_node_common*>(__builtin_addressof(imp))});
}

[[nodiscard]] inline constexpr bool empty() const noexcept
Expand Down
174 changes: 174 additions & 0 deletions tests/0026.container/0002.list/list_iter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#include <fast_io_dsal/list.h>

struct X
{
int a;
};

void test_iter()
{
::fast_io::list<X> l{X{1}, X{2}, X{3}};

auto iter = l.begin();
{
auto &&value = *iter;
auto &&value2 = iter->a;
auto value3 = *iter++;

if (value.a != 1 || value2 != 1 || value3.a != 1)
{
::fast_io::fast_terminate();
}
}

++iter;

{
auto &&value = *iter;
auto &&value2 = iter->a;
auto value3 = *iter++;

if (value.a != 3 || value2 != 3 || value3.a != 3)
{
::fast_io::fast_terminate();
}
}

if (iter != l.end())
{
::fast_io::fast_terminate();
}
}

void test_iter2()
{
::fast_io::list<X> l{X{1}, X{2}, X{3}};

for (auto &&v : l)
{
if (v.a != 1 && v.a != 2 && v.a != 3)
{
::fast_io::fast_terminate();
}
}
}

void test_const_iter()
{
::fast_io::list<X> const l{X{1}, X{2}, X{3}};

auto iter = l.begin();
{
auto &&value = *iter;
auto &&value2 = iter->a;
auto value3 = *iter++;

if (value.a != 1 || value2 != 1 || value3.a != 1)
{
::fast_io::fast_terminate();
}
}

++iter;

{
auto &&value = *iter;
auto &&value2 = iter->a;
auto value3 = *iter++;

if (value.a != 3 || value2 != 3 || value3.a != 3)
{
::fast_io::fast_terminate();
}
}

if (iter != l.end())
{
::fast_io::fast_terminate();
}
}

void test_const_iter2()
{
::fast_io::list<X> const l{X{1}, X{2}, X{3}};

for (auto &&v : l)
{
if (v.a != 1 && v.a != 2 && v.a != 3)
{
::fast_io::fast_terminate();
}
}
}

void test_reverse_iter()
{
::fast_io::list<X> l{X{1}, X{2}, X{3}};
auto iter = l.rbegin();
{
auto &&value = *iter;
auto &&value2 = iter->a;
auto value3 = *iter++;

if (value.a != 3 || value2 != 3 || value3.a != 3)
{
::fast_io::fast_terminate();
}
}
{
auto &&value = *iter;
auto &&value2 = iter->a;
auto value3 = *iter++;

if (value.a != 2 || value2 != 2 || value3.a != 2)
{
::fast_io::fast_terminate();
}
}
++iter;
if (iter != l.rend())
{
::fast_io::fast_terminate();
}
}

void test_reverse_const_iter()
{
::fast_io::list<X> const l{X{1}, X{2}, X{3}};
auto iter = l.crbegin();
{
auto &&value = *iter;
auto &&value2 = iter->a;
auto value3 = *iter++;

if (value.a != 3 || value2 != 3 || value3.a != 3)
{
::fast_io::fast_terminate();
}
}
{
auto &&value = *iter;
auto &&value2 = iter->a;
auto value3 = *iter++;

if (value.a != 2 || value2 != 2 || value3.a != 2)
{
::fast_io::fast_terminate();
}
}
++iter;
if (iter != l.crend())
{
::fast_io::fast_terminate();
}
}

int main()
{
::test_iter();
::test_iter2();
::test_const_iter();
::test_const_iter2();
::test_reverse_iter();
::test_reverse_const_iter();
}