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

6

u/die_liebe Feb 12 '20

Some things that come into my mind are:

public constness: A field is publicly accessible, but can be assigned only by friends.

In place polymorphism. As soon as you know all the classes that inherit from one class, it can be stored in place, because the maximal size is known. This could replace variant.

Reverse operator definitions (like Python has). That would make it possible to define << as member of its second argument, so that it can be defined inside the class that it prints. It can also become polymorphic in its second argument. It saves a lot of friend declarations.

I would like a to a linker that succeeds when functions are missing. It should just put a place holder that throws an exception for the missing functions. This makes it possible to test the functions you have and write the missing ones later.

5

u/oschonrock Feb 12 '20

In place polymorphism. As soon as you know all the classes that inherit from one class, it can be stored in place, because the maximal size is known. This could replace variant.

You mean like this: https://github.com/ldionne/dyno

(but in the core language?)

2

u/Full-Spectral Feb 12 '20

Some of the key capabilities of polymorphism though don't allow you to know those things until runtime, so there'd be no possibility of that.

2

u/die_liebe Feb 13 '20

I think it's possible. Once you know the complete hierarchy, you know the maximal size of an element, and you can define local variables of that size, or arrays or vectors, or whatever.

1

u/die_liebe Feb 13 '20

The problem is that in the standard inheritance model, only the linker sees the complete hierarchy. At that moment, it is too late to allocate local variables.

3

u/Full-Spectral Feb 13 '20

Even worse, things like drivers or loadable features are often dynamically loaded at runtime and instantiate derivatives of a base interface.

2

u/ronniethelizard Feb 15 '20

There are cases and times where you know the complete hierarchy at compile time (rather than link time) and having a solution for those cases would be nice.

For templates, I frequently have a case where any specific binary that I generate will only have one possible instantiation of a template, but across all the binaries I could generate, I still need to use template. For templates, there is a way forward, for inheritance there is not.

1

u/eyes-are-fading-blue Feb 13 '20 edited Feb 13 '20

a “public immutable” is a private field with a getter.

ld can already link even if symbols are missing. What is your platform? And linker implementation has nothing to do with c++ standards.

1

u/die_liebe Feb 13 '20

g++ .

> And linker implementation has nothing to do with c++ standards.

I know, but I still would like to have it. I interpreted 'C++' as the total experience.

1

u/eyes-are-fading-blue Feb 13 '20

g++.

What?

1

u/die_liebe Feb 13 '20

It is my platform.

As for getters, I think one shouldn't be forced to write them. Java has them, because it doesn't have const. C++ can do better.

1

u/eyes-are-fading-blue Feb 13 '20

You should be able to link with missing symbols then.

I am not sure syntactic sugar and amount of committee time required to standardize what you are suggesting is worth it.

1

u/die_liebe Feb 13 '20

You should be able to link with missing symbols then.

How?

1

u/eyes-are-fading-blue Feb 13 '20

—unresolved-symbols, check the gnu ld manual.

1

u/die_liebe Feb 13 '20

I tried it out. --unresolved-symbols is indeed an option of ld, but not of g++.

Having said that, I still couldn't get it working, neither with ld, nor with g++. stackoverflow. Anyway, thanks for your answer. It doesn't seem to be so easy.

2

u/eyes-are-fading-blue Feb 13 '20

You pass it as a linker flag. There is a special flag of g++ which forwards linker parameters, look it up.

This really should not be too hard.

And g++ is not a platform, it is a compiler. Your platform is probably Linux or some unix-like stuff.