-
-
Notifications
You must be signed in to change notification settings - Fork 339
Iteration of result sets #1311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iteration of result sets #1311
Conversation
In addition, extensive unit tests have been added, especially conceptual tests.
What is the appropriate syntax for using iterate? iterate seems to need a Table type but that does not work for general selects!
|
@trueqbit, maybe a discussion for another place. But I'm trying to create a wrapper around
The error is: Any thoughts? |
The specific query you posted here does not return a view on a result set of a select statement, but a view on "mapped objects", so there is a mismatch between the error you described and the iterator method you used. The "mapped objects" view returns the same iterator type for start and end. Of course, I have no insight into the specifics of your application. However, nowadays there is a very nice way of type erasure that usually saves me from writing view or iterator adapters: range generators. You can have a function that returns a range generator of MarvelHeroS: std::generator<MarvelHero> query_heroes() {
for (MarvelHero hero : storage.iterate</*...*/>(/*...*/)) {
co_yield hero;
}
} I use the reference implementation of the C++ WG21 proposal P2168, which is available on Lewis' Repository. There are probably improved implementations since the C++ WG21 proposal P2502. |
@trevornagy
but I got compiled error cannot deduce template parameter 'T'. |
@juandent This has been an oversight on my side. Tracked in issue #1443, fixed with PR #1448.
@xiaopi-ouo This has been an oversight on my side. Tracked in your issue #1443, fixed with PR #1448. |
This PR introduces iteration over result sets of select statements (possibly with common table expressions).
Technically speaking, the feature consists of:
internal::result_set_view
.std::ranges::view
,std::ranges::borrowed_range
.internal::result_set_iterator
.std::input_iterator
.std::default_sentinel_t
is taken as a range sentinel.The feature currently requires a C++20 compiler, but can also be used with implementations of the C++14 standard library.
Additional changes:
internal::view_t
tointernal::mapped_view
internal::iterator_t
tointernal::mapped_iterator