220 13488 <B1C4DDBA-B386-4B07-A0CA-8E79FDD2E3A8@gmail.com> article
Path: news.gmane.org!not-for-mail
From: Nicola Gigante <nicola.gigante@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal: Strongly Typed Bitset
Date: Thu, 2 Oct 2014 09:51:34 +0200
Lines: 228
Approved: news@gmane.org
Message-ID: <B1C4DDBA-B386-4B07-A0CA-8E79FDD2E3A8@gmail.com>
References: <f77c8cc7-64f6-4d3b-9a10-8a5ee5f2254d@isocpp.org> <113390b2-9c74-47e2-a943-5d27dd48bdf1@isocpp.org> <CAGg_6+P+Hsq_stLp4+CTyK3ezvOvCAyCy7hBu+ZqSbJMfJHQ8w@mail.gmail.com> <41983d24-efb2-4255-b09b-f84cff7bf56d@isocpp.org> <f24d9028-86d6-4fc7-b5bf-03aacebb18d5@isocpp.org> <63de9d71-e3b0-4242-9698-bea3a307b3c7@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_C9433F83-B7B1-4B1D-A75B-6FFA9FCEE77B"
X-Trace: ger.gmane.org 1412236310 17480 80.91.229.3 (2 Oct 2014 07:51:50 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 2 Oct 2014 07:51:50 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDMMZOF5V4KBBCMIWSQQKGQEWFM6NBI@isocpp.org Thu Oct 02 09:51:44 2014
Return-path: <std-proposals+bncBDMMZOF5V4KBBCMIWSQQKGQEWFM6NBI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wg0-f72.google.com ([74.125.82.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDMMZOF5V4KBBCMIWSQQKGQEWFM6NBI@isocpp.org>)
	id 1XZbAo-0002Ij-Le
	for gclcip-std-proposals@m.gmane.org; Thu, 02 Oct 2014 09:51:38 +0200
Original-Received: by mail-wg0-f72.google.com with SMTP id m15sf800827wgh.3
        for <gclcip-std-proposals@m.gmane.org>; Thu, 02 Oct 2014 00:51:38 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:mime-version:subject:date
         :references:to:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=8Xxx/j0UArpQ4Gu+CVyk4MlB58/IVZ1VuyAUSwvjHv0=;
        b=JTEjwkQLNkynJdSxf7zxg4qM7J6EmYZZuUJTk3ia30Qy0NVMUSTMcvMTUtW27DhNkd
         m5CRxEZnzqkgkYUOuc1JeBbJjzozdkRoHVbAY9xoeEsKxfK2mqdOqR/bRH8F9VAN3XbK
         33szDUmBBqnaUHWjMPRIU56eFW7M4Rv+W3roKzv8Aj+SCFL2EsIhKWx4Xd+Egf1C32Lh
         W7O72HuHSPNTRwU2KeBEh1ldWXImFLvdrgskXCTJ1yYEhxF7w4gNkANEyl35yYiE4N+f
         CMn58KmAjb22tJWxMI8Mf2qjiciiGL5B5teLgQaYQMKkl3e1HdYwTPD1bi9P6h8uYJRL
         0k3A==
X-Gm-Message-State: ALoCoQmmQ/WRvTJlzoB9VCINB1iVIBxeFaJXtlr015jcFJ1nd4TRUw0y12LNi7ZKESOyuhzlSayf
X-Received: by 10.152.1.136 with SMTP id 8mr1354805lam.5.1412236298388;
        Thu, 02 Oct 2014 00:51:38 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.106.4 with SMTP id gq4ls32806wib.51.canary; Thu, 02 Oct
 2014 00:51:37 -0700 (PDT)
X-Received: by 10.194.78.76 with SMTP id z12mr45567593wjw.24.1412236297541;
        Thu, 02 Oct 2014 00:51:37 -0700 (PDT)
Original-Received: from mail-wi0-x22b.google.com (mail-wi0-x22b.google.com [2a00:1450:400c:c05::22b])
        by mx.google.com with ESMTPS id go6si207777wib.89.2014.10.02.00.51.37
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 02 Oct 2014 00:51:37 -0700 (PDT)
Received-SPF: pass (google.com: domain of nicola.gigante@gmail.com designates 2a00:1450:400c:c05::22b as permitted sender) client-ip=2a00:1450:400c:c05::22b;
Original-Received: by mail-wi0-f171.google.com with SMTP id em10so434527wid.16
        for <std-proposals@isocpp.org>; Thu, 02 Oct 2014 00:51:37 -0700 (PDT)
X-Received: by 10.194.71.195 with SMTP id x3mr31488696wju.27.1412236297094;
        Thu, 02 Oct 2014 00:51:37 -0700 (PDT)
Original-Received: from gigamac.fritz.box (adsl-ull-179-183.49-151.net24.it. [151.49.183.179])
        by mx.google.com with ESMTPSA id cw6sm3668659wjb.18.2014.10.02.00.51.35
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 02 Oct 2014 00:51:36 -0700 (PDT)
In-Reply-To: <63de9d71-e3b0-4242-9698-bea3a307b3c7@isocpp.org>
X-Mailer: Apple Mail (2.1878.6)
X-Original-Sender: nicola.gigante@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of nicola.gigante@gmail.com designates 2a00:1450:400c:c05::22b as
 permitted sender) smtp.mail=nicola.gigante@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=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: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:13488
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13488>

--Apple-Mail=_C9433F83-B7B1-4B1D-A75B-6FFA9FCEE77B
Content-Type: text/plain; charset=ISO-8859-1


Hi

Il giorno 02/ott/2014, alle ore 03:26, Matthew Fioravante <fmatthew5876@gmail.com> ha scritto:

> I've updated the draft with fast_bitset and small_bitset.
> 
> https://github.com/fmatthew5876/stdcxx-bitset
> 
> I had some ideas for additional directions to go into. I've not put these in the paper.
> 
> Some new public members:
> 
> template <size_t N, typename T> class bitset {
>   public:  
>     using underlying_type = T[N / (sizeof(T) * CHAR_BIT) + 1];
> 
>     array<T,sizeof(underlying_type) / sizeof(T)> get_underlying() const;
>     void set_underlying(array<T,sizeof(underlying_type) / sizeof(T)> a);
>  
> 
> get_underlying() would return an array of T whose bits are identical to the bits stored in the bitset. All of the bits > N would be 0.
> set_underlying(a) would set the internal bits to the values of the bits in a. All of the bits > N are ignored.
> 
> Alternatively, instead of value semantics we could do reference semantics:
> template <size_t N, typename T> class bitset {
>   public:  
>     using underlying_type = T[N / (sizeof(T) * CHAR_BIT) + 1];
> 
>     array<T,sizeof(underlying_type) / sizeof(T)>& rep();
>     const array<T,sizeof(underlying_type) / sizeof(T)>& rep() const;
> 
> 
> This is more dangerous as bitset is a value type which can be freely copied, but it might be more efficient for large bitsets.
> 

In my opinion this is a very useful feature! A lot of times I've wanted to use bitset but I couldn't because
I also needed to directly access the underlying data. I think this is a fundamental flaw in the current std::bitset
design. I'd farther suggest to make it simple to tie a bitset to an already existing buffer. Would it be difficult
to standardize a "bitset_view" class that just adapts an existing random access container and expose the
bit access capabilities of bitset? Then the old bitset could be implemented by wrapping this view over
a std::array, while wrapping over an array_view would make it possible to access already existing buffers.
Wrapping it over an std::vector, we'll have boost::dynamic_bitset for free.
In this way you could make the old bitset a simple typedef (given that the current proposal would
break the ABI anyway, why not?), but you could also leave bitset alone, not breaking the ABI in any way, 
and let users that need more power to use bitset_view over whichever container they like.

What do you think about this idea?

Bye,
Nicola

-- 

--- 
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/.

--Apple-Mail=_C9433F83-B7B1-4B1D-A75B-6FFA9FCEE77B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><div><br></div><div>Hi=
</div><br><div><div>Il giorno 02/ott/2014, alle ore 03:26, Matthew Fioravan=
te &lt;<a href=3D"mailto:fmatthew5876@gmail.com">fmatthew5876@gmail.com</a>=
&gt; ha scritto:</div><br class=3D"Apple-interchange-newline"><blockquote t=
ype=3D"cite"><div dir=3D"ltr">I've updated the draft with fast_bitset and s=
mall_bitset.<div><br></div><div><a href=3D"https://github.com/fmatthew5876/=
stdcxx-bitset">https://github.com/fmatthew5876/stdcxx-bitset</a><br></div><=
div><br></div><div>I had some ideas for additional directions to go into. I=
've not put these in the paper.</div><div><br></div><div>Some new public me=
mbers:</div><div><br></div><div><div class=3D"prettyprint" style=3D"backgro=
und-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-w=
rap: break-word; position: static; z-index: auto;"><code class=3D"prettypri=
nt"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</spa=
n> <span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span>siz=
e_t N<span style=3D"color: #660;" class=3D"styled-by-prettify">,</span> <sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">typename</span> T<sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span> <font co=
lor=3D"#000088">class</font> bitset <span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><br>&nbsp; <span style=3D"color: #008;" class=3D=
"styled-by-prettify">public</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">:</span> &nbsp;<br>&nbsp; &nbsp; <span style=3D"color: #00=
8;" class=3D"styled-by-prettify">using</span> underlying_type <span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span> T<span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">[</span>N <span style=3D"color: #=
660;" class=3D"styled-by-prettify">/</span> <span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">sizeof</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(</span>T<span style=3D"color: #660;" class=3D"styled-by-pret=
tify">)</span> <span style=3D"color: #660;" class=3D"styled-by-prettify">*<=
/span> CHAR_BIT<span style=3D"color: #660;" class=3D"styled-by-prettify">)<=
/span> <span style=3D"color: #660;" class=3D"styled-by-prettify">+</span> <=
span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">];</span><br><br>&nbsp; &nb=
sp; array<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</sp=
an>T<span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span>underlying_type<sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">)</span> <span style=
=3D"color: #660;" class=3D"styled-by-prettify">/</span><font><span style=3D=
"" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">sizeof</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"" class=3D"styled-by-prettify">T=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span></=
font><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span> =
get_underlying<span style=3D"color: #660;" class=3D"styled-by-prettify">()<=
/span> <span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><br>&nb=
sp; &nbsp; <span style=3D"color: #008;" class=3D"styled-by-prettify">void</=
span> set_underlying<span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span>array<span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span>T<span style=3D"color: #660;" class=3D"styled-by-prettify">,</spa=
n><font><span style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
 style=3D"" class=3D"styled-by-prettify">underlying_type</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">/</span><span style=3D"" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)&gt;</span><span style=3D"" class=3D"styled-by=
-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">);</span></font><br>&nbsp; </code></div><br>get_underlying() would retur=
n an array of T whose bits are identical to the bits stored in the bitset. =
All of the bits &gt; N would be 0.</div><div>set_underlying(a) would set th=
e internal bits to the values of the bits in a. All of the bits &gt; N are =
ignored.</div><div><br></div><div>Alternatively, instead of value semantics=
 we could do reference semantics:</div><div><div class=3D"prettyprint" styl=
e=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, =
187); word-wrap: break-word; position: static; z-index: auto;"><code class=
=3D"prettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">=
template</span> <span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span>size_t N<span style=3D"color: #660;" class=3D"styled-by-prettify"=
>,</span> <span style=3D"color: #008;" class=3D"styled-by-prettify">typenam=
e</span> T<span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</s=
pan> <font color=3D"#000088">class</font> bitset <span style=3D"color: #660=
;" class=3D"styled-by-prettify">{</span><br>&nbsp; <span style=3D"color: #0=
08;" class=3D"styled-by-prettify">public</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">:</span> &nbsp;<br>&nbsp; &nbsp; <span style=
=3D"color: #008;" class=3D"styled-by-prettify">using</span> underlying_type=
 <span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span> T<spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">[</span>N <span style=
=3D"color: #660;" class=3D"styled-by-prettify">/</span> <span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">sizeof</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span>T<span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)</span> <span style=3D"color: #660;" class=3D"styled-by-=
prettify">*</span> CHAR_BIT<span style=3D"color: #660;" class=3D"styled-by-=
prettify">)</span> <span style=3D"color: #660;" class=3D"styled-by-prettify=
">+</span> <span style=3D"color: #066;" class=3D"styled-by-prettify">1</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">];</span><br><b=
r>&nbsp; &nbsp; array<span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span>T<span style=3D"color: #660;" class=3D"styled-by-prettify">,=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span>underl=
ying_type<span style=3D"color: #660;" class=3D"styled-by-prettify">)</span>=
 <span style=3D"color: #660;" class=3D"styled-by-prettify">/</span><font><s=
pan style=3D"" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">sizeof</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"" class=3D"styled-by-=
prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>)</span></font><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;&amp;</span> rep<span style=3D"color: #660;" class=3D"styled-by-prettify=
">()</span><font><span style=3D"color: #660;" class=3D"styled-by-prettify">=
;</span><span style=3D"" class=3D"styled-by-prettify"><br></span></font>&nb=
sp; &nbsp; <span style=3D"color: #008;" class=3D"styled-by-prettify">const<=
/span> array<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span>T<span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">(</span>underlying_type=
<span style=3D"color: #660;" class=3D"styled-by-prettify">)</span> <span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">/</span><font><span style=
=3D"" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">sizeof</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"" class=3D"styled-by-prettif=
y">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</spa=
n></font><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;&amp=
;</span> rep<span style=3D"color: #660;" class=3D"styled-by-prettify">()</s=
pan> <span style=3D"color: #008;" class=3D"styled-by-prettify">const</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><br><br><=
/code></div><div><br></div>This is more dangerous as bitset is a value type=
 which can be freely copied, but it might be more efficient for large bitse=
