Since 2011 many new features were added to the standards, some of them are now very used like auto and nullptr, some others are rarely used. However, the most important changes that can bring the language to the next level are in the pipe.
Modules
The legacy #include mechanism is still there and it has many disadvantages, here are some of them from this interesting document.
Modules improve access to libraries with more robust and more efficient semantic model. From the user’s perspective, the code looks only slightly different, because one uses an import declaration rather than a #include preprocessor directive:
import std; // Module import directive.int main() { std::cout << “Hello World\n”;}
No need to include many files of STL, just one import is sufficient, the code became cleaner. The module import loads a binary representation of the std module and makes its API available to the application directly. Preprocessor definitions that precede the import declaration have no impact on the API provided by std because the module itself was compiled as a separate, standalone module.
MetaClass
Herb Sutter contributes for many years to make C++ a better language, and the last year he proposes the metaclasses feature. here’s from his post the motivation behind adding it:
I’ve been working on an experimental new C++ language feature tentatively called “metaclasses” that aims to make C++ programming both more powerful and simpler.
And here’s from the proposal, a definition of metaclasses and the benefits of using it:
Metaclasses(provisional name) let programmers write a new kind of efficient abstraction: a user-defined named subset of classes that share common characteristics – including user-defined rules, defaults, and generated functions – by writing a custom transformation from normal C++ source code to a normal C++ class definition. There is no type system bifurcation; the generated class is a normal class.
Primary goals:
· Expand C++’s abstraction vocabulary beyond class/struct/union/enum which are the type categories hardwired into the language.
· Enable providing longstanding best practices as reusable libraries instead of English guides/books, to have an easily adopted vocabulary (e.g., interface, value) instead of lists of rules to be memorized (e.g., remember this coding pattern to write an abstract base class or value type, relying on tools to find mistakes).
· Enable writing compiler-enforced patterns for any purpose: coding standards(e.g., many Core Guidelines “enforce” rules), API requirements (e.g., rules a class must follow to work with a hardware interface library, a browser extension, a callback mechanism), and any other pattern for classes.
· Enable writing many new “specialized types” features(e.g., as we did in C++11 with enum class) as ordinary library code instead of pseudo-English standardese, with equal usability and efficiency, so that they can be unit-tested and debugged using normal tools, developed/distributed without updating/shipping a new compiler, and go through LEWG/LWG as code instead of EWG/CWG as standardese. As a consequence, enable standardizing valuable extensions that we’d likely never standardize in the core language because they are too narrow (e.g., interface), but could readily standardize as a small self-contained library.
· Eliminate the need to invent non-C++ “side languages” and special compilers, such as Qt moc, COM MIDL, and C++/CX, to express the information their systems need but cannot be expressed in today’s C++ (such as specialized types for properties, event callbacks, and similar abstractions).
With Modules and Metaclasses, the C++ will be more powerful and easy to use, and in the future, many new features will be added. what we can say is Thanks to all the C++ contributors who help to improve the language and long life to C++
联系客服