diff --git a/include/fast_io_dsal/impl/deque.h b/include/fast_io_dsal/impl/deque.h index 24a2ef43..4fd47cbc 100644 --- a/include/fast_io_dsal/impl/deque.h +++ b/include/fast_io_dsal/impl/deque.h @@ -358,7 +358,7 @@ inline constexpr ::std::ptrdiff_t deque_iter_difference_common(::fast_io::contai { ::std::ptrdiff_t controllerdiff{a.controller_ptr - b.controller_ptr}; constexpr ::std::ptrdiff_t blocksizedf{static_cast<::std::ptrdiff_t>(::fast_io::containers::details::deque_block_size)}; - return controllerdiff * blocksizedf + (a.curr_ptr - b.begin_ptr) + (b.begin_ptr - b.curr_ptr); + return controllerdiff * blocksizedf + (a.curr_ptr - a.begin_ptr) + (b.begin_ptr - b.curr_ptr); } template @@ -366,7 +366,7 @@ inline constexpr ::std::size_t deque_iter_difference_unsigned_common(::fast_io:: { ::std::size_t controllerdiff{a.controller_ptr - b.controller_ptr}; constexpr ::std::size_t blocksizedf{::fast_io::containers::details::deque_block_size}; - return controllerdiff * blocksizedf + static_cast<::std::size_t>((a.curr_ptr - b.begin_ptr) + (b.begin_ptr - b.curr_ptr)); + return controllerdiff * blocksizedf + static_cast<::std::size_t>((a.curr_ptr - a.begin_ptr) + (b.begin_ptr - b.curr_ptr)); } template @@ -1776,8 +1776,8 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE requires ::std::constructible_from> inline constexpr insert_range_result insert_range_impl(size_type pos, R &&rg, size_type old_size) noexcept(::std::is_nothrow_constructible_v>) { - size_type const halfold_size{old_size >> 1u}; #if 0 + size_type const halfold_size{old_size >> 1u}; if constexpr(::std::ranges::sized_range) { size_type const rgsize{::std::ranges::size(rg)}; @@ -1785,31 +1785,13 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE else #endif { - size_type retpos; - iterator retit, rotfirst, rotmid, rotlast; - if (pos < halfold_size) - { - this->prepend_range(rg); - size_type const new_size{this->size()}; - size_type const inserted{new_size - old_size}; - auto bg{this->begin()}; - size_type newpos{pos + inserted}; - rotfirst = bg; - rotmid = bg + inserted; - retpos = newpos; - retit = rotlast = bg + newpos; - } - else - { - this->append_range(rg); - auto bg{this->begin()}; - rotfirst = retit = bg + pos; - rotmid = bg + old_size; - rotlast = this->end(); - retpos = pos; - } + this->append_range(rg); + auto bg{this->begin()}; + iterator rotfirst = bg + pos; + iterator rotmid = bg + old_size; + iterator rotlast = this->end(); ::fast_io::containers::rotate_for_fast_io_deque(rotfirst, rotmid, rotlast); - return {retpos, retit}; + return {pos, rotfirst}; } } @@ -1845,18 +1827,28 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE this->push_back(e); } } - +#if 0 +private: template <::std::ranges::range R> requires ::std::constructible_from> - inline constexpr void prepend_range(R &&rg) noexcept(::std::is_nothrow_constructible_v>) + inline constexpr size_type prepend_range_impl(R &&rg) noexcept(::std::is_nothrow_constructible_v>) { - // To do: cleanup code + size_type const old_size{this->size()}; for (auto &e : rg) { this->push_front(e); } + return this->size() - old_size; } - +public: + template <::std::ranges::range R> + requires ::std::constructible_from> + inline constexpr void prepend_range(R &&rg) noexcept(::std::is_nothrow_constructible_v>) + { + // To do: cleanup code + this->prepend_range_impl(::std::forward(rg)); + } +#endif inline constexpr ~deque() { diff --git a/tests/0026.container/0003.deque/insert_range.cc b/tests/0026.container/0003.deque/insert_range.cc index ee3569f4..2052e088 100644 --- a/tests/0026.container/0003.deque/insert_range.cc +++ b/tests/0026.container/0003.deque/insert_range.cc @@ -196,16 +196,16 @@ inline void test_insert_range_index() } // Helper to compare dq and ref - auto check_equal = [&](auto const &msg) { + auto check_equal = [&](auto const &msg, ::std::source_location src = ::std::source_location::current()) { if (dq.size() != ref.size()) { - ::fast_io::io::panicln("ERROR: size mismatch: ", msg); + ::fast_io::io::panicln(src, "\tERROR: size mismatch: ", msg); } for (::std::size_t i{}; i != dq.size(); ++i) { if (dq[i] != ref[i]) { - ::fast_io::io::panicln("ERROR: value mismatch at index ", i, " : ", msg); + ::fast_io::io::panicln(src, "\tERROR: value mismatch at index ", i, "\tdq[i]=", dq[i], "\tref[i]=", ref[i], " : ", msg); } } }; @@ -257,7 +257,7 @@ inline void test_insert_range_index() int main() { test_iterator_ops(); -#if 0 - test_insert_range_index(); +#if 1 + test_insert_range_index(); #endif } \ No newline at end of file