Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++17] replace boost optional with std::optional in zip_longest #32

Open
ryanhaining opened this issue Feb 18, 2017 · 7 comments
Open

Comments

@ryanhaining
Copy link
Owner

ryanhaining commented Feb 18, 2017

  • update examples/zip_longest_examples.cpp to use structured bindings
  • update README example to use structured bindings
@ryanhaining
Copy link
Owner Author

std::optional doesn't support reference types. I can use a std::optional<std::reference_wrapper<T>> but that'll throw off uses with assignment

@xjjgjmeng
Copy link

Is it possible to replace boost::optional with C Pointers in zip_longest?

@ryanhaining
Copy link
Owner Author

I can't imagine how, do you have something in mind?

@xjjgjmeng
Copy link

xjjgjmeng commented Jul 8, 2023

#include <zip_longest.hpp>

#include <vector>
#include <string>
#include <iostream>

int main() {
    std::vector<int> ivec{1, 4, 9, 16, 25, 36};
    std::vector<std::string> svec{"hello", "good day", "goodbye"};

    // i: int*
    // s: std::string*
    for (auto&& [i, s] : iter::zip_longest(ivec, svec)) {
        if (i) {
            std::cout << *i << std::endl;
        }

        if (s) {
            std::cout << *s << std::endl;
        }
    }
}

@ryanhaining
Copy link
Owner Author

of course you could implement a zip_longest like that, but changes to the yielded type cannot break existing uses.

@xjjgjmeng
Copy link

Changing the type to a pointer doesn't change the existing usage, does it?

@ryanhaining
Copy link
Owner Author

I can't change the library in a way that breaks existing users if they update to a newer version of the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants