Proposal for the next C++ standards

Modern C++ refers to the evolution of the C++ programming language beyond its original design principles, incorporating newer features, idioms, and best practices that have emerged since the language’s inception.

C++ is standardized by the International Organization for Standardization (ISO). C++ standards are typically released every few years, bringing new features and improvements to the language.

Modern C++ introduces a range of new features aimed at improving code clarity, safety, and performance. The smart pointers was a great added feature. Indeed, they provides safer and more convenient memory management compared to raw pointers.

And the smart pointers are now popular and widely used in the C++ projects. Just a quick look in the most popular C++ projects in Github proof that the smart pointers are the prefered way to work with pointers.

However, the raw pointers still there and many developers still use them. So why not assist them to use the smart pointers by forcing using the smart pointers by the compiler. The proposal consist of adding a new attribute to specify that a class can’t use raw pointers as fields types or method params types.

This way the compiler will protect the class code from the raw pointers 🙂

Even more I think it’s beneficial to the C++ developers to add the [[modern]] attribute to qualify that a class is modern.

And the compiler will reject the bad practices from the legacy C++.

Another suggestion concerns the decalaration of the shared pointers. Indeed, the smart pointers are now widly used, so why not provide a shortcut of declaring the shared pointer and instead of typing:

std::shared_ptr<Test> ptr_name;

only type:

ref Test ptr_name;

While this proposal may not introduce significant enhancements to the language, it is imperative to establish mechanisms that allow the compiler to safeguard the code against the legacy pitfalls of C++ programming.