Enums - probably an old subject
monarch_dodra
monarchdodra at gmail.com
Thu Nov 21 11:20:55 PST 2013
On Thursday, 21 November 2013 at 18:44:39 UTC, Steve Teale wrote:
> On Thursday, 21 November 2013 at 17:39:28 UTC, Andrei
> Alexandrescu wrote:
>> On 11/21/13 8:48 AM, Steve Teale wrote:
>>> Could 'with' be extended to cover enum names do you think?
>>> Also a
>>> supplementary question - does auto lock out some things like
>>> this, are
>>> there other examples?
>>
>> Guess it could. One other thing we could do is to make enum
>> namespaces behave like imports.
>>
>> Andrei
>
> I'd love to understand "make enum namespaces behave like
> imports", but I should probably ask that on D Learn ;=)
When you import from a module, you only need to specify the
module name if there is ambiguity. So for example:
//----
import std.array;
void main()
{
split("hello"); //OK!
}
//----
import std.array;
import std.algorithm;
void main()
{
split("hello"); //Wait... did you want std.algorithm.split,
or std.array.split?
std.array.split("hello"); //OK! That's clearer now.
}
//----
What Andrei is saying is that an enum *could* work the same way:
enum RedBlack //For red black trees
{
Red,
Black,
}
enum BlackWhite //For Checker boards
{
Black,
White,
}
void main()
{
writeln(Red); //OK! No problem!
writeln(Black); //I'm sorry... that's ambiguous :/
writeln(RedBlack.Black); //OK! That's clearer now!
}
Whether or not it *should*, I don't know. "Why not?" I like to
say :)
More information about the Digitalmars-d
mailing list