enum behaivor. another rehash of the topic
Tommi
tommitissari at hotmail.com
Sun Dec 15 07:01:46 PST 2013
On Sunday, 15 December 2013 at 12:40:53 UTC, monarch_dodra wrote:
> On Sunday, 15 December 2013 at 09:38:28 UTC, deadalnix wrote:
>> Resulting in people giving name like TestT1, TestT2 as enum
>> values in C++. As a result, you end up with the same verbosity
>> as in D, without the possibility of using 'with'.
>
> I've usually seen the "namespace" or "struct "approach, eg:
>
> namespace CheckerBoardColor
> // or struct CheckerBoardColor
> {
> enum Enumeration
> {
> Red,
> Black,
> };
> };
>
> This allows using "CheckerBoardColor::Red", which (IMO) is nice
> and verbose. you can use "using CheckerBoardColor" for the
> equivalent of "with" (namespace only).
>
> Unfortunatly, the actual enum "type" is
> "CheckerBoardColor::Enumeration", which is strangely verbose.
I'd rather do this:
namespace CheckerBoardColorNamespace
{
enum CheckerBoardColor { Red, Black };
};
using CheckerBoardColorNamespace::CheckerBoardColor;
auto v = CheckerBoardColor::Red;
int main()
{
using namespace CheckerBoardColorNamespace;
auto v = Red;
}
...and you get to have a nice name for the enum type.
More information about the Digitalmars-d
mailing list