From 0a2765d5880a5a3e9c8c4bb97b9c7bbe882c913a Mon Sep 17 00:00:00 2001 From: MeanSquaredError <35379301+MeanSquaredError@users.noreply.github.com> Date: Sat, 31 Aug 2024 14:08:08 +0300 Subject: [PATCH] Make the result_t::iterator::operator++(int) return void in order to fix a bug and preserve compatibility with C++20 ranges. --- include/sqlpp11/result.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/include/sqlpp11/result.h b/include/sqlpp11/result.h index 58b0bd10..8c1bdae6 100644 --- a/include/sqlpp11/result.h +++ b/include/sqlpp11/result.h @@ -125,11 +125,16 @@ namespace sqlpp return *this; } - iterator operator++(int) + // It is quite difficult to implement a postfix increment operator that returns the old iterator + // because the underlying database results work in a stream fashion not allowing to return to + // previously-read rows. + // + // We need the postfix increment mostly for compatibility with C++20 ranges so we set the return + // type to "void" which is allowed for C++20 range iterators. + // + void operator++(int) { - auto previous_it = *this; - _result.next(_result_row.get()); - return previous_it; + ++*this; } std::reference_wrapper _result;