Skip to content

Commit

Permalink
Also add missing operators on row iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv committed Feb 29, 2020
1 parent b7d743c commit 4667612
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
- Fix possible crash in `connection::connection_string` (#290).
- Fix filtering of default values in `connection::connection_string` (#288).
- Deprecate `row::swap` and public inheritance of iterators from `row`.
- More copy/move constructors/assignments on result iterators.
- More copy/move/default constructors/assignments on result iterators.
- More copy/move/default constructors/assignments on row iterators.
7.0.3
- Fixed misreporting of broken connection as `sql_error` (#280).
- Replaced non-ASCII test texts with escape codes (#282, #283).
Expand Down
2 changes: 2 additions & 0 deletions include/pqxx/field.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public:
*/
field(row const &r, row_size_type c) noexcept;

field() = default;

/**
* @name Comparison
*/
Expand Down
11 changes: 10 additions & 1 deletion include/pqxx/row.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ public:
using difference_type = row_difference_type;
using reference = field;

const_row_iterator() = default;
const_row_iterator(row const &T, row_size_type C) noexcept : field{T, C} {}
const_row_iterator(field const &F) noexcept : field{F} {}
const_row_iterator(const_row_iterator const &) = default;
const_row_iterator(const_row_iterator &&) = default;

/**
* @name Dereferencing operators
Expand All @@ -230,6 +233,9 @@ public:
* @name Manipulations
*/
//@{
const_row_iterator &operator=(const_row_iterator const &) = default;
const_row_iterator &operator=(const_row_iterator &&) = default;

const_row_iterator operator++(int);
const_row_iterator &operator++()
{
Expand Down Expand Up @@ -313,7 +319,10 @@ public:
using value_type = iterator_type::value_type;
using reference = iterator_type::reference;

const_reverse_row_iterator(const_reverse_row_iterator const &r) = default;
const_reverse_row_iterator() = default;
const_reverse_row_iterator(const_reverse_row_iterator const &) = default;
const_reverse_row_iterator(const_reverse_row_iterator &&) = default;

explicit const_reverse_row_iterator(super const &rhs) noexcept :
const_row_iterator{rhs}
{
Expand Down
31 changes: 31 additions & 0 deletions test/unit/test_row.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,36 @@ void test_row()
}


void test_row_iterator()
{
pqxx::connection conn;
pqxx::work tx{conn};
pqxx::result rows{tx.exec("SELECT 1, 2, 3")};

auto i{rows[0].begin()};
PQXX_CHECK_EQUAL(i->as<int>(), 1, "Row iterator is wrong.");
auto i2{i};
PQXX_CHECK_EQUAL(i2->as<int>(), 1, "Row iterator copy is wrong.");
i2++;
PQXX_CHECK_EQUAL(i2->as<int>(), 2, "Row iterator increment is wrong.");
pqxx::row::const_iterator i3;
i3 = i2;
PQXX_CHECK_EQUAL(i3->as<int>(), 2, "Row iterator assignment is wrong.");

auto r{rows[0].rbegin()};
PQXX_CHECK_EQUAL(r->as<int>(), 3, "Row reverse iterator is wrong.");
auto r2{r};
PQXX_CHECK_EQUAL(r2->as<int>(), 3, "Row reverse iterator copy is wrong.");
r2++;
PQXX_CHECK_EQUAL(
r2->as<int>(), 2, "Row reverse iterator increment is wrong.");
pqxx::row::const_reverse_iterator r3;
r3 = r2;
PQXX_CHECK_EQUAL(
i3->as<int>(), 2, "Row reverse iterator assignment is wrong.");
}


PQXX_REGISTER_TEST(test_row);
PQXX_REGISTER_TEST(test_row_iterator);
} // namespace

0 comments on commit 4667612

Please sign in to comment.