It's an improvement in the sense that it's more general; you can loop through any container that implements that protocol, which most (if not all) of the STL containers do. For example,
template <class T>
void foo(T arr)
{
for (auto it = arr.begin(); it != arr.end(); ++it)
{
std::cout << *it << std::endl;
}
}
You could pass a `std::map<int>` to `foo`, or a `std::list<string>`, or a `std::vector<char>`. You could even create your own classes and give them to `foo`, as long as they implement the `begin`/`end` protocol.
It's certainly more verbose than necessary, but it can be convenient.
You can do that. That's part of C++11 and is supported by basically every major compiler.
The advantage of iterators is that they're incredibly flexible. You can use them for sub-ranges, reversed ranges, non-ranges like input and output iterators, etc, etc. This is vastly more powerful than something like, say, Objective C's NSFastEnumeration, which just allows for the trivial case handled by the range-based for-loop.
> Why do I even need to know about them when all I want is walk through the collection?
Because there are algorithms where you may not want to walk through the whole collection. STL wasn't meant to be a container library alone, it also includes many generic algorithms that work using iterators to delimit the range of data to be operated upon.
It basically is this easy these days, thankfully. It is nice to have iterators, though, because it allows you some flexibility for swapping out the underlying data structures on existing algorithmic code. This has proved quite useful when I've written graph code.
That's correct, it's nothing fancy. Rather than use anything complicated it's so much faster for these sorts of game-jam situations to pack all the level data into a bitmap and just edit it visually. Since I was loading the level image anyway for display, it made the process of editing monster placement, triforce pieces, etc very fast.
Check out pandoc [1], it will let you write documents in Markdown + LaTeX for equations and then convert it to LaTeX, a PDF, or several other document formats.
Also, even though Markdown tends to be fairly easy to write, there are many edge cases where you can't really be sure what the result is unless you try it.
By definition, the subscript operator [] is interpreted in such a
way that ‘‘E1[E2]’’ is identical to ‘‘*((E1) + (E2))’’. Because
of the conversion rules which apply to +, if E1 is an array and
E2 an integer, then E1[E2] refers to the E2th member of E1.
Therefore, despite its asymmetric appearance, subscripting is a
commutative operation.¹
Now obviously, c arrays are just strips of memory allocated to that array, so you can access them using the address of the start of the address and the offset (number of array items to skip). To access them, you sum the address and the offset, then you have the address of the item.
And now, a[b] is just short hand for the pointer arithmetic going on and you could just use any two ints and access any arbitrary memory address (i assume the compiler enforces that this doesn't happen).
I think the trick is that array[i] and i[array] will always be the same value in C.
It's confusing because array[i] makes sense but i[array] doesn't (how the hell can you use an array as an index on an integer?)
It works because array is a pointer to a memory address and i (or index) is an offset. array[i] will add the index to the memory address and return the value there, where as i[array] will add the memory address to the index. Since array+index == index+array, they point to the same memory and return the same value.
Something like "because my kids can receive great education here" would be a great answer, but just "lovin' it" means nothing. And having good friends is not a good reason either, because real friends are those that stay close to you when you are far away.
Moreover, I'd say adult people's life should not be constructed around their kids. It should be the opposite: kids follow their parents where they go until they can fly alone. I think it has been the case for most of humanity most of the time (the only exceptions could have been "baby kings" like Louis XIII, but they do not count).
In the same vein, if you father or mother love hiking, find a way to hike with kids. If you love snorkeling just teach them to snorkel early. If you prefer reading books at home just stay at home. They will follow. Having happy parents is the best gift for kids.
In our new society, having kids often means becoming their slave, and you are frowned upon if you dare keeping your hobbies once you have them. This is one of the most worrying mistakes I can imagine. I mean educational mistake. Kids do not need, or even like to be baby dictators.
Eh, I think too many parents are selfish, especially in America (not saying Sivers is--clearly he's not).
How often do you see parents dragging their screaming kids around, giving their 2-year old an iPad to shut them up at the coffee shop, buying a 50" flat screen TV while the college fund is at $0 and the bank accounts are overdrawn.
In the spirit of Sivers' post, I think if parents stopped, maybe once a month, and asked themselves "What am I doing to set my children up to have happy lives?" we'd all be better off.
Right, but none of the author's reasons seemed to revolve around anything but his own desire to focus and work on his products. In the context of raising a family, that's hard to justify.
I don't aim to be thorough when blogging. They're just succinct little tidbits.
Of course there's more to the story, and of course it was a whole-family decision. In fact my wife kinda led the decision even more than me.
We hope to move back to Singapore when our kid is a bit older, but he's still just a baby, so I really want him to grow up outside surrounded by nature, not inside shopping malls.
I hear you and appreciate the brevity, but I think it makes the post sound (to me) a little like: "Hey, I just ask myself a simple question about what I want, follow my heart, and off I go!"
Well, none of this is communicated by your blog post. The "more" to your story is actually key to your story, it seems to me. Why did you not include it?
I just checked my account's security history, and there's been a failed login attempt every 7 hours for the past two days, all from different IP addresses.