Closer to Perfection: Get to Know C++11 Scoped and Based Enum Types -- Danny Kalev

Here's a nice intro and overview of one of the smaller features that makes C++11 safer.

Speaking of scoped and based enums, here's an interesting historical tidbit you may not know: These were initially co-proposed for C++ by an expert working on mission- and life-critical software and a large horizontal software company. Just goes to show the broad applicability of features like these, that matter where safety is critical and also help everyone.

Closer to Perfection: Get to Know C++11 Scoped and Based Enum Types

by Danny Kalev

C++ enum types pack a set of related constants in an intuitive and efficient user-defined type. Can you ask for more? With two new C++11 enhancements, namely scoped enums and based enums, the answer is "yes." Find out all about the recent facelift that C++11 enums underwent and learn how to refactor your code to benefit from the new enum features – without sacrificing performance or backward compatibility.

From the intro:

Enums are one of my favorite C++ features. They exemplify the notion of an efficient user-defined type without the heavy machinery of virtual functions, constructors, etc. (Compare C++ enums to other programming languages that still insist on using a full-blown class instead, and you’ll see what I mean.)

Yet, traditional enum types aren't flawless. ... C++11 addresses these issues with revamped enumerations that give you tighter control over the scope, size, and implicit conversions of enum types. Let's look at these new features more closely, and examine how they can improve both our code quality and frustration level.

Continue reading...

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.