220 5830 <7d0bc129-f8aa-4803-bbd9-bd5ca504d728@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Remove vector<bool>?
Date: Mon, 26 Aug 2013 06:22:00 -0700 (PDT)
Lines: 256
Approved: news@gmane.org
Message-ID: <7d0bc129-f8aa-4803-bbd9-bd5ca504d728@isocpp.org>
References: <CAGsORuDQdeWAO5yjA6=h0hW9Y0Sj4F1gcHB61udw5JFmtx+g4Q@mail.gmail.com> <b06daeb3-a585-4c55-aebf-cae643146838@isocpp.org> <CAGg_6+O_d85CBjT+cTV6vQqepUTXVvUMV_QUioS6ELpQCav6GQ@mail.gmail.com>
 <521B07D2.8070000@beamways.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_64_15372834.1377523320745"
X-Trace: ger.gmane.org 1377523323 18523 80.91.229.3 (26 Aug 2013 13:22:03 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 26 Aug 2013 13:22:03 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCEKFTV6ZUMBB6VM5WIAKGQEOVGBCWQ@isocpp.org Mon Aug 26 15:22:05 2013
Return-path: <std-proposals+bncBCEKFTV6ZUMBB6VM5WIAKGQEOVGBCWQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f197.google.com ([209.85.214.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBB6VM5WIAKGQEOVGBCWQ@isocpp.org>)
	id 1VDwk7-0001br-EO
	for gclcip-std-proposals@m.gmane.org; Mon, 26 Aug 2013 15:22:03 +0200
Original-Received: by mail-ob0-f197.google.com with SMTP id eh20sf13627206obb.8
        for <gclcip-std-proposals@m.gmane.org>; Mon, 26 Aug 2013 06:22:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=JhfFr3VhLZ+1Eqr5sy/xPgsmwRALgTNgaro9NspgJ7A=;
        b=qhO1wg3viduZ8SqlqaDkx9KZDM04PEfaw+rs9WznEmqjGmfT8AQlyWKpJeczdgny+7
         KM9GsIplJRyzNwta5bmDPES/hNQDhtmKwncfevyq+C8/fnFJ38YOZRTktH5UgtDV8mgj
         AlV4pdRMQtn+/UM7VaywHBJH7iDM8+/mHVij8x6PFc/OgC+BddZ6Yy0g9SgGG4cGxNuX
         v2JfA5c1C0sqV3bJ+FUN+bdgEpyDBfxsN8jSo2oDVKxsFqlyKVmLsVHr0f9OQ4XPSF2V
         o9633iC2aDXCSN20YanR7vTfccuK6dhjh5L7krIQ5v1j9neS+LghQCXR5sRJv0P5T6x8
         PCFA==
X-Received: by 10.50.141.131 with SMTP id ro3mr7242969igb.2.1377523322369;
        Mon, 26 Aug 2013 06:22:02 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.17.70 with SMTP id m6ls2211411igd.4.gmail; Mon, 26 Aug 2013
 06:22:01 -0700 (PDT)
X-Received: by 10.50.109.165 with SMTP id ht5mr325688igb.11.1377523321873;
        Mon, 26 Aug 2013 06:22:01 -0700 (PDT)
In-Reply-To: <521B07D2.8070000@beamways.com>
X-Original-Sender: jmckesson@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:5830
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/5830>

------=_Part_64_15372834.1377523320745
Content-Type: text/plain; charset=ISO-8859-1

On Monday, August 26, 2013 12:46:26 AM UTC-7, Bengt Gustafsson wrote:
>
>  I was just trying to be pragmatic about solving the actual problems we 
> are discussing, which should be problems that are of interest to real 
> programmer's use of the language. I freely admit that the vector<bool> 
> specialization is a wart but I don't see that this actually creates a lot 
> of problems in the real world. Could anyone exemplify a reasonable usage 
> that fails in a hard to detect way?
>

It's not that it fails in a "hard to detect" way. Generally speaking, when 
vector<bool> fails to act like a `vector` of `bool`s, it's pretty noisy 
about it. The problem is that, silent or not, if you really needed an 
honest-to-God `vector` that contains `bool`s, you *can't get one*.
 

> The real problems I could detect with vector<bool> were that the 
> performance of algorithms like count() is significantly less than it could 
> be. I suggested how this could be solved in a way that is totally invisible 
> to the programmer. I also suggested that the API required could be 
> standardized to allow user-defined algorithms to take advantage of the 
> speedup.
>

 

> From a practical programmer's standpoint I think it is very neat that 
> vector<bool> hides the fact that there is a special implementation 
> underneath.
>

If it actually hid the fact, that might be true. But it doesn't. Consider 
the following:

void OperateOnBoolArray(const bool *array, size_t count);

vector<bool> stuff = {...};
OperateOnBoolArray(stuff.data(), stuff.size());

If the types here were anything *besides* `bool`, this would be perfectly 
legitimate code. But it's not..

Nothing is being hidden here; `vector<bool>` is not a `vector`. It doesn't 
provide the interface for a vector. And if you think this is too 
theoretical, consider some template code:

template<class T>
void Proc()
{
  vector<T> arr = {...};
  OperateOnArray(arr.data(), arr.size());
}

By all rights, this code *ought* to work with any type T. But it doesn't; 
if you stick `bool` in there, the compiler will fail, since `vector<bool>` 
doesn't have a `data` member. Because `vector<bool>` isn't a `vector` of 
`bool`s.
 

> If another very similar but different class is introduced I can't see that 
> this would make the language easier to understand or use.
>
 
>
If bit_vector is introduced all template code that uses vector<T> and would 
> benefit from a packed structure would need to be specialized for bool. Is 
> that really better?
>

No, it's not. The only way "bit_vector" is better is that it provides us a 
pathway whereby we can *get rid of `vector<bool>`*. That's the *only*reason we want it: so that people who currently use `vector<bool>` have a 
type that they can use. They can do a find-replace on "vector<bool>" with 
"bit_vector", and their code should immediately work as before. It needs to 
be a drop-in replacement so that they can stop using `vector<bool>`.

That way, C++17 can deprecate the `vector<bool>` specialization, and C++20 
can *remove* it. Then, we will have what we should have had 20 years 
before: a real `vector` that can contain real `bool`s, and a type that is a 
space-optimized pseudo-container that has `bool`-like stuff in it. We can 
even add new interfaces to that container, the way boost::dynamic_bitset 
has some useful functions on it.

>  

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_64_15372834.1377523320745
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Monday, August 26, 2013 12:46:26 AM UTC-7, Bengt Gustaf=
sson wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div text=3D"#000000" bgcolor=3D"#FFFFFF">
    I was just trying to be pragmatic about solving the actual problems
    we are discussing, which should be problems that are of interest to
    real programmer's use of the language. I freely admit that the
    vector&lt;bool&gt; specialization is a wart but I don't see that
    this actually creates a lot of problems in the real world. Could
    anyone exemplify a reasonable usage that fails in a hard to detect
    way?<br></div></blockquote><div><br>It's not that it fails in a "hard t=
o detect" way. Generally speaking, when vector&lt;bool&gt; fails to act lik=
e a `vector` of `bool`s, it's pretty noisy about it. The problem is that, s=
ilent or not, if you really needed an honest-to-God `vector` that contains =
`bool`s, you <i>can't get one</i>.<br>&nbsp;</div><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><div text=3D"#000000" bgcolor=3D"#FFFFFF">
   =20
    The real problems I could detect with vector&lt;bool&gt; were that
    the performance of algorithms like count() is significantly less
    than it could be. I suggested how this could be solved in a way that
    is totally invisible to the programmer. I also suggested that the
    API required could be standardized to allow user-defined algorithms
    to take advantage of the speedup.</div></blockquote><div><br>&nbsp;</di=
v><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><div text=3D"#000000" bgcolo=
r=3D"#FFFFFF">From a practical programmer's standpoint I think it is very n=
eat
    that vector&lt;bool&gt; hides the fact that there is a special
    implementation underneath.</div></blockquote><div><br>If it actually hi=
d the fact, that might be true. But it doesn't. Consider the following:<br>=
<br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250=
); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px=
; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpret=
typrint"><span style=3D"color: #008;" class=3D"styled-by-prettify">void</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">OperateOnBoolArray</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">bool</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">array</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> size_t count</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
<br>vector</span><span style=3D"color: #080;" class=3D"styled-by-prettify">=
&lt;bool&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> stuff </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">{...};</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">OperateOnBoolArray</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">stuff</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">data</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(),</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> stuff</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">size</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">());</span></div></code></div><br>If the types here were anything <i>besi=
des</i> `bool`, this would be perfectly legitimate code. But it's not..<br>=
<br>Nothing is being hidden here; `vector&lt;bool&gt;` is not a `vector`. I=
t doesn't provide the interface for a vector. And if you think this is too =
theoretical, consider some template code:<br><br><div class=3D"prettyprint"=
 style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187,=
 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">Proc</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>&nbsp; vector</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> arr </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
{...};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
&nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Ope=
rateOnArray</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">arr</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">data</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(),</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> arr</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">size</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">());</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span></div></code></div><br>By all rights, this code <i>ought</i> to wo=
rk with any type T. But it doesn't; if you stick `bool` in there, the compi=
ler will fail, since `vector&lt;bool&gt;` doesn't have a `data` member. Bec=
ause `vector&lt;bool&gt;` isn't a `vector` of `bool`s.<br>&nbsp;</div><bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div text=3D"#000000" bgcolor=3D"#F=
FFFFF">If another very similar but different
    class is introduced I can't see that this would make the language
    easier to understand or use.<br></div></blockquote><blockquote style=3D=
"margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padd=
ing-left: 1ex;" class=3D"gmail_quote"><div>&nbsp;</div></blockquote><blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;"><div text=3D"#000000" bgcolor=3D"#FFF=
FFF">
   =20
    If bit_vector is introduced all template code that uses
    vector&lt;T&gt; and would benefit from a packed structure would need
    to be specialized for bool. Is that really better?<br></div></blockquot=
e><div><br>No, it's not. The only way "bit_vector" is better is that it pro=
vides us a pathway whereby we can <i>get rid of `vector&lt;bool&gt;`</i>. T=
hat's the <i>only</i> reason we want it: so that people who currently use `=
vector&lt;bool&gt;` have a type that they can use. They can do a find-repla=
ce on "vector&lt;bool&gt;" with "bit_vector", and their code should immedia=
tely work as before. It needs to be a drop-in replacement so that they can =
stop using `vector&lt;bool&gt;`.<br><br>That way, C++17 can deprecate the `=
vector&lt;bool&gt;` specialization, and C++20 can <i>remove</i> it. Then, w=
e will have what we should have had 20 years before: a real `vector` that c=
an contain real `bool`s, and a type that is a space-optimized pseudo-contai=
ner that has `bool`-like stuff in it. We can even add new interfaces to tha=
t container, the way boost::dynamic_bitset has some useful functions on it.=
<br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div text=3D"#000000=
" bgcolor=3D"#FFFFFF">
  </div>

</blockquote></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_64_15372834.1377523320745--

.
