Topic: bitset_view


Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Thu, 2 Oct 2014 21:05:23 -0700 (PDT)
Raw View
------=_Part_8094_1071566199.1412309123958
Content-Type: text/plain; charset=UTF-8

So from the other bitset thread came about the idea of a bitset_view class.

This would be an adapter which works like array_view.

array<uint32_t, 2> a;
bitset_view<uint32_t> bv = a;

bv.set(1); //sets the first bit of a[0];
bv.set(32); //sets the first bit of a[1];
bv.set(64); //Error!

It might be more interesting to use operator*() and operator->() to do the
bit operations and have the bitset_view methods just handle assigning to
array_views. With regards to const, bitset_view will have pointer semantics
like array_view. In other words, bitset_view<T> and const bitset_view<T>
are like T* and T* const, while bitset_view<const T> and const
bitset_view<const T> is like T const *, and T const * const.

template <typename T>
class bitset_adapter {
  public:
    bitset_adapter(const bitset_adapter<T>&) = delete;

    bool test() const;
    bitset_adapter& set();
    bitset_adapter& reset();
    //..
};

template <typename T>
class bitset_view {
  public:
    bitset_adapter& operator*();
    bitset_adapter* operator->();

    explicit bitset_view(array_view<T> a);
    bitset_view& operator=(array_view<T> a);

    //...
};

template <typename T>
class bitset_view<const T> {
 public:
  const bitset_adapter& operator*();
  const bitset_adapter* operator->();

  explicit bitset_view(array_view<const T> a);
  bitset_view& operator=(array_view<const T> a);

  //...
};


uint32_t a[2];
uint32_t a2[2];
bitset_view<uint32_t> bv = a;
bv->set(1); //sets first bit of a[0]
bv->set(63); //sets last bit of a[1];
bv->test(1); //returns true

const bitset_view<uint32_t> cbv = a;
bv->set(1); //Still ok, this is like T* const
bv->test(1); //Ok, const operation

cbv = a2; //Error, cbv is const!

const uin32_t ca[2];
bitset_view<const uint32_t> bvc = ca;
ca->test(1); //Ok, const operation returns false
ca->set(1); //Error, view is const!

bvc = a2; //Ok, const view over non-const data

const bitset_view<const uin32_t> cbvc = ca;
ca->test(1); //Ok const operation
ca->set(1); //Error, view is const!

cbvc = s2; //Error, cbvc is const!





--

---
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_8094_1071566199.1412309123958
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">So from the other bitset thread came about the idea of a b=
itset_view class.<div><br></div><div>This would be an adapter which works l=
ike array_view.&nbsp;</div><div><br></div><div><div class=3D"prettyprint" s=
tyle=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 18=
7, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"=
subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">a=
rray</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">uint32_t</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #066;" class=3D"styled-by-prettify">2</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> a</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br>bitset_view</span><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify">&lt;uint32_t&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> bv </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span><font color=3D"#000000"><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> a</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br><br>bv</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">.</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">set</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 style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">//sets the first bit of a[0];</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>bv</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">set</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">32</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">//sets the first bit of a[1];</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>bv</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">.</span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">set</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">6=
4</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">//Error!</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font></div></co=
de></div><br><div>It might be more interesting to use operator*() and opera=
tor-&gt;() to do the bit operations and have the bitset_view methods just h=
andle assigning to array_views. With regards to const, bitset_view will hav=
e pointer semantics like array_view. In other words, bitset_view&lt;T&gt; a=
nd const bitset_view&lt;T&gt; are like T* and T* const, while bitset_view&l=
t;const T&gt; and const bitset_view&lt;const T&gt; is like T const *, and T=
 const * const.</div><div><br></div><div><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 1=
