2 ms·
Corrected below, leaving here for posterity and to make sure this conversation isn't confusing in the future. The only thing I'll note is that you get a compile
by stormbrew 11y ago
Corrected below, leaving here for posterity and to make sure this conversation isn't confusing in the future. The only thing I'll note is that you get a compile error on a zero length array, so the OP of this chain turns out right in a way heh.
Start ignoring here: Are you suggesting end() and begin() can be called on an array? As far as I know they can't. Apparently you can deduce array length in a constexpr function now in C++11 (which I only learned just now but also couldn't get working quickly, so have some salt with that), but before that arrays always degrade to pointers when passed as function arguments so there's (afaik) no way to extract their length from their type...
- hendzen 11y agoBefore the array decays to a pointer, you can get its length. Here is the implementation of std::begin for arrays in libc++: https://github.com/llvm-mirror/libcxx/blob/60d223df071f6e3d4ffa29331ed466fff563096f/include/iterator#L1430-L1436 https://github.com/llvm-mirror/libcxx/blob/60d223df071f6e3d4...
- stormbrew 11y agoQuite right, I'm apparently rusty on my stdlib knowledge. Didn't know about the reference trick.
- onedognight 11y agoYes you can call std::begin() and std::end() on an array. int a[] = {4,5,6}; for(int i : a) ; That is how the above works.