Comments (16)
This is cool, I'm working on this now, I seem to have completed enumerate already. Thanks
from cppitertools.
Great! Btw, along the same lines, you might want to specialize for the different types of iterators. For instance I don't think your slice would work with maps since their iterators are not random_access. I did an implementation on my own (that's where I learned about that declval trick) and specialized the iterator "jump" depending on the type: for random access it's just += step, for bidirectionals move until hitting end() or the slice limit.
Oh, and last but not least: awesome code! :) Have you already posted it on reddit/r/cpp?
from cppitertools.
I'll have to look into slice (though I didn't write that one), but that's a good point thanks for pointing it out. A friend of mine posted this on reedit/cpp about a month ago, here: http://www.reddit.com/r/cpp/comments/1nhulu/python_itertools_and_builtin_iteration_functions/
If you mean you implemented the specialization on this, then we'd happily look at any pull requests. Thanks a lot for the interest
from cppitertools.
Nevermind about reddit: I just saw the post.
from cppitertools.
If you mean you implemented the specialization on this, then we'd happily look at any pull requests. Thanks a lot for the interest
Mine is a bit different, but I might add a modified version if I find the time this weekend :)
from cppitertools.
Ok cool, hopefully I'll have these updates done by then as well.
from cppitertools.
So 2 things.
- About halfway through the project I read that std::begin is now the preferred way to get an iterator, this should be relatively easy to fix though possibly even with just a regex.
- As for the map thing when I was cleaning up my code I noticed that some functions placed more requirements than others on the iterators. The ideal solution would be to use SFINAE to detect for things like random access and the appearance of certain methods, this somewhat tricky to do and I have a feeling that it would require some duplication of code. The good thing is that I think it would be needed for too many that only really need ++ != and *.
I think I'm going to open up a separate issue for this as it is significantly more complex than just adding std::begin everywhere
from cppitertools.
Yes, I agree. I would also replace Container
with Iterable
which better conveys the meaning of the data you're iterating on.
from cppitertools.
I started updating for std::begin
and std::end
and noticed that for std::cbegin
won't exist until c++14, I guess even the c++ standards committee forgets things, so I'm wondering if either of you had an opinion on this.
EDIT: same problem with rbegin
from cppitertools.
rbegin
and rend
can't really be relied on since the iteration protocol only requires a begin and end for iterable objects. For const objects, std::begin
should return a const iterator anyway. see: testenumerate.hpp where I was able to successfully use a const string
from cppitertools.
Well, given that you don't force constness on the template argument, I just assume std::begin
will pick up the correct one. In my tests with it I tried to iterate on both const variables and not (including references) and it worked.
from cppitertools.
We shouldn't be using cbegin
cause we want the user to be able to modify the iterable through the loop. As he said, std::begin
will pick const iterator if it has to
from cppitertools.
rbegin
andrend
can't really be relied on since the iteration protocol only requires a begin and end for iterable objects.
True, but it should be possible to "deduce" them as long as the iterator is bidirectional or random access. See this stackoverflow answer: http://stackoverflow.com/a/14468490/89640
from cppitertools.
The only ones that would want them would be the ones that already assume a .rbegin()
or .rend()
so that would be better. AFAIK slice
needs random access, sorted
needs an iterable that is non-exhaustible, and reverse
needs the .rbegin()
/.rend()
.
Part of my goal has been to require the least from Iterables as possible, only assuming just begin
end
increment, dereference, and !=, but I might have to start rethinking that.
and get rid of the boost dependency in zip_longest, but that's another story.
from cppitertools.
Hi guys,
With regards to the SFINAE to select for different iterator "concepts", you can use std::advance(). In fact, using the iterator manipulation functions defined in <iterator>
would make your classes more flexible. The others are distance, next, and prev.
http://en.cppreference.com/w/cpp/iterator
Be careful that you don't pass a negative index to advance, because then the iterators have to be BidirectionalIterators.
from cppitertools.
everything on the iterables has been modified to use std::begin and std::end
from cppitertools.
Related Issues (20)
- Can't get cmake FetchContent to work HOT 12
- Negative indexing on slice HOT 1
- `product` with repeats as an argument HOT 5
- New tagged versioned release. HOT 1
- Unable to use iterator from combination with C++17 STL transform_reduce HOT 1
- product's repeat argument as a variant.
- enumerate.hpp mixes class and struct HOT 1
- enumerate with signed index HOT 2
- [DOC] compress HOT 2
- Requesting rbegin and rend for iter::repeat HOT 5
- Fix all `reference` type aliases to match the return type of operator* exactly.
- Accept move-only callables in all itertools that take callables objects
- unique_everseen should be templated by a hash function and use a different set object HOT 1
- dereference operators should be const
- Add security policy
- Can't use as subproject HOT 3
- Nesting with Combinations Compilation Issue in MSVC HOT 1
- [cmake] FetchContent warning message HOT 1
- Question : enumerate(zip(...)) HOT 4
- Combinations seems not to work with std::vector<torch::Tensor> with degree 3. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppitertools.