Generic string join

JS js.mdnq at gmail.com
Mon Jul 29 02:01:35 PDT 2013


Here is a optimal generic string joiner that maximizes compiler 
optimization, allows for a variable number of arguments that can 
be strings or arrays of strings.

http://dpaste.dzfl.pl/0a021e1f

Drawbacks:
     1. Static if explosion
     2. Not elegant
     3. Only works with RT strings or RT string arrays, would be 
nice to work with chars and possibly others.
     4. Does not have the ability to use book ends delimitation... 
not difficult to do but just more bloat-code.
     5. Would be nice to allow apply a lambda to each "element". 
Again, not hard but requires all those special cases to deal with 
proper delimitation due to the recursion required.
     6. Requires a mixin statement... this is not pretty at all. 
One can't wrap the mixin in a normal function call because it 
defeats the purpose of optimization(CT strings will be passed as 
variables and not optimized by the CT).
     etc...

While I have some code to flatten such arrays before 
delimitation, which would probably make it much easier, which is 
the way I started, the code was going to turn out to be the same 
in the end as the flattener, so I just modified the 
code(basically use string concatenation instead of tuple 
concatenation).


Anyways, maybe someone has a good idea how to improve the code to 
achieve the same results. Note in in the test, every possible 
3-combination is tried, which I think is good enough to prove the 
validity of the code.


More information about the Digitalmars-d-learn mailing list