Giter VIP home page Giter VIP logo

product-iterator's People

Contributors

mirandaconrado avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

product-iterator's Issues

Working with empty container(s)?

First, let me thank you the for this. Seems exactly what I'm looking for.

Have you considered what happens/should-happen if one of the containers are empty?

I get a crash when trying to work with that, e.g. as illustrated:

#include "product_iterator.hpp"
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  vector<int> c1({1,2});
  vector<char> c2;         // NOTE THIS IS EMPTY!

  auto it = make_product_iterator(c1, c2);
  auto end = it.get_end();
  for(; it != end; ++it)
  {
    cout << "{" << it.get<0>() << ", " << it.get<1>() << "}\n";
  }
}

To allow client to use/test for that you could e.g. introduce a new method - similar to the get<>() - that tests for whether the container iterator is at its end, e.g. something like:

template <size_t I>
bool not_end() {
    return std::get<I>(current_)!=std::get<I>(end_);
}

I've tried to add that (se snippet code below for usage), but it still crashes al beit after output the first expected combination. I haven't examined (yet) what is causing the crash, but likely it is related to how you advance iterators in your implementation.

  for(; it != end; ++it)
  {
    cout << "{" << it.get<0>();
    if( it.not_end<1>() ) cout << ", " << it.get<1>();
    cout << "}\n";
 }

Expected output:

{1}
{2}

Regards,
/Michael

Awesome

Just wanted to say this is awesome! Thanks! :)

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.