How to list all the manifest constants in a class or struct

Heromyth bitworld at qq.com
Mon Jun 18 03:10:12 UTC 2018


On Sunday, 17 June 2018 at 20:03:09 UTC, aliak wrote:
> On Sunday, 17 June 2018 at 02:44:38 UTC, Heromyth wrote:
>> [...]
>
> I think this bolts.isManifestAssignable [1] will get you 
> partially there. The place where it'll fail though is a static 
> immutable (since they are assignable to manifest constants) but 
> you can filter those by seeing if you can take the address, 
> something like:
>
> foreach (m; __traits(allMembers, T)) {
>   if (isManifestAssignable!(T, m) && 
> !is(typeof(mixin("&T."~m))) {
>     // it's a manifest constant ... (?)
>   }
> }
>
> There of course might be edge cases I can't think of/don't know 
> about though.
>
> Cheers,
> - Ali
>
> http://bolts.dpldocs.info/bolts.traits.isManifestAssignable.html

Thant's it. Thanks for your great lib: 
https://github.com/aliak00/bolts


More information about the Digitalmars-d-learn mailing list