On Tuesday, 24 September 2019 at 17:01:46 UTC, Anonymouse wrote:
I want to write a piece of code that reflects on the names of
members of a passed struct, where some are depreacted.
https://run.dlang.io/is/P9EtRG
struct Foo
{
string s;
int ii;
bool bbb;
deprecated("Use `s`")
string zzzz;
}
template longestMemberLength(T)
{
enum longestMemberLength = ()
{
size_t maxLength;
foreach (immutable i, immutable name;
__traits(allMembers, T))
{
static if (!__traits(isDeprecated,
__traits(getMember, T, name)))
{
maxLength = max(maxLength, name.length);
}
}
return maxLength;
}();
}
static assert (longestMemberLength!Foo == "bbb".length);
onlineapp.d(23): Deprecation: variable `onlineapp.Foo.zzzz` is
deprecated - Use s
Is there any way to inspect the deprecated-ness of a member
this way? I only have what __traits(allMembers) gives me.
Does your code work or does it not? I don't seem to unterstand
neither what the question here is nor what the desired result is.
Is the problem that the static reflections triggers the
deprecation warning?