Topic: A Proposal to Add a Logical Const Wrapper to the
Author: Jonathan Coe <jonathanbcoe@gmail.com>
Date: Thu, 24 Apr 2014 10:47:43 -0700 (PDT)
Raw View
------=_Part_2885_15499990.1398361663447
Content-Type: text/plain; charset=UTF-8
Following discussion on the BSI and c++std-lib mailing lists I propose an
addition to the C++ Standard Library to make logical const-ness easy to
implement and easy to spot in code review:
https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=sharing
All thoughts are welcome.
Kind regards,
Jonathan Coe
--
---
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_2885_15499990.1398361663447
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Following discussion on the BSI and c++std-lib mailin=
g lists I propose an addition to the C++ Standard Library to make logical c=
onst-ness easy to implement and easy to spot in code review:</div><div><br>=
</div><div><a href=3D"https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0ty=
R1FRWFk/edit?usp=3Dsharing">https://drive.google.com/file/d/0B5BUDfRWFDPva1=
pOM0tyR1FRWFk/edit?usp=3Dsharing</a><br></div><div><br></div><div>All thoug=
hts are welcome.</div><div><br></div><div>Kind regards,</div><div><br></div=
><div>Jonathan Coe</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" 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_2885_15499990.1398361663447--
.
Author: "'Geoffrey Romer <gromer@google.com>' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 24 Apr 2014 10:56:26 -0700
Raw View
--047d7bdc84c46d560e04f7cd9193
Content-Type: text/plain; charset=UTF-8
I'd suggest providing a link to a rendered web page, not raw HTML. See here
for how to do that: https://support.google.com/drive/answer/2881970?hl=en
On Thu, Apr 24, 2014 at 10:47 AM, Jonathan Coe <jonathanbcoe@gmail.com>wrote:
> Following discussion on the BSI and c++std-lib mailing lists I propose an
> addition to the C++ Standard Library to make logical const-ness easy to
> implement and easy to spot in code review:
>
>
> https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=sharing
>
> All thoughts are welcome.
>
> Kind regards,
>
> Jonathan Coe
>
> --
>
> ---
> 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/.
>
--
---
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/.
--047d7bdc84c46d560e04f7cd9193
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I'd suggest providing a link to a rendered web pa=
ge, not raw HTML. See here for how to do that:=C2=A0<a href=3D"https://supp=
ort.google.com/drive/answer/2881970?hl=3Den">https://support.google.com/dri=
ve/answer/2881970?hl=3Den</a></div>
</div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">On Thu,=
Apr 24, 2014 at 10:47 AM, Jonathan Coe <span dir=3D"ltr"><<a href=3D"ma=
ilto:jonathanbcoe@gmail.com" target=3D"_blank">jonathanbcoe@gmail.com</a>&g=
t;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Following discussion o=
n the BSI and c++std-lib mailing lists I propose an addition to the C++ Sta=
ndard Library to make logical const-ness easy to implement and easy to spot=
in code review:</div>
<div><br></div><div><a href=3D"https://drive.google.com/file/d/0B5BUDfRWFDP=
va1pOM0tyR1FRWFk/edit?usp=3Dsharing" target=3D"_blank">https://drive.google=
..com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=3Dsharing</a><br></div><d=
iv><br>
</div><div>All thoughts are welcome.</div><div><br></div><div>Kind regards,=
</div><div><br></div><div>Jonathan Coe</div></div><span class=3D"HOEnZb"><f=
ont color=3D"#888888">
<p></p>
-- <br>
<br>
--- <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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--047d7bdc84c46d560e04f7cd9193--
.
Author: Jonathan Coe <jonathanbcoe@gmail.com>
Date: Thu, 24 Apr 2014 10:57:43 -0700 (PDT)
Raw View
------=_Part_596_23306621.1398362263457
Content-Type: text/plain; charset=UTF-8
pdf available here:
https://drive.google.com/file/d/0B5BUDfRWFDPvczNXWmtiSmJiVnM/edit?usp=sharing
On Thursday, April 24, 2014 6:47:43 PM UTC+1, Jonathan Coe wrote:
>
> Following discussion on the BSI and c++std-lib mailing lists I propose an
> addition to the C++ Standard Library to make logical const-ness easy to
> implement and easy to spot in code review:
>
>
> https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=sharing
>
> All thoughts are welcome.
>
> Kind regards,
>
> Jonathan Coe
>
--
---
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_596_23306621.1398362263457
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">pdf available here:<div><br></div><div><a href=3D"https://=
drive.google.com/file/d/0B5BUDfRWFDPvczNXWmtiSmJiVnM/edit?usp=3Dsharing">ht=
tps://drive.google.com/file/d/0B5BUDfRWFDPvczNXWmtiSmJiVnM/edit?usp=3Dshari=
ng</a></div><div><br></div><div><br><br>On Thursday, April 24, 2014 6:47:43=
PM UTC+1, Jonathan Coe wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr"><div>Following discussion on the BSI and c++std-lib mailin=
g lists I propose an addition to the C++ Standard Library to make logical c=
onst-ness easy to implement and easy to spot in code review:</div><div><br>=
</div><div><a href=3D"https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0ty=
R1FRWFk/edit?usp=3Dsharing" target=3D"_blank" onmousedown=3D"this.href=3D'h=
ttps://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp\75shar=
ing';return true;" onclick=3D"this.href=3D'https://drive.google.com/file/d/=
0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp\75sharing';return true;">https://driv=
e.google.com/file/<wbr>d/<wbr>0B5BUDfRWFDPva1pOM0tyR1FRWFk/<wbr>edit?usp=3D=
sharing</a><br></div><div><br></div><div>All thoughts are welcome.</div><di=
v><br></div><div>Kind regards,</div><div><br></div><div>Jonathan Coe</div><=
/div></blockquote></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" 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_596_23306621.1398362263457--
.
Author: Jonathan Coe <jonathanbcoe@gmail.com>
Date: Thu, 24 Apr 2014 11:05:43 -0700 (PDT)
Raw View
------=_Part_1_9212445.1398362743221
Content-Type: text/plain; charset=UTF-8
link as requested by Geoffrey Romer:
https://googledrive.com/host/0B5BUDfRWFDPvNGNsWmRJZFp1YU0/logical_const.html
On Thursday, April 24, 2014 6:47:43 PM UTC+1, Jonathan Coe wrote:
>
> Following discussion on the BSI and c++std-lib mailing lists I propose an
> addition to the C++ Standard Library to make logical const-ness easy to
> implement and easy to spot in code review:
>
>
> https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=sharing
>
> All thoughts are welcome.
>
> Kind regards,
>
> Jonathan Coe
>
--
---
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_1_9212445.1398362743221
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">link as requested by Geoffrey Romer:<div><br></div><div><a=
href=3D"https://googledrive.com/host/0B5BUDfRWFDPvNGNsWmRJZFp1YU0/logical_=
const.html">https://googledrive.com/host/0B5BUDfRWFDPvNGNsWmRJZFp1YU0/logic=
al_const.html</a></div><div><br></div><div><br><br>On Thursday, April 24, 2=
014 6:47:43 PM UTC+1, Jonathan Coe wrote:<blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr"><div>Following discussion on the BSI and c++std=
-lib mailing lists I propose an addition to the C++ Standard Library to mak=
e logical const-ness easy to implement and easy to spot in code review:</di=
v><div><br></div><div><a href=3D"https://drive.google.com/file/d/0B5BUDfRWF=
DPva1pOM0tyR1FRWFk/edit?usp=3Dsharing" target=3D"_blank" onmousedown=3D"thi=
s.href=3D'https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit=
?usp\75sharing';return true;" onclick=3D"this.href=3D'https://drive.google.=
com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp\75sharing';return true;">h=
ttps://drive.google.com/file/<wbr>d/<wbr>0B5BUDfRWFDPva1pOM0tyR1FRWFk/<wbr>=
edit?usp=3Dsharing</a><br></div><div><br></div><div>All thoughts are welcom=
e.</div><div><br></div><div>Kind regards,</div><div><br></div><div>Jonathan=
Coe</div></div></blockquote></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" 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_1_9212445.1398362743221--
.
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Thu, 24 Apr 2014 20:22:02 +0200
Raw View
Hi Jonathan,
While I am not against your proposed class as such, I think I disagree
with the premise of your paper. If I have a pointer type:
using P = int*;
and make a const object of that type:
const P p = ...;
I can't modify the pointer:
p++; // error
but I can modify what it points to:
(*p)++; // ok
Notice the four types `pointer to int`, `const pointer to int`,
`pointer to const int` and `const pointer to const int` are distinct
types.
Conceptually this is the same as the situation you describe, and so
should be equally surprising. I think neither are.
Regards,
Andrew.
On Thu, Apr 24, 2014 at 7:47 PM, Jonathan Coe <jonathanbcoe@gmail.com> wrote:
> Following discussion on the BSI and c++std-lib mailing lists I propose an
> addition to the C++ Standard Library to make logical const-ness easy to
> implement and easy to spot in code review:
>
> https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=sharing
>
> All thoughts are welcome.
>
> Kind regards,
>
> Jonathan Coe
>
> --
>
> ---
> 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/.
--
---
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/.
.
Author: hbchai@google.com
Date: Thu, 24 Apr 2014 15:01:25 -0700 (PDT)
Raw View
------=_Part_15_32523617.1398376885625
Content-Type: text/plain; charset=UTF-8
Hi Jonathan,
I've created and used a wrapper class similar in intent to logical_const,
and have found it very useful. Here are some thoughts I have:
- Might want to flesh out the motivation aspect for adding this. For me,
the key problem was thread-safety, in particular the requirement that const
methods of objects documented as being thread-compatible never mutate
shared state.
- It should be noted that logical_const does not magically propagate to
nested pointers.
- The overloaded conversion operators were unfamiliar to me and likely
would be a source of confusion. When wrapping types, I elected to add a
special internal() method which returned that type.
I do wish something like this were in the standard.
Best,
Haw-Bin Chai
--
---
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_15_32523617.1398376885625
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Hi Jonathan,</div><div><br></div><div>I've created an=
d used a wrapper class similar in intent to logical_const, and have found i=
t very useful. Here are some thoughts I have:</div><div><br></div><div>- Mi=
ght want to flesh out the motivation aspect for adding this. For me, the ke=
y problem was thread-safety, in particular the requirement that const metho=
ds of objects documented as being thread-compatible never mutate shared sta=
te.</div><div><br></div><div><span style=3D"font-size: 13px;">- It should b=
e noted that logical_const does not magically propagate to nested pointers.=
</span><br></div><div><br></div><div>- The overloaded conversion operators =
were unfamiliar to me and likely would be a source of confusion. When wrapp=
ing types, I elected to add a special internal() method which returned that=
type.</div><div><br></div><div>I do wish something like this were in the s=
tandard.</div><div><br></div><div>Best,</div><div>Haw-Bin Chai</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" 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_15_32523617.1398376885625--
.
Author: Jonathan Coe <jonathanbcoe@gmail.com>
Date: Fri, 25 Apr 2014 01:40:02 -0700 (PDT)
Raw View
------=_Part_246_32026235.1398415202448
Content-Type: text/plain; charset=UTF-8
Andrew,
While I agree that the behaviour in the example you give is unsurprising
nearly all of the C++ programmers I have spoken to are caught out by the
same behaviour in the context of pointer members and const functions. If
real programmers with decades of experience can be caught out then this
behaviour is at least a nasty 'gotcha'.
Geoffrey and Haw-Bin
Thanks for your very helpful comments (brain-dump was very useful). I'll
reply in due course.
regards,
Jon
--
---
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_246_32026235.1398415202448
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Andrew,<div>While I agree that the behaviour in the exampl=
e you give is unsurprising nearly all of the C++ programmers I have spoken =
to are caught out by the same behaviour in the context of pointer members a=
nd const functions. If real programmers with decades of experience can be c=
aught out then this behaviour is at least a nasty 'gotcha'.</div><div><br><=
/div><div>Geoffrey and Haw-Bin</div><div>Thanks for your very helpful comme=
nts (brain-dump was very useful). I'll reply in due course.</div><div><br><=
/div><div>regards,</div><div><br></div><div>Jon</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" 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_246_32026235.1398415202448--
.
Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Mon, 26 May 2014 12:59:41 -0700 (PDT)
Raw View
------=_Part_319_14940061.1401134381757
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thursday, 24 April 2014 18:47:43 UTC+1, Jonathan Coe wrote:
>
> Following discussion on the BSI and c++std-lib mailing lists I propose an=
=20
> addition to the C++ Standard Library to make logical const-ness easy to=
=20
> implement and easy to spot in code review:
>
>
> https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=3Ds=
haring
>
> All thoughts are welcome.
>
> Kind regards,
>
> Jonathan Coe
>
I like the idea of a logical_const, as I also feel that const is broken as=
=20
it currently exists, but to repair it would have the potential of breaking=
=20
much code :(
I don't believe, however, that this is the right approach, as it doesn't=20
fix the problem.
Consider the following:
struct A {
int valA;
};
struct B {
A a;
int valB;
};
struct C {
std::logical_const<B *> b;
};
const C c {/* ... */};
In this, valB cannot be changed, due to the logical_const, but as=20
logical_const itself is only a shallow const, valA can be changed. In=20
fact, you might even say that the logical_const in this example is a lie;)=
=20
You would need to be consistent in making all pointers, whether naked or=
=20
not, logical_const.
What is needed is a change to the language to introduce something like a=20
deep_const, which has the following properties:
- if a class, struct or union is marked deep_const, all the non-static,=
=20
non-pointer members are also implicitly deep_const and all non-static,=
=20
pointer members of type T * =E2=80=A6 * var would become deep_const t * =
deep_const=20
=E2=80=A6 deep_const * deep_const var;
- mutable would stop the recursive marking;
- deep_const can be const_casted away;
- a deep_const object can only be passed to a function or function=20
object by value, or where the parameter is likewise marked deep_const;
- any base of a deep_const is likewise deep_const;
- constructors and destructors can ignore any non-top-level deep_const=
=20
markers;
- only static member functions and member functions marked deep_const=20
can be called for a deep_const object. this would be a deep_const point=
er=20
to a deep_const object.
There are probably other consequences that I have not thought about.
Given this, I cannot see such a proposal making any headway with the=20
standards committee :(
--=20
---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
------=_Part_319_14940061.1401134381757
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, 24 April 2014 18:47:43 UTC+1, Jonatha=
n Coe wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
<div>Following discussion on the BSI and c++std-lib mailing lists I propose=
an addition to the C++ Standard Library to make logical const-ness easy to=
implement and easy to spot in code review:</div><div><br></div><div><a hre=
f=3D"https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=
=3Dsharing" target=3D"_blank" onmousedown=3D"this.href=3D'https://drive.goo=
gle.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp\75sharing';return true=
;" onclick=3D"this.href=3D'https://drive.google.com/file/d/0B5BUDfRWFDPva1p=
OM0tyR1FRWFk/edit?usp\75sharing';return true;">https://drive.google.com/fil=
e/<wbr>d/<wbr>0B5BUDfRWFDPva1pOM0tyR1FRWFk/<wbr>edit?usp=3Dsharing</a><br><=
/div><div><br></div><div>All thoughts are welcome.</div><div><br></div><div=
>Kind regards,</div><div><br></div><div>Jonathan Coe</div></div></blockquot=
e><div><br></div><div>I like the idea of a logical_const, as I also feel th=
at const is broken as it currently exists, but to repair it would have the =
potential of breaking much code :(</div><div><br></div><div>I don't believe=
, however, that this is the right approach, as it doesn't fix the problem.<=
/div><div><br></div><div>Consider the following:</div><div><br></div><div c=
lass=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wr=
ap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D=
"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"sty=
led-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><span style=3D"color: #008;" class=3D"styled-by-prettify=
">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> valA=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br><br><br></span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> B </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> A a</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> valB</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</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></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> C </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br> std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">logical_const</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">B </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">*></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> b</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></span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br=
><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">const=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> C c </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">/* ... */</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">};</span></div></code></d=
iv><div><br></div><div><br></div><div>In this, valB cannot be changed, due =
to the logical_const, but as logical_const itself is only a shallow const, =
valA can be changed. In fact, you might even say that the logical_con=
st in this example is a lie;) You would need to be consistent in maki=
ng all pointers, whether naked or not, logical_const.</div><div><br></div><=
div>What is needed is a change to the language to introduce something like =
a deep_const, which has the following properties:</div><div><ul><li><span s=
tyle=3D"line-height: normal;">if a class, struct or union is marked deep_co=
nst, all the non-static, non-pointer members are also implicitly deep_const=
and all non-static, pointer members of type T * =E2=80=A6 * var would beco=
me deep_const t * deep_const =E2=80=A6 deep_const * deep_const var;</span><=
/li><li><span style=3D"line-height: normal;">mutable would stop the recursi=
ve marking;</span></li><li><span style=3D"line-height: normal;">deep_const =
can be const_casted away;</span></li><li><span style=3D"line-height: normal=
;">a deep_const object can only be passed to a function or function object =
by value, or where the parameter is likewise marked deep_const;</span></li>=
<li><span style=3D"line-height: normal;">any base of a deep_const is likewi=
se deep_const;</span></li><li><span style=3D"line-height: normal;">construc=
tors and destructors can ignore any non-top-level deep_const markers;</span=
></li><li><span style=3D"line-height: normal;">only static member functions=
and member functions marked deep_const can be called for a deep_const obje=
ct. this would be a deep_const pointer to a deep_const object.</span>=
</li></ul>There are probably other consequences that I have not thought abo=
ut.</div><div><br></div><div>Given this, I cannot see such a proposal makin=
g any headway with the standards committee :(</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" 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_319_14940061.1401134381757--
.
Author: Diggory Blake <diggsey@googlemail.com>
Date: Mon, 26 May 2014 18:06:38 -0700 (PDT)
Raw View
------=_Part_708_18513352.1401152798152
Content-Type: text/plain; charset=UTF-8
How is your example broken?
c : const C
c.b : const std::logical_const<B*>
c.b->a : const A
c.b->a.valA : const int
You can't change valA, it all behaves correctly.
On Monday, 26 May 2014 20:59:41 UTC+1, Douglas Boffey wrote:
>
> I like the idea of a logical_const, as I also feel that const is broken as
> it currently exists, but to repair it would have the potential of breaking
> much code :(
>
> I don't believe, however, that this is the right approach, as it doesn't
> fix the problem.
>
> Consider the following:
>
> struct A {
> int valA;
> };
>
>
> struct B {
> A a;
> int valB;
> };
>
>
> struct C {
> std::logical_const<B *> b;
> };
>
>
> const C c {/* ... */};
>
>
> In this, valB cannot be changed, due to the logical_const, but as
> logical_const itself is only a shallow const, valA can be changed. In
> fact, you might even say that the logical_const in this example is a lie;)
> You would need to be consistent in making all pointers, whether naked or
> not, logical_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_708_18513352.1401152798152
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">How is your example broken?<br>c : const C<br>c.b : const =
std::logical_const<B*><br>c.b->a : const A<br>c.b->a.valA : con=
st int<br><br>You can't change valA, it all behaves correctly.<br><br>On Mo=
nday, 26 May 2014 20:59:41 UTC+1, Douglas Boffey wrote:<br><blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><br></div><div>I like t=
he idea of a logical_const, as I also feel that const is broken as it curre=
ntly exists, but to repair it would have the potential of breaking much cod=
e :(</div><div><br></div><div>I don't believe, however, that this is the ri=
ght approach, as it doesn't fix the problem.</div><div><br></div><div>Consi=
der the following:</div><div><br></div><div style=3D"border:1px solid rgb(1=
87,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><=
div><span style=3D"color:#008">struct</span><span style=3D"color:#000"> A <=
/span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>&nb=
sp; </span><span style=3D"color:#008">int</span><span style=3D"color:#000">=
valA</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br></span><span style=3D"color:#660">};</span><span style=3D"color:#000"><b=
r><br><br></span><span style=3D"color:#008">struct</span><span style=3D"col=
or:#000"> B </span><span style=3D"color:#660">{</span><span style=3D"color:=
#000"><br> A a</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br> </span><span style=3D"color:#008">int</span><spa=
n style=3D"color:#000"> valB</span><span style=3D"color:#660">;</span><span=
style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><span =
style=3D"color:#000"><br><br><br></span><span style=3D"color:#008">struct</=
span><span style=3D"color:#000"> C </span><span style=3D"color:#660">{</spa=
n><span style=3D"color:#000"><br> std</span><span style=3D"color:#660=
">::</span><span style=3D"color:#000">logical_const</span><span style=3D"co=
lor:#660"><</span><span style=3D"color:#000">B </span><span style=3D"col=
or:#660">*></span><span style=3D"color:#000"> b</span><span style=3D"col=
or:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"color=
:#660">};</span><span style=3D"color:#000"><br><br><br></span><span style=
=3D"color:#008">const</span><span style=3D"color:#000"> C c </span><span st=
yle=3D"color:#660">{</span><span style=3D"color:#800">/* ... */</span><span=
style=3D"color:#660">};</span></div></code></div><div><br></div><div><br><=
/div><div>In this, valB cannot be changed, due to the logical_const, but as=
logical_const itself is only a shallow const, valA can be changed. I=
n fact, you might even say that the logical_const in this example is a lie;=
) You would need to be consistent in making all pointers, whether nak=
ed or not, logical_const.</div><br></div></blockquote></div>
<p></p>
-- <br />
<br />
--- <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 />
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_708_18513352.1401152798152--
.
Author: Jonathan Coe <jonathanbcoe@gmail.com>
Date: Thu, 7 Aug 2014 13:37:29 -0700 (PDT)
Raw View
------=_Part_30_581879338.1407443849570
Content-Type: text/plain; charset=UTF-8
My google drive html document preview and sharing seems to have gone awry.
please find an up-to-date pdf here:
https://drive.google.com/file/d/0B5BUDfRWFDPvZTNES2xUWlUtYmc/edit?usp=sharing
revisions since previous versions given at the end.
On Thursday, April 24, 2014 6:47:43 PM UTC+1, Jonathan Coe wrote:
>
> Following discussion on the BSI and c++std-lib mailing lists I propose an
> addition to the C++ Standard Library to make logical const-ness easy to
> implement and easy to spot in code review:
>
>
> https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=sharing
>
> All thoughts are welcome.
>
> Kind regards,
>
> Jonathan Coe
>
--
---
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_30_581879338.1407443849570
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
My google drive html document preview and sharing seems to have gone awry.<=
div><br></div><div>please find an up-to-date pdf here:</div><div><br></div>=
<div>https://drive.google.com/file/d/0B5BUDfRWFDPvZTNES2xUWlUtYmc/edit?usp=
=3Dsharing</div><div><br></div><div>revisions since previous versions given=
at the end.<br><br>On Thursday, April 24, 2014 6:47:43 PM UTC+1, Jonathan =
Coe wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><di=
v>Following discussion on the BSI and c++std-lib mailing lists I propose an=
addition to the C++ Standard Library to make logical const-ness easy to im=
plement and easy to spot in code review:</div><div><br></div><div><a href=
=3D"https://drive.google.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp=
=3Dsharing" target=3D"_blank" onmousedown=3D"this.href=3D'https://drive.goo=
gle.com/file/d/0B5BUDfRWFDPva1pOM0tyR1FRWFk/edit?usp\75sharing';return true=
;" onclick=3D"this.href=3D'https://drive.google.com/file/d/0B5BUDfRWFDPva1p=
OM0tyR1FRWFk/edit?usp\75sharing';return true;">https://drive.google.com/fil=
e/<wbr>d/<wbr>0B5BUDfRWFDPva1pOM0tyR1FRWFk/<wbr>edit?usp=3Dsharing</a><br><=
/div><div><br></div><div>All thoughts are welcome.</div><div><br></div><div=
>Kind regards,</div><div><br></div><div>Jonathan Coe</div></div></blockquot=
e></div>
<p></p>
-- <br />
<br />
--- <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 />
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_30_581879338.1407443849570--
.