2022-12-20 02:54 AM
Just try it:
std::tuple<int, int, int> testTuples() { return { 1, 2, 3 }; };
struct Test { int a = 0, b = 0, c = 0; };
int main()
{
auto [a, b, c] = testTuples();
void* mem = malloc(3 * sizeof(int));
auto test = new(mem)Test;
}
The code above compiles in Visual Studio, does not compile in STM32CubeIDE.
Surprisingly "std::pair" works.
Though tuples are just some syntax sugar, no "placement new" is really annoying, because you either must manually re-initialize structs when needed, or allocate new memory, or use ugly deprecated hack with "memset()".