Closed iliocatallo closed 10 years ago
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?
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.
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 notifications@github.com 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 https://github.com/ryanhaining/cppitertools/issues/14#issuecomment-54486132 .
Yeah, hopefully std::reference_wrapper
should do the trick.
Thanks.
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.
Probably you should return a std::tuple<std::reference_wrapper<Args>...>
.
Thank you.
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.
I got combinations
working with move-only as well. That same pattern should apply to the rest of the combinatorics.
Great! thank you for your awesome library!
thanks for your interest and for bringing this issue to light. I'll close it once I finish the rest of the combinatorics.
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
did it. lml. permutations
is working. it is done for all the combinatorics
Hi,
I would like to use the library with move only types. Here's a toy example:
Thanks.