ts.</div><div><br></div></div></blockquote><div><br></div><div>In my opinio=
n this is a very useful feature! A lot of times I&rsquo;ve wanted to use bi=
tset but I couldn&rsquo;t because</div><div>I also needed to directly acces=
s the underlying data. I think this is a fundamental flaw in the current st=
d::bitset</div><div>design. I&rsquo;d farther suggest to make it simple to =
tie a bitset to an already existing buffer. Would it be difficult</div><div=
>to standardize a &ldquo;bitset_view&rdquo; class that just adapts an exist=
ing random access container and expose the</div><div>bit access capabilitie=
s of bitset? Then the old bitset could be implemented by wrapping this view=
 over</div><div>a std::array, while wrapping over an array_view would make =
it possible to access already existing buffers.</div><div>Wrapping it over =
an std::vector, we&rsquo;ll have boost::dynamic_bitset for free.</div><div>=
In this way you could make the old bitset a simple typedef (given that the =
current proposal would</div><div>break the ABI anyway, why not?), but you c=
ould also leave bitset alone, not breaking the ABI in any way,&nbsp;</div><=
div>and let users that need more power to use bitset_view over whichever co=
ntainer they like.</div><div><br></div><div>What do you think about this id=
ea?</div></div><br><div>Bye,</div><div>Nicola</div></body></html>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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 />

--Apple-Mail=_C9433F83-B7B1-4B1D-A75B-6FFA9FCEE77B--

.
