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

GEODE-10096: Replaced macro definitions with enumerations. #938

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

mreddington
Copy link

No description provided.

cppcache/src/TcrConnection.hpp Outdated Show resolved Hide resolved
cppcache/src/TcrConnection.cpp Outdated Show resolved Hide resolved
cppcache/src/TcrConnection.hpp Outdated Show resolved Hide resolved
/* Note: this implementation can be thrown away once we upgrade to C++23. */

template< class Enum >
constexpr underlying_type_t<Enum> to_underlying( Enum e ) noexcept {
Copy link
Contributor

@jake-at-work jake-at-work Mar 5, 2022

Choose a reason for hiding this comment

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

I am torn on this... I both like and dislike it.

Dislikes:

  • The name, underlying doesn't feel right, but I can't put my finger on it. to_ordinal?
  • It sort of undoes one of the key features of enum class by casting the enum something, you don't really see what, that can decay to another type.
  • Doesn't have a reverse like static_cast does so there is no mirror operation going back and forth between enum and ordinal value.

Like:

  • Hides the mess of casting to a int type.

🤷

Copy link
Author

Choose a reason for hiding this comment

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

Counterpoints:

  • This is a direct copy of an STL utility we just don't have in C++11.
  • Look where I'm using it - at some point, we need to write these enum values to the byte stream. Now there are two ways we can do that:
    • We can map an enum to a value, and a value to an enum, like via some switch statement. If we do that, then we don't need to specify the enum values themselves, since we'd never cast the enum to or from an integer type. This is just redundant in every way.
    • We cast the enum where we write bytes to the wire.
  • It doesn't need a reverse. You can static cast any integer to an enum and the compiler will let you know if you're narrowing, but if you want to cast from an enum to the numeric type used to implement it, that's built into the enum type but you wouldn't know it, or can't rely on it since it can change, either by the compiler, or in the case of an enum class, the implementer. The compiler always knows, so this leverages deduction to get it right for you.

But I feel you. I don't like the use of enums overall. There's just something about them that don't seem "good enough". I don't think C++ would have had enumerations in the form we have them today if we didn't inherit from C, so I'm always aware of the loose type safety they come with.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I wasn't aware they added this in 14. Well then... if the C++ gods like it then we should too. Thanks!

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.

3 participants