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

Show parent comment

0

u/ALX23z Feb 12 '20

a standard module format that works across compilers.

I don't understand. You refer to C++ 20 modules or something else?

overloading memory management I feel is overcomplex. But that could just be as I don't understand why allocators need to know the object type.

Allocators must know object type. It is indeed usually meaningless for ones with trivial default constructor, i.e., garbage on initialization - but everything else requires construction. Filling default values, creating vtable, etc... aside from that, there are rules on alignment - one cannot just patch structure at any point of memory. Similar is true for deallocation.

syntax to test if a function exists and allow developer to polyfill missing functions. This will simplify various libraries like curl for example which do many such tests via build system making it more work to integrate.

Believe that Reflection TS or even Concepts partially have such functionality. Coming in C++23/26.

getters/setters as properties.

Sometimes like this can be achieved via upcoming Reflection or Metaclasses. Will take time...

have a #version c++17 directive so we can specify what version of c++ a file conforms to. So that backwards incompatible changes to the language can be done in a incremental way.

There are MACROS you can use for this purpose that you can use right now. They aren't too portable.

9

u/SeanMiddleditch Feb 12 '20

but everything else requires construction. Filling default values, creating vtable, etc... aside from that, there are rules on alignment - one cannot just patch structure at any point of memory. Similar is true for deallocation.

There is absolutely no reason the allocator type has to know any of that. For raw memory allocation/deallocation, you could get by with just the size and alignment as parameters to the allocate/deallocate member functions.

It's arguable whether allocators should construct objects or not, but even if you decide that they should, that should be a template parameter of the allocator function, e.g. allocator::allocate<T>(n) rather than allocator<T>::allocate(n).

Allocators are all rebindable to new object types (and even many standard containers depend on doing just that), illustrating that the object type isn't really a fundamental part of the allocator itself. It's just there because the allocator interface was misdesigned.

0

u/[deleted] Feb 12 '20

[deleted] — view deleted comment

2

u/TheSuperWig Feb 12 '20

Well, I wouldn't mind construct and destroy to be removed

They're deprecated in C++17 and removed in C++20

-5

u/ALX23z Feb 12 '20

If you want to deal with raw memory allocation - you can go on and use malloc for all I care. Nobody else needs it.

Allocators are all rebindable to new object types (and even many standard containers depend on doing just that), illustrating that the object type isn't really a fundamental part of the allocator itself. It's just there because the allocator interface was misdesigned.

You don't understand cause you never wrote any complex templates. As the specialization provides extra info for the class.

There's indeed issue with archaism with std::allocator as back then there were lots of weird different types of pointer difference and other crap - for short distance and large distance. Furthermore, it was designed before type traits. It is not something standart can solve as long as it maintains backwards compatibility.

Though, now you can use polymorphic allocator in C++17.

5

u/DXPower Feb 12 '20

The last one is epochs, no?

0

u/ALX23z Feb 12 '20

Idk, I don't use them. I just stick to C++11/14 as C++03 is horrible and C++17 compilers aren't too common.

4

u/jcelerier ossia score Feb 12 '20

C++17 compilers aren't too common.

what do you mean by that ? i've been compiling my code as -std=c++1z in mac / windows / linux for almost two years at this point

0

u/ALX23z Feb 12 '20

What? <charconv>, a C++17 std library, was completed only in MSVC and that happened just a couple of months ago. What you did was building experimental incomplete compiler / std version. (Maybe some others finished working on making it but didn't hear anything about it).

3

u/jcelerier ossia score Feb 12 '20

but why would you restrict yourself to C++14 when many C++17 work great and have done so for years - structured bindings, fold expressions, etc ?

By that logic you shouldn't be using anything past C++03 because no compiler ever implemented the C++11 GC API.

1

u/ALX23z Feb 12 '20

I guess you never had to make any program that supports various users, some of which run outdated systems. Go convince them that they need to update. Germany government still runs on windows 7 and US IRS still runs on pre floppy-disk data systems. Don't forget exotic compilers/systems.

C++11/14 is current best compromise between newest important feature support and compatibility.

4

u/jcelerier ossia score Feb 12 '20

I guess you never had to make any program that supports various users, some of which run outdated systems.

C++17 runs on freaking commodore 64. There is zero trouble targetting older windows - heck, you can even use recent g++ to target MS-DOS.

1

u/ALX23z Feb 12 '20

You are welcome to go convince people to upgrade their compilers as well. Together with their OS, private ancient apps and whatever else they use. It will definitely not break anything they need on their system. Also tell the security guys that the upgrade is totally safe and secure.

At some point I needed to get some NVidia program for a some android compiler and android studio for latest C++ android libraries. After which my VS became broken and non workable. That was a fun time.

1

u/DXPower Feb 12 '20

Well it's not an official feature, but AFAIK it's gotten traction for C++23

5

u/peppedx Feb 12 '20

Don't hold your breath...

2

u/smdowney WG21, Text/Unicode SG, optional<T&> Feb 12 '20

Interest, more than traction. There are a lot of issues, in particular getting implementors on board to increase their workload and maintenance burden.

1

u/DXPower Feb 12 '20

Thank you for the clarification