It doesn't look like that to me, the ++i thing seems to be just to start printing the array from 1 (I don't know how things are in Python nowadays but I know in Lua arrays start at 1, so there's no need for something like this in there), the value of i is still increasing without telling it explicitly to do so
Their C++17 example prints starting from 0. Probably a mistake.
If you look at the linked page for C++20[0], other types can be put in the initializer statement, so it's unlikely the loop auto-increments.
[0]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p06...
Linus Torwalds famously said that subset is zero. You're not allowed to use C++ in Linux, a wise move.
Here's Google's: https://google.github.io/styleguide/cppguide.html Search for "do not use" and you'll find plenty of hits.
here you go: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
Reminds me of Good Parts, Bad Parts meme of JS.
This can’t be further from truth. C++ is essentially Frankenstein’s monster.
If anything it is more of a Chimera
> Gall's Law: A complex system that works is invariably found to have evolved from a simple system that worked. A complex system designed from scratch never works and cannot be patched up to make it work. You have to start over with a working simple system.
import std.stdio;
string[9] vec = [
"the", "quick", "brown", "fox",
"jumped", "over", "the", "lazy", "dog"
];
void main()
{
foreach (i, s; vec)
writeln(i, ": ", s);
} for (auto [i, v] : std::views::enumerate(vec)) {
std::cout << i << ": " << v << '\n';
}
This is how you'd do it. for (int i=0; auto&& it: vec)
cout << (++i) << ": " << it << endl;
It's certainly not obvious what's going on there at a glance.This is at least a bit more pythonic:
for (auto [i, it] : std::views::enumerate(vec)) {
std::cout << i << ": " << it << "\n";
} 1> (mapdo (op put-line `@1: @2`) '#"how now brown cow" 0)
how: 0
now: 1
brown: 2
cow: 3
nil
mapdo: map for side effects of calling the function, not calculating a result, like map.op: produce a lambda function out of an expression in which @1, @2, ... explicitly indicate the insertion of positional arguments, which are then implicitly bestowed onto the generated lambda.
`...`: quasistring syntax: supports @ notations for interpolating. @1, @2 of op do not require a double @@ inside a quasistring.
put-line: ordinary function to put a string to a stream (standard output by default) followed by newline.
#"...": string list literal: contents are broken on whitespace and denote a list of strings #"foo bar" -> ("foo" "bar"). Requires ' quote in front to be quoted literally, and not evaluated as a compound expression applying the argument "bar" to the operator "foo". Yes, there is a #`...` quasi string list for templating over this.
0: ordinary integer zero. But endowed with the power of being iterable. Where an iterable thing is required, 0 denotes the whole numbers 0, 1, 2, ...
These are some of the ingredients in my one-member research programme into nicer Lisp coding.
HarHarVeryFunny•3d ago
for (auto [i,v] : std::views::enumerate(vec)) std::cout << i << ": " << v << std::endl;
FWIW C++23 also has a python-like print and println:
std::println("{}: {}", i, v);
BigTTYGothGF•23m ago
arikrahman•13m ago
Maxatar•10m ago