In the biggest change to C++ syntax, ->
and ::
operators are to be replaced by .
operator in the upcoming C++23 AF00L proposal. The rationale behind this proposal is there can be no confusion (as to which operator to use).
The ::
operator is not only used in scope resolution and also as class-to-static_member. However, another way to refer to a static member is through the object instance. All these leads to subtle confusion as to what ::
actually denotes.
// class with static member struct Widget { static int Count; }; Widget o; Widget* p = &o; // Accessing Widget's static Count int a = Widget::Count; int b = o.Count; int c = p->Count;
The ::
operator is also used by scoped enum to refer to its enumerators.
// enum class enum class Fruit { Apple, Orange, Banana }; // usage of scoped enum Fruit::Orange
Efforts to mimick the C++11 scoped enum syntax without its safety is by enclosing unscoped enum inside a namespace or class. So ::
operator actually does not tell the developer reading the enum usage about the enum type.
// namespace scoped enum namespace Fruit { enum fruit { Apple, Orange, Banana } }; // usage of namespace scoped enum Fruit::Orange
Moreover, when an unscoped enum is a class member, its enumerators may be accessed using class member access operators .
and ->
. All these adds up to the confusion.
// class scoped enum struct Fruit { enum fruit { Apple, Orange, Banana } }; // usage of class scoped enum Fruit::Orange Fruit x; Fruit* p = &x; int c = x.Orange; int d = p->Orange;
Similarly, the ->
operator is not only used in pointer-to-member but also to indicate return type of lambda.
// Example of C++11 lambda with boolean return type auto lambda = []() -> bool {...}
In C++17, the ->
operator is used in type deduction guides(See code example below).
// C++17 Deduction Guides template<typename T> struct S { T val; }; // map string literals to S<std::string> S(const char*) -> S<std::string>;
In an effort to end all confusion in one fell swoop, ->
and ::
operators are going to be deprecated in favor of the universal .
operator.
In addition to this new development, C++23 is going to get garbage collection to manage its memory and every C++ class inherits automatically from the base Object class!
“That’s great news! I can make use of my father’s 1995 original Java textbook to learn C++23!” – Russian college student, Sabina
Before anyone makes a serious commentary to this blog post, take a good look at the posting date!
For those who like this year’s April’s Fool post, be sure to check out 2019 and 2020 April’s Fool post:
Leave a Reply to Put sleep() to make more money from HFT. And Lock-free vs Block-free – Coding Tidbit Cancel reply