Const unbackled

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 24 19:28:54 PDT 2008


"Georg Wrede" wrote
> We should stop discussing whether/how this is implementable 
> syntactically/semantically, and instead start discussing USE CASES, and DO 
> WE NEED THIS IN THE FIRST PLACE.

For starters, let's look at some functions in std.string:

invariant(char)[][] split(string s);
invariant(char)[][] split(string s, string delim);
invariant(char)[][] splitlines(string s);
The use case could be said that one might want to pass a mutable string to 
these functions, and have it return mutable slices into the argument WITHOUT 
modifying the argument.

string stripl(string s);
string stripr(string s);
string strip(string s);
string chop(string s);
These could all be usable on mutable strings, with the result being a slice 
of the original, and hopefully mutable.  You should be able to specify that 
the function does not modify the argument.

And in tango.text.Util:

        trim (source)                               // trim whitespace
        triml (source)                              // trim whitespace
        trimr (source)                              // trim whitespace
        strip (source, match)                       // trim elements
        stripl (source, match)                      // trim elements
        stripr (source, match)                      // trim elements
        chopl (source, match)                       // trim pattern match
        chopr (source, match)                       // trim pattern match
        delimit (src, set)                          // split on delims
        split (source, pattern)                     // split on pattern
        splitLines (source);                        // split on lines
        head (source, pattern, tail)                // split to head & tail

These all could be specified that source is not modified.

-Steve 





More information about the Digitalmars-d mailing list