Date: Fri, 8 Mar 2024 00:39:41 +0100
Here's another idea:
struct S {
int arr[3];
template <char... Name>
requires (sizeof...(Name) == 1)
int operator""() {
switch (Name...) {
case 'x': return arr[0];
case 'y': return arr[1];
case 'z': return arr[2];
}
}
};
You wouldn't need to touch using-declarations; this is pretty much
using existing syntax.
Such a "member selection operator" could also be used to implement
swizzling such as "s.xy", "s.zzz", etc.
struct S {
int arr[3];
template <char... Name>
requires (sizeof...(Name) == 1)
int operator""() {
switch (Name...) {
case 'x': return arr[0];
case 'y': return arr[1];
case 'z': return arr[2];
}
}
};
You wouldn't need to touch using-declarations; this is pretty much
using existing syntax.
Such a "member selection operator" could also be used to implement
swizzling such as "s.xy", "s.zzz", etc.
Received on 2024-03-07 23:39:53