That's a cool feature, even the if with initializer. By the way, if you have access to boost, you have one more option that works before C++20:
#include <iostream> #include <array> #include <string> #include <boost/range/adaptor/indexed.hpp> int main() { std::array<std::string, 3> data = {"hello", ",", "world"}; using namespace boost::adaptors; for (auto const& d : data | indexed(0)) { std::cout << (d.index() + 1) << " - " << d.value() << '\n'; } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's a cool feature, even the if with initializer. By the way, if you have access to boost, you have one more option that works before C++20: