I'm trying to capture (by value) an entire C-style array. The array seems to decay to a pointer... How do I prevent this so that the whole array is captured?
Code:
#include <iostream>
int main()
{
char x[1024];
std::cerr << sizeof(x) << "\n";
[x = x] // copy
{
std::cerr << sizeof(x) << "\n";
}();
}
This prints:
1024 <<-- yay
8 <<-- oops... not a true copy
It should be noted that this works as I had hoped (1024 for both results):
#include <iostream>
#include <array>
int main()
{
std::array<char, 1024> x;
std::cerr << sizeof(x) << "\n";
[x = x] // copy
{
std::cerr << sizeof(x) << "\n";
}();
}