Comments (12)
I believe the current implementation of product does copy the data. I was considering reworking it and similar to use reference wrappers. The majority of the library does support move only types though afaik, is it product specifically that's giving you problems or in general you are experiencing trouble?
from cppitertools.
Unfortunately I have the same problem with iter::powerset
. Basically, I have a std::vector
of move only objects and I would like to iterate over the container with iter::powerset
and iter::product
.
Thanks.
from cppitertools.
Okay I think I can do this with reference_wrapper without any sort of API
break. I'll have to consider it a bit more, and probably get to this over
the weekend.
On Thu, Sep 4, 2014 at 10:36 AM, iliocatallo [email protected]
wrote:
Unfortunately I have the same problem with iter::powerset. Basically, I
have a std::vector of move only objects and I would like to iterate over
the container with iter::powerset and iter::product.Thanks.
—
Reply to this email directly or view it on GitHub
#14 (comment)
.
from cppitertools.
Yeah, hopefully std::reference_wrapper
should do the trick.
Thanks.
from cppitertools.
My mistake, since product returning tuples, std::reference_wrapper
isn't right. It needs to be a tuple of references. I'm in the process of reworking product to support rvalues properly, afterwhich I'll be going through all the combinatoric functions and figuring out the right solution at each step.
from cppitertools.
Probably you should return a std::tuple<std::reference_wrapper<Args>...>
.
Thank you.
from cppitertools.
nah, because reference_wrapper
would be wrong if dereferencing one of the iterators returned a value. As it turns out I fixed this issue while rewriting product
to support temporaries so product
now works with containers of moveonly types. The previous version used make_tuple
which would deduce the types, so even if *iter
had type T&
, the resulting tuple would be tuple<T>
. I now have it explicitly templating the tuple
; I'm not using make_tuple
anwhere. That solves product, but reference wrapper still needs to be added in the other combinatoric functions.
from cppitertools.
I got combinations
working with move-only as well. That same pattern should apply to the rest of the combinatorics.
from cppitertools.
Great! thank you for your awesome library!
from cppitertools.
thanks for your interest and for bringing this issue to light. I'll close it once I finish the rest of the combinatorics.
from cppitertools.
I believe this is working for all combinatorics now including powerset
, with the exception of permutations
which uses next_permutation
which has its own requirments. I can't do much about that without implementing a totally new permutations
though, and it would still have to cover the case where there are two equal elements in one sequence.
edit: I'll figure it out tomorrow. I got some ideas
from cppitertools.
did it. lml. permutations
is working. it is done for all the combinatorics
from cppitertools.
Related Issues (20)
- Can't get cmake FetchContent to work HOT 12
- iter::combinations' behaviour when r = 0 is different from Python's itertools.combinations HOT 2
- Question: calling functions with iterators as parameters HOT 2
- Internal linkage of iter::chain leads to ODR violation. 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.