getopt: How does arraySep work?

Anonymouse zorael at gmail.com
Tue Jul 14 13:51:58 UTC 2020


On Tuesday, 14 July 2020 at 11:12:06 UTC, Andre Pany wrote:
> [...]

Steven Schveighoffer already answered while I was composing this, 
so discarding top half.

As far as I can tell the default arraySep of "" splitting the 
argument by whitespace is simply not the case.

> https://github.com/dlang/phobos/blob/master/std/getopt.d#L923

     // ...
     else static if (isArray!(typeof(*receiver)))
     {
         // array receiver
         import std.range : ElementEncodingType;
         alias E = ElementEncodingType!(typeof(*receiver));

         if (arraySep == "")
         {
             *receiver ~= to!E(val);
         }
         else
         {
             foreach (elem; val.splitter(arraySep).map!(a => 
to!E(a))())
                 *receiver ~= elem;
         }
     }

So you will probably want an arraySep of " " if you want 
--modelicalibs "a b".


More information about the Digitalmars-d-learn mailing list