How to pass list of strings as compile-time parameters?

Timon Gehr timon.gehr at gmx.ch
Tue Apr 24 11:03:07 PDT 2012


On 04/24/2012 07:37 PM, H. S. Teoh wrote:
> I'm trying to write a template function for doing member-wise
> comparisons between two objects, with an optional list of members to
> ignore. But I can't seem to figure out the syntax for passing a list of
> strings (or an AA of strings) to the function?
>
> I tried this:
>
> 	bool compareByMemb(string[] ignores, T)(T obj1, T obj2) {
> 		foreach (name; __traits(getAllMembers, T)) {
> 			...
> 		}
> 	}
>
> but the compiler complains:
>
> 	Error: arithmetic/string type expected for value-parameter, not string[]
>
> What gives?
>
>
> T
>

Try using an alias parameter (with an optional type constraint). imo the 
template instantiation semantics needs a clean-up.


More information about the Digitalmars-d-learn mailing list