template <size_t N>
void myA(const int(&arra)[N], const int(&arrb)[N])
{
auto arra_begin = std::begin(arra);
std::cout << *arra_begin << std::endl; // 1
}
// Си++20!!!!!!!!!!
void myB(std::span<int> arra, std::span<int> arrb)
{
auto arra_begin = std::begin(arra);
std::cout << *arra_begin << std::endl; // 1
}
sizeof(void*) == sizeof(size_t)
.2) If a side effect on a memory location is unsequenced relative to a value computation using the value of any object in the same memory location, the behavior is undefined.
cout << i << i++; // undefined behavior until C++17
a[i] = i++; // undefined behavior until C++17
n = ++i + i; // undefined behavior
value++
(вместе с square) выполнился раньше оператора сдвига <<
, которые используются для вывода в поток cout.C D | X
0 0 | 1
0 1 | 0
1 0 | 0
1 1 | 1
Получаем, X = !C!D + CDX A | Y
0 0 | 0
0 1 | 1
1 0 | 1
1 1 | 1
Получаем Y = !XA + X!A + XA = !XA + X!A + XA + XA = (!XA + XA) + (X!A + XA) = A + Xstd::vector<std::vector<int>> matrix = {{1,2,3,42},{5,6,7,8},{9,10,11,42}};
const size_t limit = matrix.size() * matrix.front().size();
const size_t cols = matrix.front().size();
size_t i = 0;
size_t j = 1;
while(i < limit - 1 && matrix[i / cols][i % cols] != matrix[j / cols][j % cols])
{
if(++j == limit) j = ++i + 1;
}
if(i < limit - 1)
{
std::cout << "Indices of elements: [" << i / cols << "," << i % cols << "]";
std::cout << "[" << j / cols << "," << j % cols << "]" << std::endl;
}
else std::cout << "Not found" << std::endl;