C++ Logo

std-discussion

Advanced search

What is the reason of one rule of C++ ?

From: Vadim Flyagin <vadim.flyagin_at_[hidden]>
Date: Sun, 12 Nov 2023 06:04:42 +0200
Dear experts in the ISO C++ Standard!

Konstantin Vladimirov, who is an informatics lecturer at Moscow Institute
of Physics and Technology (in particular, he teaches C++), initiated a
discussion recently about the following issue in his Telegram channel [1].

He asked the following question and said that he does not know the answer,
nor have his subscribers found the answer yet. Maybe you could answer this
question? Below is my translation of this question from the Russian:

“Some strange kind of C++.

Respected reader of my channel @MSerhiy has noticed a funny thing: there
are different rules of overloading for structures and for primitive types
in this example: [2].

Quite soon, I grubbed up the answer in the standard.

C++20, [expr.type] "If a prvalue initially has the type “cv T”, where T is
a cv-unqualified non-class, non-array type, the type of the expression is
adjusted to T prior to any further analysis"

But I started pondering during the process for some reason. Just
hypothetically: why was this done so? This helps what things and when? I
have no ideas.

I propose to speculate concerning the source for this rule in this thread.”

Best wishes, Vadim.

[1] https://t.me/cpp_lects_rus/136

[2] https://godbolt.org/z/YT9bo7ore

Received on 2023-11-12 04:04:56