how to properly compare this type?

Jack jckj33 at gmail.com
Tue Feb 9 23:12:57 UTC 2021


I have a class like this:

struct S { }

class A
{
	@(S)
	{
		int a;
		string b() { return ib; }
		string b(string s) { return ib = s;}
	}

	int x;
	int y;

	string ib = "lol";
}

where I want to list the members that have S UDA but it failing 
to compare string b() { ... }. How do I do this?

current code:


	import std.traits : hasUDA;
	string[] arr;
	static foreach(member; __traits(allMembers, A))
	{
		static if(hasUDA!(__traits(getMember, A, member), S))
		{
			pragma(msg, typeof(__traits(getMember, A, member)));
			static if(is(typeof(__traits(getMember, A, member)) == string 
function(string)))
			{
				arr ~= member;
			}
		}	
	}
	writeln(arr);


arr is empty


More information about the Digitalmars-d-learn mailing list