Topic: bit_mask class (was compressed std::bitset<N>)
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sun, 19 Feb 2017 09:39:01 +0100
Raw View
This is a multi-part message in MIME format.
--------------2223C6D1B79EC08D68A40920
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 16/02/2017 =C3=A0 11:00, Marc a =C3=A9crit :
> On Thursday, February 16, 2017 at 8:04:53 AM UTC+1, Vicente J. Botet=20
> Escriba wrote:
>
> Hi,
>
> I wanted to use bitset<8>,bitset<16>,bitset<32> to represent the
> mask of 8,16 and 32 bits respectively but the sizeof them is 64
> bits on the systems I've tested.
>
> Wondering if others have suffered already of this situation.
>
> How do you fill about adding a constraint on the implementation,
> so that the sizeof shall be respectively 8, 16, 32 bits.
>
> If this is not backward compatible, would it be worth to define a
> different type?
>
>
> That's really QoI. Trying to use the standard to force implementations=20
> to improve on this point seems wrong to me.
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D63218
> (didn't check for other implementations)
Thanks for the link. It seems that we cannot change it without breaking=20
changes.
My use case is a project that is using uint8_t, uint16_t, uint32_t as=20
representation type for bit mask. I would like to replace those uintxx_t=20
types by a wrapper bit_mask<uintxx_t, N> that wraps a uintxx_t=20
restricted to N bits and that defines the domain operations and no more.
template <class T, unsigned N =3D ...> // N can default to the number=
=20
if bits of T
struct bit_mask {
T mask;
public:
...
};
There is a point I don't understood in [1]. it seems that we cannot ensure
alignof(bit_mask<uint32_t, N>) =3D=3D alignof(uint32_t)
is this correct? If yes, could I have a pointer to the standard wording?
Couldn't alignas help here
template <class T, unsigned N =3D ...> // N can default to the number =
if bits of T
struct alignas(T) bit_mask;
Wouldn't this ensure that
alignof(bit_mask<uint32_t, N>) =3D=3D alignof(uint32_t)
?
Is there an interest on a bit_mask<uintxx_t, N> class?
Vicente
[1] Controlling bitset's underlying type
https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/UjNcLLrGwv=
8/Pe1Icl6h6xQJ
--=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/b75ea3ff-b0f4-674e-26db-7b0c592780a0%40wanadoo.f=
r.
--------------2223C6D1B79EC08D68A40920
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 16/02/2017 =C3=A0 11:00, Marc a =C3=
=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:4fda10c9-d748-4874-bc14-5ee952956c99@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">On Thursday, February 16, 2017 at 8:04:53 AM UTC+1,
Vicente J. Botet Escriba wrote:
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<p><font size=3D"+1">Hi,</font></p>
<p><font size=3D"+1">I wanted to use bitset<8>,</font><fo=
nt
size=3D"+1"> bitset<16>,</font><font size=3D"+1">
bitset<32> to represent the mask of 8,16 and 32
bits respectively but the sizeof them is 64 bits on the=C2=
=A0
systems I've tested.</font></p>
<p><font size=3D"+1">Wondering if others have suffered already
of this situation. <br>
</font></p>
<p><font size=3D"+1">How do you fill about adding a constraint
on the implementation, so that the sizeof shall be
respectively 8, 16, 32 bits.</font></p>
<p><font size=3D"+1">If this is not backward compatible, would
it be worth to define a different type?<br>
</font></p>
</div>
</blockquote>
<div><br>
That's really QoI. Trying to use the standard to force
implementations to improve on this point seems wrong to me.<br>
<a class=3D"moz-txt-link-freetext" href=3D"https://gcc.gnu.org/bu=
gzilla/show_bug.cgi?id=3D63218">https://gcc.gnu.org/bugzilla/show_bug.cgi?i=
d=3D63218</a><br>
(didn't check for other implementations)<br>
</div>
</div>
</blockquote>
<br>
Thanks for the link. It seems that we cannot change it without
breaking changes.<br>
<br>
My use case is a project that is using uint8_t, uint16_t, uint32_t
as representation type for bit mask. I would like to replace those
uintxx_t types by a wrapper bit_mask<uintxx_t, N> that wraps a
uintxx_t restricted to N bits and that defines the domain operations
and no more.<br>
<br>
=C2=A0=C2=A0=C2=A0 template <class T, unsigned N =3D ...> // N ca=
n default to
the number if bits of T<br>
=C2=A0=C2=A0=C2=A0 struct bit_mask {<br>
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 T mask;<br>
=C2=A0=C2=A0=C2=A0 public: <br>
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 ...<br>
=C2=A0=C2=A0=C2=A0 };<br>
<br>
There is a point I don't understood in [1]. it seems that we cannot
ensure <br>
<br>
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8=
">
=C2=A0=C2=A0=C2=A0 alignof(bit_mask<uint32_t, N>) =3D=3D alignof(=
uint32_t)<br>
<br>
is this correct? If yes, could I have a pointer to the standard
wording?<br>
<br>
Couldn't alignas help here<br>
<pre class=3D"de1">=C2=A0=C2=A0=C2=A0 template <class T, unsigned N =
=3D ...> // N can default to the number if bits of T
=C2=A0=C2=A0=C2=A0 struct alignas(T) bit_mask;
<span class=3D"br0"></span></pre>
<br>
Wouldn't this ensure that<br>
<br>
=C2=A0=C2=A0=C2=A0 alignof(bit_mask<uint32_t, N>) =3D=3D alignof(=
uint32_t)<br>
<br>
?<br>
<br>
Is there an interest on a=C2=A0 bit_mask<uintxx_t, N> class?<br>
<br>
<br>
Vicente<br>
<br>
[1]
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8=
">
<span class=3D"IVILX2C-mb-Y" id=3D"t-t">Controlling bitset's underlying
type<br>
</span><a class=3D"moz-txt-link-freetext" href=3D"https://groups.google=
..com/a/isocpp.org/forum/#!msg/std-proposals/UjNcLLrGwv8/Pe1Icl6h6xQJ">https=
://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/UjNcLLrGwv8/Pe1=
Icl6h6xQJ</a><br>
</body>
</html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b75ea3ff-b0f4-674e-26db-7b0c592780a0%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b75ea3ff-b0f4-674e-26db-7b0c592780a0=
%40wanadoo.fr</a>.<br />
--------------2223C6D1B79EC08D68A40920--
.