Fix issue 4813 trait for getting at access modifiers #952

wants to merge 1 commit into


None yet

6 participants


Added isPublic, isPrivate, isProtected, isPackage, and isExport traits

@jmaschme jmaschme Fix issue 4813
Added isPublic, isPrivate, isProtected, isPackage, and isExport traits

Would a getProtection trait not be more useful/flexible? Otherwise we'll end up with lots of wrappers for it unless they're added to phobos.


I think that would probably be best left for Phobos. There is no built-in representation for a protection type, so what would a getProtection trait return.

Also this approach is fairly consistent with the existing traits (isStaticFunction, isFinalFunction, isVirtualFunction, etc).


I was thinking a string. It's fine either way I guess as long as the inverse is in phobos (with the current pull I'd expect a getProtection template in phobos which returns a string with the protection type).

alexrp commented Jul 5, 2012

Given that we have isVirtualFunction, isFinalFunction, and so on, I'd go for consistency and do it like this pull request does. It would have been better to have traits that returned strings for these things, but now we're stuck with the other approach, so let's be consistent.


I just reviewed a pull request that added protection level detection to __traits: #856. How do these two compare?


I just tried using this DSYMBOL macro on my code, and it didn't pass an important test to me: it didn't give the protection on members returned from traits(getMember).


I pushed an update to mine that passes the tests I need - in addition to the macro, gotta check for various dot expressions. Take a look at the pull request Andrei linked to.

Other than that, the difference is I return a string instead of doing is... meh either way works for me, the string just seemed simpler.

@9rnsr 9rnsr referenced this pull request Sep 29, 2012

Protection trait #856


Closed as it is redundant with #856.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment