Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make iterator_t std::input_iterator compatible
- Loading branch information
1 parent
707424a
commit 85c8600
Showing
7 changed files
with
112 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
#pragma once | ||
|
||
#include <memory> // std::unique_ptr | ||
#include <sqlite3.h> | ||
#include <type_traits> // std::integral_constant | ||
|
||
namespace sqlite_orm { | ||
|
||
/** | ||
* Guard class which finalizes `sqlite3_stmt` in dtor | ||
*/ | ||
struct statement_finalizer { | ||
sqlite3_stmt* stmt = nullptr; | ||
using statement_finalizer = | ||
std::unique_ptr<sqlite3_stmt, std::integral_constant<decltype(&sqlite3_finalize), sqlite3_finalize>>; | ||
|
||
statement_finalizer(decltype(stmt) stmt_) : stmt(stmt_) {} | ||
|
||
inline ~statement_finalizer() { | ||
sqlite3_finalize(this->stmt); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ namespace sqlite_orm { | |
} | ||
|
||
iterator_t<self> end() { | ||
return {nullptr, *this}; | ||
return {}; | ||
} | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <type_traits> | ||
#include <utility> | ||
#include <sqlite_orm/sqlite_orm.h> | ||
#include <catch2/catch.hpp> | ||
|
||
using namespace sqlite_orm; | ||
|
||
struct User { | ||
int id = 0; | ||
std::string name; | ||
}; | ||
|
||
TEST_CASE("iterator_t") { | ||
using storage = decltype(make_storage( | ||
"aPath", | ||
make_table("users", make_column("id", &User::id, primary_key()), make_column("name", &User::name)))); | ||
using iter = decltype(std::declval<storage>().iterate<User>().begin()); | ||
|
||
// weakly_incrementable | ||
static_assert(std::is_default_constructible_v<iter>, "needs to be default constructible"); | ||
static_assert(std::is_same_v<typename iter::difference_type, std::ptrdiff_t>, "needs to have difference_type"); | ||
static_assert(std::is_same_v<decltype(++std::declval<iter>()), iter&>, "needs to be incrementable"); | ||
using check = decltype(std::declval<iter>()++); | ||
|
||
// indirectly_readable | ||
static_assert(std::is_same_v<decltype(*std::declval<const iter>()), const User&>, | ||
"needs to be const dereferencable"); | ||
|
||
// input_iterator | ||
static_assert(std::is_same_v<typename iter::iterator_category, std::input_iterator_tag>, | ||
"needs to have iterator_category"); | ||
|
||
// sentinel | ||
static_assert(std::is_same_v<decltype(std::declval<const iter>() == std::declval<const iter>()), bool>, | ||
"supports equality checking"); | ||
} |