Thread overview |
---|
January 14, 2018 How do I get class member type? | ||||
---|---|---|---|---|
| ||||
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. |
January 14, 2018 Re: How do I get class member type? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc | 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 > } > } |
January 14, 2018 Re: How do I get class member type? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc | 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);
|
Copyright © 1999-2021 by the D Language Foundation