Proposal: Package aliases
Robert Fraser
fraserofthenight at gmail.com
Thu May 15 15:05:34 PDT 2008
Steven Schveighoffer wrote:
> I admit, after writing all this, it does seem unlikely that you would ever
> need to use the import foo : bar = baz.
I find it useful for smoothing over std library differences. For
example, Phobos's find() function returns -1 if the substring isn't
found, while Tango's returns the length of the haystack. I also need the
trim() function, which is called strip() in Phobos. So I have something
like:
version(inTango)
{
import tango.text.Util : trim;
import tango.core.Array : tangoFind = find;
private int find(char[] haystack, char[] needle)
{
uint res = tangoFind(haystack, needle);
return res == haystack.length ? -1 : res;
}
}
else
{
import std.string : find, trim = strip;
}
This way, I can call the trim() and find() functions and expect them to
work whichever library is being used.
More information about the Digitalmars-d
mailing list