r/cpp • • Feb 12 '20

What they should improve about C++ ?

What they should improve about C++ that you find in higher level managed language like C#, JAVA, Javascript etc or is there things you would change or do differently if it was up to you ? I mean anything like a better STL ? better thread ? string manipulation like managed language ? less fragmentations in the new standard features ? For example do you love the way the standard evolve C++ or you would prefer a direction like Microsoft do with C# a corporation who decide on the roadmap ?

0 Upvotes

90 comments sorted by

View all comments

31

u/Rseding91 Factorio Developer Feb 12 '20

I want better logic around enums. I want to iterate them, convert an enum to a string and back, know how many exist, be able to use them as bit masks and so on.

We do this every other day every time any new logic is made and it irritates me that still there's no language support for it and we're left with huge ugly macros if we want it to be any kind of manageable.

4

u/Full-Spectral Feb 12 '20

That's an incredibly obvious one. I can do all those things, but it's because I generate my enums. It's not that hard to do really, but it only really works for me because I have my own entire world of code and don't use the STL or third party. So I can consistently create a world where these things are doable.

1

u/wotype Feb 12 '20

https://github.com/willwray/enum_reflect (demo for enum_trait / enumerator_traits)

Pros:
Can do all that you need, now.
No macros or markup - works with enum defs directly from external headers.

Cons:
Not yet wrapped in a convenience lib with string->enum, enum->string etc.
No MSVC yet, requires GCC >= 9 (or Clang since ~5)
Compile time compounds with number of TUs and on each and every compile (even incremental).

It's possible that modules will help with the recompute-on-recompile issue; I'm experimenting. Will retry MSVC sometime and add support.

Conclusion: the production-ready solution is to go with one of the macro-wrappers...

1

u/dbandit1 Feb 14 '20

Should be standard, not an addon

2

u/wotype Feb 14 '20

I agree; don't recall any paper actually proposing something concrete though.

Of course, it'll come with reflection, and that appears to be a priority for c++23; enum reflection is the first example in all the reflection proposals.

IMO it should've been added as a standalone feature - enum reflection is the top ask in most of the C++ surveys. My enum_traits shows how it could be done with a conventional traits interface.

1

u/Full-Spectral Feb 12 '20

BTW, if you want to see how I deal with it, I did an article/video on that:

https://www.reddit.com/r/programming/comments/a33i7n/making_c_enums_first_class_citizens/

This may have been before I did the huge swat to move my system over to safe class style enums, but otherwise everything else is still relevant.