Giter Site home page Giter Site logo

Comments (12)

ryanhaining avatar ryanhaining commented on August 9, 2024

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.

iliocatallo avatar iliocatallo commented on August 9, 2024

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.

ryanhaining avatar ryanhaining commented on August 9, 2024

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.

iliocatallo avatar iliocatallo commented on August 9, 2024

Yeah, hopefully std::reference_wrapper should do the trick.

Thanks.

from cppitertools.

ryanhaining avatar ryanhaining commented on August 9, 2024

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.

iliocatallo avatar iliocatallo commented on August 9, 2024

Probably you should return a std::tuple<std::reference_wrapper<Args>...>.

Thank you.

from cppitertools.

ryanhaining avatar ryanhaining commented on August 9, 2024

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.

ryanhaining avatar ryanhaining commented on August 9, 2024

I got combinations working with move-only as well. That same pattern should apply to the rest of the combinatorics.

from cppitertools.

iliocatallo avatar iliocatallo commented on August 9, 2024

Great! thank you for your awesome library!

from cppitertools.

ryanhaining avatar ryanhaining commented on August 9, 2024

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.

ryanhaining avatar ryanhaining commented on August 9, 2024

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.

ryanhaining avatar ryanhaining commented on August 9, 2024

did it. lml. permutations is working. it is done for all the combinatorics

from cppitertools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.