memberIsVisibleAndNotDeprecated

Eponymous template; aliases itself to true if the passed member of the passed aggregate Thing is not private and not deprecated.

Compilers previous to 2.096 need to flip the order of the checks (visibility first, deprecations second), whereas it doesn't matter for compilers 2.096 onwards. If the order isn't flipped though we get deprecation warnings. Having it this way means we get the visibility/deprecation check we want on all (supported) compiler versions, but regrettably deprecation messages on older compilers. Unsure where the breakpoint is.

template memberIsVisibleAndNotDeprecated (
Thing
string memberstring
) {
static if(!isAggregateType!Thing)
enum pattern;
static if(!isAggregateType!Thing)
enum message;
static if(!(!isAggregateType!Thing))
static if(!memberstring.length)
enum message;
static if(!(!isAggregateType!Thing))
static if(!(!memberstring.length))
static if(__VERSION__ >= 2096L)
static if(!__traits(isDeprecated, __traits(getMember, Thing, memberstring)) && (__traits(getVisibility, __traits(getMember, Thing, memberstring)) != "private") && (__traits(getVisibility, __traits(getMember, Thing, memberstring)) != "package"))
enum memberIsVisibleAndNotDeprecated;
static if(!(!isAggregateType!Thing))
static if(!(!memberstring.length))
static if(__VERSION__ >= 2096L)
static if(!(!__traits(isDeprecated, __traits(getMember, Thing, memberstring)) && (__traits(getVisibility, __traits(getMember, Thing, memberstring)) != "private") && (__traits(getVisibility, __traits(getMember, Thing, memberstring)) != "package")))
enum memberIsVisibleAndNotDeprecated;
static if(!(!isAggregateType!Thing))
static if(!(!memberstring.length))
static if(!(__VERSION__ >= 2096L))
static if(__VERSION__ >= 2089L)
static if(!__traits(isDeprecated, __traits(getMember, Thing, memberstring)) && (__traits(getProtection, __traits(getMember, Thing, memberstring)) != "private") && (__traits(getProtection, __traits(getMember, Thing, memberstring)) != "package"))
enum memberIsVisibleAndNotDeprecated;
static if(!(!isAggregateType!Thing))
static if(!(!memberstring.length))
static if(!(__VERSION__ >= 2096L))
static if(__VERSION__ >= 2089L)
static if(!(!__traits(isDeprecated, __traits(getMember, Thing, memberstring)) && (__traits(getProtection, __traits(getMember, Thing, memberstring)) != "private") && (__traits(getProtection, __traits(getMember, Thing, memberstring)) != "package")))
enum memberIsVisibleAndNotDeprecated;
static if(!(!isAggregateType!Thing))
static if(!(!memberstring.length))
static if(!(__VERSION__ >= 2096L))
static if(!(__VERSION__ >= 2089L))
static if((__traits(getProtection, __traits(getMember, Thing, memberstring)) != "private") && (__traits(getProtection, __traits(getMember, Thing, memberstring)) != "package") && !__traits(isDeprecated, __traits(getMember, Thing, memberstring)))
enum memberIsVisibleAndNotDeprecated;
static if(!(!isAggregateType!Thing))
static if(!(!memberstring.length))
static if(!(__VERSION__ >= 2096L))
static if(!(__VERSION__ >= 2089L))
static if(!((__traits(getProtection, __traits(getMember, Thing, memberstring)) != "private") && (__traits(getProtection, __traits(getMember, Thing, memberstring)) != "package") && !__traits(isDeprecated, __traits(getMember, Thing, memberstring))))
enum memberIsVisibleAndNotDeprecated;
}

Members

Imports

format (from std.format)
public import std.format : format;
Undocumented in source.
format (from std.format)
public import std.format : format;
Undocumented in source.
isAggregateType (from std.traits)
public import std.traits : isAggregateType;
Undocumented in source.

Parameters

Thing

Some aggregate.

memberstring

String name of the member of Thing that we want to check the visibility and deprecationness of.

Examples

struct Foo
{
    public int i;
    private bool b;
    package string s;
    deprecated public int di;
}

class Bar
{
    public int i;
    private bool b;
    package string s;
    deprecated public int di;
}

static assert( memberIsVisibleAndNotDeprecated!(Foo, "i"));
static assert(!memberIsVisibleAndNotDeprecated!(Foo, "b"));
static assert(!memberIsVisibleAndNotDeprecated!(Foo, "s"));
static assert(!memberIsVisibleAndNotDeprecated!(Foo, "di"));

static assert( memberIsVisibleAndNotDeprecated!(Bar, "i"));
static assert(!memberIsVisibleAndNotDeprecated!(Bar, "b"));
static assert(!memberIsVisibleAndNotDeprecated!(Bar, "s"));
static assert(!memberIsVisibleAndNotDeprecated!(Bar, "di"));