Search elemnt in Compile-time Argument List of strings
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 26 14:47:55 PDT 2016
On 7/26/16 4:58 PM, ParticlePeter wrote:
> On Tuesday, 26 July 2016 at 20:18:48 UTC, Steven Schveighoffer wrote:
> ....
>> void processMember( T, ignore... )() {
>> foreach( member; __traits( allMembers, T )) { // this is a
>> compile-time list, so it's a static foreach.
>> foreach(i, arg; ignore ){ // i is the index into the ignore tuple
>> static if( arg == member ) break; // break out of the foreach
>> loop, need to ignore it.
>> else static if(i + 1 == arg.length) // this is the last element!
>> {
>> // process member here, generate e.g. setter function as string
>> mixin
>> }
>> }
>> }
>> }
>
> There is one problem with this approach, ignore might be empty (I should
> have mentioned it). Would you know a workaround for that case as well?
Hm... good point :)
Here is a workaround:
foreach(i, arg; AliasSeq!(ignore, "SENTINEL"))
static if(i == ignore.length)
{
// process, it's good
}
else static if(arg == member) break;
-Steve
More information about the Digitalmars-d-learn
mailing list