Flag & byLine confusion.

Ali Çehreli acehreli at yahoo.com
Sun Dec 20 01:08:06 UTC 2020


On 12/19/20 4:40 PM, Mike Parker wrote:

 >> 1. Yes.keepTerminator
 >
 > This is because of Yes is a struct with an opDispatch template that
 > "forwards" to Flag!"keepTerminator".yes. This is the preferred syntax
 > and will work with any Flag parameter.

I use Flag a lot but I am always bugged by how ugly the !"foo" part is 
especially compared to Yes.foo. A section I had removed from my DConf 
presentation asked whether we could add opDispatch to templates as well. 
That would allow us to say Flag.foo.

I don't know how we could fit it in the syntax but it could be something 
like this:

template Flag() {
   auto opDispatch(string s)() {
     alias opDispatch = FlagImpl!s;
   }
}

Another thought that came to me to solve the same issue was to allow 
string template parameters without needing to write the double quotes:

// Re-purposing the 'static' keyword for fun. :)
template Flag(static string s) {
   // ...
}

So we could either write Flag!"foo" or Flag!foo. Similar to how 
opDispatch would convert unknown symbols to strings. Perhaps like this?

template Flag(opDispatch s) {
   // ...
}

Ali



More information about the Digitalmars-d-learn mailing list