Is it undefined behaviour in C++ to access elements in adjacent arrays as in following code?
#include <type_traits>
#include <algorithm>
#include <iterator>
int main()
{
int a[10][10];
static_assert(std::is_standard_layout< decltype(a) >::value, "!");
std::fill(std::begin(*std::begin(a)), std::end(*std::prev(std::end(a))), 0);
struct B { int b[10]; };
B b[10];
static_assert(std::is_standard_layout< decltype(b) >::value, "!");
std::fill(std::begin(std::begin(b)->b), std::end(std::prev(std::end(b))->b), 0);
}
Technically I think for POD-types it is legal to access underlying memory in any manner one want, but what about std::*
stuff?
What if I change all begin/end
to rbegin/rend
?