87); word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">templ=
ate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"=
color: #660;" class=3D"styled-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-prettify">class</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> bitset_adapter </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: #008;" clas=
s=3D"styled-by-prettify">public</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>&nbsp; &nbsp; bitset_adapter</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> bitset_adapter</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&gt;&amp;)</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">delete</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> test</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">const</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>&nbsp; &nbsp; bitset_adapter</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">set</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br>&nbsp; &nbsp; </span><font color=3D"#000088"><span style=3D"=
color: #000;" class=3D"styled-by-prettify">bitset_adapter</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span></font><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> reset</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">//.. </span><span style=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><br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">template</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> T</span><span style=3D"color: #660;" class=3D"styled-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-prettify">class</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> bitset_view </sp=
an><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: #008;" class=3D"styled-by-prettify">public</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; bitset_adapter</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">*();</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; bitset_adapter</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-&gt;();</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">explicit</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> bitset_view</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">array_view</span><span st=
yle=3D"color: #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;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> a</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br>&nbsp; &nbsp; bitset_view</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">operator</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">array_view</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">//...</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</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">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
bitset_view</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>&nbsp;</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">public</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: #008;" class=3D=
"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> bitset_adapter</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">operator</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">*();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> bits=
et_adapter</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;();</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">explicit</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> bitset_view</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><font col=
or=3D"#000000"><span style=3D"color: #000;" class=3D"styled-by-prettify">ar=
ray_view</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span></font><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">&nbsp; bitset_view</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D(</span><font color=3D"#000000"><span style=3D"=
color: #000;" class=3D"styled-by-prettify">array_view</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span></font><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>&nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-pretti=
fy">//...</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br>uin=
t32_t a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</=
span><span style=3D"color: #066;" class=3D"styled-by-prettify">2</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">];</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>uint32_t a2</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"=
color: #066;" class=3D"styled-by-prettify">2</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">];</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>bitset_view</span><span style=3D"color: #080;=
" class=3D"styled-by-prettify">&lt;uint32_t&gt;</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> bv </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> a</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>bv</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">-&gt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">se=
t</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><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;=
" class=3D"styled-by-prettify">//sets first bit of a[0]</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>bv</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">-&gt;</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">set</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">63</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/=
/sets last bit of a[1];</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br>bv</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">-&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">test</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(<=
/span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">//returns true</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> bitset_view</span><span style=3D"color:=
 #080;" class=3D"styled-by-prettify">&lt;uint32_t&gt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> cbv </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> a</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>bv</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">-&gt;</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">set</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #800;" class=3D"styled-by-prettify">//Still ok, this is like T* const</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>bv</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">test</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 style=3D"color: #660;" =
class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-b=
y-prettify">//Ok, const operation</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br>cbv </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> a2</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//Erro=
r, cbv is const!</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">const</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
uin32_t ca</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
[</span><font color=3D"#006666"><span style=3D"color: #066;" class=3D"style=
d-by-prettify">2</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">];</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span></font><span style=3D"color: #000;" class=3D"styled-by-prettify">b=
itset_view</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> uint32_t</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> bvc </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> ca</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>ca</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">-&gt;</span><font color=3D"#000088"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">test</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">//Ok, const operation returns false</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span></font><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">ca</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">-&gt;</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">set</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #800;" class=3D"styled-by-prettify">//Error, view is const=
!</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>b=
vc </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> a2</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">//Ok, const view over non-const data<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> bitset_view</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> uin32_t</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> cbvc </span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> ca</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>ca</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">-&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">test</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 style=3D"color: #660;" class=3D"styled-by-prettify">)</span><font colo=
r=3D"#000000"><span style=3D"color: #660;" class=3D"styled-by-prettify">;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #800;" class=3D"styled-by-prettify">//Ok const operation<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
</font><span style=3D"color: #000;" class=3D"styled-by-prettify">ca</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">set</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 style=3D"color: #660;" =
class=3D"styled-by-prettify">)</span><font color=3D"#000000"><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" cla=
ss=3D"styled-by-prettify">//Error, view is const!</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span></font><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>cbvc </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> s2</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">/</span><font color=3D"#000000"><span style=3D"color: #800;" class=
=3D"styled-by-prettify">/Error, cbvc is const!</span></font><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br><br><br><br></span></div></c=
ode></div><br><br></div></div></div>

<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 />

------=_Part_8094_1071566199.1412309123958--

.


Author: rhalbersma@gmail.com
Date: Fri, 3 Oct 2014 12:52:00 -0700 (PDT)
Raw View
------=_Part_8687_1201817263.1412365920114
Content-Type: text/plain; charset=UTF-8

On Friday, October 3, 2014 6:05:24 AM UTC+2, Matthew Fioravante wrote:
>
> So from the other bitset thread came about the idea of a bitset_view class.
>

