3 ms·
> Historically at least, I expect structure elements to be identified by name rather than by declaration order. then... just use the struct directly if that's
by jcelerier 8y ago
> Historically at least, I expect structure elements to be identified by name rather than by declaration order.
then... just use the struct directly if that's what you want ? But a single binding can map to multiple structs, especially in generic code :
template<typename T>
double dist(T point) {
auto& [x, y] = point;
return std::sqrt(x * x + y * y);
}
should work with T's that look like
struct Point { float f[2]; }
or
struct Point { float x, y; }
or
struct Point { float p1, p2; }
or
std::tuple<float, float>
or ...