C++ Logo

std-proposals

Advanced search

End of the east const vs. const west war - auto type deduction for const.

From: Robert Kubok <robert.kbk_at_[hidden]>
Date: Wed, 21 Aug 2019 14:49:52 +0000
Hello,
I have a proposal referring to endless war between C++ programmers: east const vs const west. My suggestion is lead by urge to end this war and the solution is automatic type deduction for const keyword. Today we use const in many places and I'm convinced that this is one of the most used keywords in C++.
The 'const' keyword could implicitly deduce type, just as 'auto' keyword does. But as always, it's better to see an example:

This kind of syntax:
const name = std::string("Robert");

would be equivalent to:
const auto name = std::string("Robert"); // I'm a west-conster myself 😉
const std::string name("Robert");

Or range-for usage:
for( const& element : someContainer ) {
    // ...
}

The thing is: where 'const' keyword can be treated as 'auto' it will be, otherwise it will be treated just as if nothing changed. In my opinion, this kind of syntax will find many use cases, just because 'const' keyword is so popular. It will ease the usage of 'const' and will make more people actually use it. It will be similar to JavaScript's 'const', syntax-wise.



Received on 2019-08-21 09:51:56