C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Fixing some initialization gotchas
From: Maciej Cencora (m.cencora_at_[hidden])
Date: 2019-08-23 16:52:04


pt., 23 sie 2019 o 23:00 Hyman Rosen via Std-Proposals <
std-proposals_at_[hidden]> napisał(a):

> I am not in favor of the status quo. I believe that C++ is broken,
> probably beyond redemption, and I'm dubious that band-aid fixes
> here and there are going to make things better.
>
> You say when you look at `auto x = {1}`, the only logical explanation in
> your mind is that the RHS is an initializer list but you have no intuition
> for `auto x{1}`. But in the context of teaching C++, why would that be?
> What is it about the presence or absence of the `=` that will speak to
> the intuition of the student? Are students supposed to know about
> initializer lists at all? Aren't they supposed to be behind-the scenes
> magic that let you write intuitive initializers without thinking about how
> they work?
>
> Also, even without `auto` things are unteachably strange.
>
> `vector<int>vi3{3};` gives me a vector containing a single 3.
> `vector<string>vs3{3};` gives me a vector containing 3 empty strings.
> `vector<int>vi0{0};` gives me a vector containing a single 0.
> `vector<string>vs0{0};` has undefined behavior and usually crashes.
>
> If I use `=` before the braces, the only thing that changes is that the
> `vs3` line doesn't compile, with messages about vector's constructor
> being explicit.
>

Fortunately with ranges we are very close on fixing all these issues.
We just need one more range - the one that generates same number n-times.
And then we can deprecate and eventually remove all containers
constructors, except 4: default, copy/move, from range, from initializer
list.
Then no more ambiguites, no more surprising results.

-- 
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups