How do I get class member type?

Marc jckj33 at gmail.com
Sun Jan 14 21:19:42 UTC 2018


On Sunday, 14 January 2018 at 19:08:44 UTC, Marc wrote:
> On Sunday, 14 January 2018 at 18:18:50 UTC, Marc wrote:
>> I didn't find how using traits I could get a class member 
>> type? I need to test if give class member is not immutable, I 
>> find isMutable but not how get a type from give class member 
>> to pass to it.
>
> for clarify, I want all this at compile time, imaginary code 
> example:
>
>> static foreach(field; FieldNameTuple!C) {
>> 		static if(isFunction!(__traits(getMember, C, field)) &&  
>> isMutable(typeof(__traits(getMember, C, field)))) {
>>			// do something
>>		}
>>	}

I solved with this:

		enum isMutableString(string field) = 
is(typeof(__traits(getMember, Field, field)) == string);



More information about the Digitalmars-d-learn mailing list