interesting semantic possible?

JS js.mdnq at gmail.com
Sun Jul 21 17:08:48 PDT 2013


Say I have a template function where there are variations, it 
would be nice to be able to specify those variables like

strip!Left(s), strip!Right(s), strip(s), etc...

instead of ahving to do stripLeft, stripRight, and strip.

But the goal isn't just to add an extra ! to type but that it 
reduces code duplication.

strip left and strip right are very similar and in a stripping 
algorithm most of the code is identical except for the direction 
the loop... instead of copying and pasting an appropriately 
placed static if could simplify things greatly.

e.g.,

string strip(string dir = {"Left", "Right", default: 
"Both"})(string s);


using such a notation could allow us to use such a notation could 
make life more interesting... (BTW, I'm not saying this notation 
has to be exactly like this...)

The idea is also to avoid littering the symbol table with symbols 
so "strings without quotes" are passed. e.g., split!Left instead 
of split!"Left" and Left doesn't have to be defined somewhere.

If this notation doesn't work well with template notation then 
some alternate could be used

strip at Left or strip#Left..



More information about the Digitalmars-d-learn mailing list