One issue with that would be that std::bitset<N> is not just a "dumb" view
over some array-like entity (std::array, array_view, C-array, pointer +
length, whatever), but it also has a class invariant that any bits above N
are zero-ed out. Any modification done through the bitset_view must
maintain that invariant.

But because bitset_view is just a view, it seems to me that it cannot
guarantee the invariant itself (outside functions might change the
underyling data), so this will induce overhead for every member function to
re-establish the class invariant. Only for say unsigned[N], you could still
have a bitset_view<N * sizeof(unsigned)> since that does not have excess
bits.

--

---
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_8687_1201817263.1412365920114
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Friday, October 3, 2014 6:05:24 AM UTC+2, Matthew Fiora=
vante wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">S=
o from the other bitset thread came about the idea of a bitset_view class.<=
/div></blockquote><div><br></div><div>One issue with that would be that std=
::bitset&lt;N&gt; is not just a "dumb" view over some array-like entity (st=
d::array, array_view, C-array, pointer + length, whatever), but it also has=
 a class invariant that any bits above N are zero-ed out. Any modification =
done through the bitset_view must maintain that invariant.&nbsp;</div><div>=
<br></div><div>But because bitset_view is just a view, it seems to me that =
it cannot guarantee the invariant itself (outside functions might change th=
e underyling data), so this will induce overhead for every member function =
to re-establish the class invariant. Only for say unsigned[N], you could st=
ill have a bitset_view&lt;N * sizeof(unsigned)&gt; since that does not have=
 excess bits.</div></div>

<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 />

------=_Part_8687_1201817263.1412365920114--

.


Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Mon, 6 Oct 2014 19:00:42 -0700 (PDT)
Raw View
------=_Part_3_1253931386.1412647242399
Content-Type: text/plain; charset=UTF-8



On Friday, October 3, 2014 3:52:00 PM UTC-4, rhalb...@gmail.com wrote:
>
>
> One issue with that would be that std::bitset<N> is not just a "dumb" view
> over some array-like entity (std::array, array_view, C-array, pointer +
> length, whatever), but it also has a class invariant that any bits above N
> are zero-ed out. Any modification done through the bitset_view must
> maintain that invariant.
>
> But because bitset_view is just a view, it seems to me that it cannot
> guarantee the invariant itself (outside functions might change the
> underyling data), so this will induce overhead for every member function to
> re-establish the class invariant. Only for say unsigned[N], you could still
> have a bitset_view<N * sizeof(unsigned)> since that does not have excess
> bits.
>

Where is there any requirement on the underlying bits in the bitset object
itself? As far as the public interface is concerned, the bitset value type
only consists of N bits.

If you're referring to the functions like toulong(), it would not be too
terrible to & the result with a compile time bitmask. Its only a single
cycle instruction.

In any case my current strong bitset proposal would already violate this
constraint because it proposes a method which will give the user non-const
access into to the underlying data.

--

---
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_3_1253931386.1412647242399
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, October 3, 2014 3:52:00 PM UTC-4, rhalb=
....@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div><br></div><div>One issue with that would be that std::bitset&=
lt;N&gt; is not just a "dumb" view over some array-like entity (std::array,=
 array_view, C-array, pointer + length, whatever), but it also has a class =
invariant that any bits above N are zero-ed out. Any modification done thro=
ugh the bitset_view must maintain that invariant.&nbsp;</div><div><br></div=
><div>But because bitset_view is just a view, it seems to me that it cannot=
 guarantee the invariant itself (outside functions might change the underyl=
ing data), so this will induce overhead for every member function to re-est=
ablish the class invariant. Only for say unsigned[N], you could still have =
a bitset_view&lt;N * sizeof(unsigned)&gt; since that does not have excess b=
its.</div></div></blockquote><div><br></div><div>Where is there any require=
ment on the underlying bits in the bitset object itself? As far as the publ=
ic interface is concerned, the bitset value type only consists of N bits.</=
div><div><br>If you're referring to the functions like toulong(), it would =
not be too terrible to &amp; the result with a compile time bitmask. Its on=
ly a single cycle instruction.</div><div><br></div><div>In any case my curr=
ent strong bitset proposal would already violate this constraint because it=
 proposes a method which will give the user non-const access into to the un=
derlying data.&nbsp;</div></div>

<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 />

------=_Part_3_1253931386.1412647242399--

.