Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Color to be scoped enumeration #62

Merged
merged 1 commit into from
Oct 29, 2018
Merged

Make Color to be scoped enumeration #62

merged 1 commit into from
Oct 29, 2018

Conversation

tiendq
Copy link
Contributor

@tiendq tiendq commented Oct 26, 2018

@plibither8
Copy link
Owner

I read the reference. How are the advantages directly linked to this project? Just asking since I can't get hold of the direct advantages of it 😄.

@tiendq
Copy link
Contributor Author

tiendq commented Oct 26, 2018

Short answer, it’s safer then safer code is a pratice we should follow especially it’s easy to do :)

Exactly it’s a new C++ feature that we should use, except you are maintaining an old C code base :)

It says all in this code (copied):

enum class Color { red, blue }; // scoped and strongly typed enum
// no export of enumerator names into enclosing scope
// no implicit conversion to int

@tiendq
Copy link
Contributor Author

tiendq commented Oct 27, 2018

I'd like to add another link, it's styled better than previous one :). I just found many others enum (I didn't look at them yesterday), it's not a high priority task but I suggest you to change them all to enum class.

https://isocpp.org/wiki/faq/cpp11-language-types#enum-class

@plibither8
Copy link
Owner

plibither8 commented Oct 27, 2018 via email

@@ -37,28 +37,28 @@ class Modifier {
public:
Modifier(Code pCode) : code(pCode) {}
friend std::ostream &operator<<(std::ostream &os, const Modifier &mod) {
return os << "\033[" << mod.code << "m";
return os << "\033[" << static_cast<int>(mod.code) << "m";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed because of C.164 of the C++ Core Guidelines especially:

Do not introduce implicit conversions (through conversion operators or non-explicit constructors) just to gain a minor convenience.

@cawvyoct cawvyoct merged commit 8264a1f into plibither8:master Oct 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants