-
Notifications
You must be signed in to change notification settings - Fork 1
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
2022/tuple-iteration-apply/ #75
Comments
Hi Bartlomiej. I was doing some iteration over tuple like last week too. |
This HelperCallable looks familiar, it looks like generic lambda,
But actually this is not a real problem -- since you have types (Args...) for printImpl to instantiate:
|
Thanks @iPMSoftware, I'll see your implementation. Do you have some different techniques used there? Thanks @PiotrNycz - unfortunately even with Args... it doesn't compile: |
@fenbf It compiles - you have just trivial error in functionname - see https://godbolt.org/z/WTscsnvnz |
@PiotrNycz ah, eh, wow! yes, that's the bug :) Thanks for pointing this out, I'll update the article |
It is always nice to help. As a bonus, one idea how to print nicely all of these tuple elementa w/o extra additional lambda/function nor index:
|
Thanks @PiotrNycz I've just updated the article with a new section with that code. |
Everybody makes mistakes, including me ;) It should be |
@PiotrNycz heh :) Having an empty tuple is probably very rare, maybe it could be even solved by having some special function template specialization to report a warning in that case... or ignore it. It's probably only needed for generic code in some libraries. |
Here is a quite simple application, which mimics a stream of heterogeneous data and still works with the compatible sub-content. It uses what has been discussed in this post and
I tried to do this with
Any ideas on how to accomplish this with concepts? |
@tahsinkose In C++ a function template is not a thing you can pass as argument to other functions. You can pass function template instantiation (as well as objects, variables other functions (pointers to functions). Here -- you need to wrap this function template with lambda:
|
C++ Templates: How to Iterate through std::tuple: std::apply and More - C++ Stories
In the previous article on the tuple iteration, we covered the basics. As a result, we implemented a function template that took a tuple and could nicely print it to the output. There was also a version with operator <<.
Today we can go further and see some other techniques. The first one is with std::apply from C++17, a helper function for tuples.
https://www.cppstories.com/2022/tuple-iteration-apply/
The text was updated successfully, but these errors were encountered: