Topic: Dynamic/Temporal constatization
Author: Dejan Milosavljevic <dmilos@gmail.com>
Date: Sat, 2 Jan 2016 06:08:25 -0800 (PST)
Raw View
------=_Part_0_1484563950.1451743705442
Content-Type: multipart/alternative;
boundary="----=_Part_1_1827313706.1451743705447"
------=_Part_1_1827313706.1451743705447
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=20
Hi
Idea is simple. Make instance temporally constant.
=20
Small example:
Container<int> c;=20
func( *const*( c ) );=20
*const*( c ).f();
=20
=20
And in details:
=20
=20
Table of Contents.
- I. Abstract
- II. Motivation
- III. Solution
- IV. Syntax
- V. Summary
- VI. Impact On the Standard
=20
I. Abstract
Dynamic constatization of instances.=20
II. Motivation
Problem 1:[*Example*:=20
template< typename T>
class Container{
public:
typedef T* iterator;
typedef T const* const_iterator;
iterator begin();
const_iterator begin()const;
iterator end();
const_iterator end()const;
void f();
void f()const;
};
Container<int> cont;
for( auto const & iter : cont ){ // in here we want to be called *begin()=
const* and *end()const*
}
=E2=80=94*end example*]
=20
Problem 2:
[*Example*:=20
void func( Container<int> & c );
void func( Container<int> const & c );
void do_something(){
Container<int> cont;
func(cont); // In here we want to call func( Container<int> const& c );
}
=E2=80=94*end example*]=20
=20
III. Solution
Solutions within current standard=20
=20
- Bloat code with new functions that has different name which will serve=
=20
to only to only one purpose.
Examples are: vector::cbegin and vector::cend, vector::crbegin,=20
vector::crend.=20
- Use helper variable with const qualifier.
=20
[*Example*:=20
=20
{
Container<int> const& ccont =3D cont;
for( auto & iter : cont ){
}
}
=20
=E2=80=94*end example*]=20
- Use some of existing cast operator which will directly lead to=20
misunderstanding and possible to something more serious.=20
[*Example*:=20
=20
// Some companies might forbid usage of reinterpret_cast
for( auto const & iter : reinterpret_cast< Container<int> const& >( co=
nt ) ){
// ... ... ...
}
=20
for( auto const & iter : static_cast< Container<int> const& >( cont ) =
){
// ... ... ...
}
// it is expected that const_cast remove constness not to add
for( auto const & iter : const_cast< Container<int> const& >( cont ) )=
{
// ... ... ...
}
=20
for( auto const & iter : ( Container<int> const& )( cont ) ){
// ... ... ...
}
=20
=20
=E2=80=94*end example*]
=20
In all cases code become less readable if we have type with realy long=
=20
name e.g. std::map< std::string, std::pair< std::string, std::string > >=
..=20
=20
=20
By adding ability to const to act on instances.On range loop:
[*Example*:=20
Container<int> cont;
for( auto &iter : const( cont ) ){
// ...
}
=E2=80=94*end example*]=20
=20
On instance:
[*Example*:=20
Container<int> cont;
func( const( cont ) );
const( cont ).f();
=E2=80=94*end example*]=20
=20
On pointers:
[*Example*:=20
Container<int> cont;
Container<int> * cp1 =3D &cont;
const( cp1 )->f();
Container<int> *const cp2 =3D &cont;
const( cp2 )->f();
Container<int> const* cp3 =3D &cont;
const( cp3 )->f();
=E2=80=94*end example*]=20
IV. Syntax*const-operator:*const ( *expression* )
V. Summary
- Avoid code bloat by adding functions which to allow explicit call of=
=20
const functions.
- Avoid misusing of cast operators to add temporal constness.
- Avoid using of temporal const references.
VI. Impact On the Standard
Core
No effect.
No new keywords.=20
No new tokens.=20
No changes to old syntax.=20
Pure extension.=20
Backward compatible.=20
Library
No effect.
Existing code.
No effect.
--=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 https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_1_1827313706.1451743705447
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"NaslovGlavni"><div>=C2=A0</div></div><div cl=
ass=3D"NaslovGlavni"><br></div><div class=3D"NaslovGlavni">Hi</div><div cla=
ss=3D"NaslovGlavni"><br></div><div class=3D"NaslovGlavni">Idea is simple. M=
ake instance temporally constant.</div><div class=3D"NaslovGlavni"><div>=C2=
=A0</div></div><div class=3D"NaslovGlavni">Small example:</div><div class=
=3D"NaslovGlavni"></div><div class=3D"NaslovGlavni"><font face=3D"courier n=
ew,monospace">=C2=A0=C2=A0=C2=A0 Container<int> c;=C2=A0<div>=C2=A0=
=C2=A0=C2=A0 func( <em>const</em>( c ) );=C2=A0</div><div>=C2=A0=C2=A0=C2=
=A0 <em>const</em>( c ).f();</div></font><div><font face=3D"courier new,mon=
ospace"></font>=C2=A0</div><div>=C2=A0</div><div>And in details:</div></div=
><div class=3D"NaslovGlavni"><div>=C2=A0=C2=A0</div></div><dt><div class=3D=
"NaslovGlavni"><div>=C2=A0</div></div></dt><dt><div class=3D"NaslovGlavni">=
Table of Contents.</div></dt><dd><ul><li><div class=3D"TOCItem">I. Abstract=
</div></li><li><div class=3D"TOCItem">II. Motivation</div></li><li><div cla=
ss=3D"TOCItem">III. Solution</div></li><li><div class=3D"TOCItem">IV. Synta=
x</div></li><li><div class=3D"TOCItem">V. Summary</div></li><li><div class=
=3D"TOCItem">VI. Impact On the Standard</div></li></ul></dd><dt><div class=
=3D"NaslovGlavni">I. Abstract</div></dt><dd> Dynamic constatization of i=
nstances. </dd><dt><div class=3D"NaslovGlavni">II. Motivation</div></dt>=
<dd><dl><dt>Problem 1:</dt><dd>[<i>Example</i>: <code><pre class=3D"TextCod=
e">template< typename T>
class Container{
public:
typedef T* iterator;
typedef T const* const_iterator;
iterator begin();
const_iterator begin()const;
iterator end();
const_iterator end()const;
void f();
void f()const;
};
Container<int> cont;
for( auto const & iter : cont ){ // in here we want to be called <i>b=
egin()const</i> and <i>end()const</i>
}
</pre></code><font face=3D"Times New Roman"> =E2=80=94<i>end example</i=
>]<div>=C2=A0</div></font><div>Problem 2:</div></dd></dl><dl><dd> [<i>Ex=
ample</i>: <code><pre class=3D"TextCode"> void func( Container<int>=
& c );
void func( Container<int> const & c );
void do_something(){
Container<int> cont;
func(cont); // In here we want to call func( Container<int> const=
& c );
}</pre></code><font face=3D"Times New Roman">=E2=80=94<i>end example</i>=
] </font><div><font face=3D"Times New Roman"></font>=C2=A0</div></dd></dl><=
p class=3D"NovaStranica"></p></dd><dt><div class=3D"NaslovGlavni">III. Solu=
tion</div></dt><dd><dl><dt class=3D"Naslovcic">Solutions within current sta=
ndard </dt><dd><ul><li>Bloat code with new functions that has different nam=
e which will serve to only to only one purpose.<div> Examples ar=
e: <code>vector::cbegin</code> and <code>vector::cend</code>, <code>vector:=
:crbegin</code>, <code>vector::crend</code>. </div></li><li>Use hel=
per variable with <code>const</code> qualifier.<div>=C2=A0</div><div>[<i>Ex=
ample</i>: <code></code></div><pre class=3D"TextCode"><code> {
Container<int> const& ccont =3D cont;
for( auto & iter : cont ){
}
}
</code></pre><font face=3D"Times New Roman">=E2=80=94<i>end example</i>] =
</font></li><li> Use some of existing cast operator which will=
directly lead to misunderstanding and possible to something more serious. =
<div>[<i>Example</i>: <code></code></div><pre class=3D"TextCode"><code> //=
Some companies might forbid usage of reinterpret_cast
for( auto const & iter : reinterpret_cast< Container<int> co=
nst& >( cont ) ){
// ... ... ...
}
for( auto const & iter : static_cast< Container<int> const&a=
mp; >( cont ) ){
// ... ... ...
}
// it is expected that const_cast remove constness not to add
for( auto const & iter : const_cast< Container<int> const&am=
p; >( cont ) ){
// ... ... ...
}
for( auto const & iter : ( Container<int> const& )( cont ) =
){
// ... ... ...
}
=20
</code></pre><font face=3D"Times New Roman"> =E2=80=94<i>end example</i>]<d=
iv>=C2=A0</div></font><div><font face=3D"Times New Roman"> In all cases co=
de become less readable if we have type with realy long name e.g. </font><c=
ode>std::map< std::string, std::pair< std::string, std::string > &=
gt;</code><font face=3D"Times New Roman">. </font></div></li></ul></d=
d><dt class=3D"Naslovcic">By adding ability to <code>const</code> to act on=
instances.</dt><dd>On range loop:<div> [<i>Example</i>: </div><blockquote>=
<code><pre class=3D"TextCode">Container<int> cont;
for( auto &iter : const( cont ) ){
// ...
}
</pre></code><font face=3D"Times New Roman"> </font></blockquote>=E2=80=94<=
i>end example</i>] <div>=C2=A0</div><div> On instance:</div><div> [<i>Examp=
le</i>: </div><blockquote><code><pre class=3D"TextCode">Container<int>=
; cont;
func( const( cont ) );
const( cont ).f();
</pre></code><font face=3D"Times New Roman"> </font></blockquote>=E2=80=94<=
i>end example</i>] <div>=C2=A0</div><div> On pointers:</div><div> [<i>Examp=
le</i>: </div><blockquote><code><pre class=3D"TextCode">Container<int>=
; cont;
Container<int> * cp1 =3D &cont;
const( cp1 )->f();
Container<int> *const cp2 =3D &cont;
const( cp2 )->f();
Container<int> const* cp3 =3D &cont;
const( cp3 )->f();
</pre></code><font face=3D"Times New Roman"> </font></blockquote>=E2=80=94<=
i>end example</i>] </dd></dl><p class=3D"NovaStranica"></p></dd><dt clas=
s=3D"NaslovGlavni">IV. Syntax</dt><dd><dl><dt><i>const-operator:</i></dt><d=
d><code>const</code> ( <i>expression</i> )</dd></dl><p class=3D"NovaStranic=
a"></p></dd><dt><div class=3D"NaslovGlavni">V. Summary</div></dt><dd><ul><l=
i>Avoid code bloat by adding functions which to allow explicit call of <cod=
e>const</code> functions.</li><li>Avoid misusing of cast operators to add t=
emporal <code>const</code>ness.</li><li>Avoid using of temporal <code>const=
</code> references.</li></ul><dl></dl></dd><dt><div class=3D"NaslovGlavni">=
VI. Impact On the Standard</div></dt><dd><dl><dt><div class=3D"NaslovPod ">=
=C2=A0 Core</div></dt><dd>=C2=A0=C2=A0=C2=A0 No effect.<div>=C2=A0=C2=A0=C2=
=A0 No new keywords. </div><div> =C2=A0=C2=A0=C2=A0 No new tokens.=
</div><div> =C2=A0=C2=A0=C2=A0 No changes to old syntax. </div><d=
iv> =C2=A0=C2=A0=C2=A0 Pure extension. </div><div> =C2=A0=
=C2=A0=C2=A0 Backward compatible. </div></dd><dt><div class=3D"Naslo=
vPod ">=C2=A0 Library</div></dt><dd>=C2=A0=C2=A0=C2=A0 No effect.</dd><dt><=
div class=3D"NaslovPod ">=C2=A0 Existing code.</div></dt><dd>=C2=A0=C2=A0=
=C2=A0 No effect.</dd></dl></dd></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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_1_1827313706.1451743705447--
------=_Part_0_1484563950.1451743705442--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sat, 2 Jan 2016 06:27:22 -0800 (PST)
Raw View
------=_Part_5143_271664054.1451744843035
Content-Type: multipart/alternative;
boundary="----=_Part_5144_933915467.1451744843035"
------=_Part_5144_933915467.1451744843035
Content-Type: text/plain; charset=UTF-8
How is this an improvement over the C++17 library feature `as_const`
<http://en.cppreference.com/w/cpp/utility/as_const>? What can your language
feature do that this library version cannot?
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_5144_933915467.1451744843035
Content-Type: text/html; charset=UTF-8
<div dir="ltr">How is this an improvement over the <a href="http://en.cppreference.com/w/cpp/utility/as_const">C++17 library feature `as_const`</a>? What can your language feature do that this library version cannot?<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href="mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href="https://groups.google.com/a/isocpp.org/group/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
------=_Part_5144_933915467.1451744843035--
------=_Part_5143_271664054.1451744843035--
.
Author: Dejan Milosavljevic <dmilos@gmail.com>
Date: Sat, 2 Jan 2016 07:13:54 -0800 (PST)
Raw View
------=_Part_8507_1252919519.1451747634959
Content-Type: multipart/alternative;
boundary="----=_Part_8508_514370546.1451747634959"
------=_Part_8508_514370546.1451747634959
Content-Type: text/plain; charset=UTF-8
On Saturday, January 2, 2016 at 3:27:23 PM UTC+1, Nicol Bolas wrote:
>
> How is this an improvement over the C++17 library feature `as_const`
> <http://en.cppreference.com/w/cpp/utility/as_const>? What can your
> language feature do that this library version cannot?
>
Hmm, didn't see that.
add_const is already in C++17 standard. Whit this I can not compete,
whatever reason/feature I found/have.
So I give up!
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_8508_514370546.1451747634959
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Saturday, January 2, 2016 at 3:27:23 PM UTC+1, =
Nicol Bolas wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0px 0p=
x 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bord=
er-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr">How is this=
an improvement over the <a onmousedown=3D"this.href=3D'http://www.goog=
le.com/url?q\75http%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Futility%2Fas_co=
nst\46sa\75D\46sntz\0751\46usg\75AFQjCNGIfwIwoE1ZL6SZluDNbj3JYOlIyg';re=
turn true;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%=
3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Futility%2Fas_const\46sa\75D\46sntz\=
0751\46usg\75AFQjCNGIfwIwoE1ZL6SZluDNbj3JYOlIyg';return true;" href=3D"=
http://en.cppreference.com/w/cpp/utility/as_const" target=3D"_blank" rel=3D=
"nofollow">C++17 library feature `as_const`</a>? What can your language fea=
ture do that this library version cannot?<br></div></blockquote><div><br></=
div><div>Hmm, didn't see that.<br><font face=3D"courier new,monospace">=
add_const</font> is already in C++17 standard. Whit=C2=A0 this I can not co=
mpete, whatever reason/feature I found/have.</div><div><br>So <span class=
=3D"hps">I give up!</span></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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_8508_514370546.1451747634959--
------=_Part_8507_1252919519.1451747634959--
.
Author: Dejan Milosavljevic <dmilos@gmail.com>
Date: Fri, 8 Jan 2016 06:20:00 -0800 (PST)
Raw View
------=_Part_780_1510729374.1452262800397
Content-Type: multipart/alternative;
boundary="----=_Part_781_1023822690.1452262800397"
------=_Part_781_1023822690.1452262800397
Content-Type: text/plain; charset=UTF-8
I still give up on this, but if someone want this, I grant right to to that.
And a few thing for the record.
In my eyes it is insignificant but there are some peoples who are waiting
for opportunity to exaggerate.
Scenario C++17:
for( auto& iter: std::as_const( cont ) ){
//.. what ever
}
Compiler must enter in as_const to see what is inside and at the end it
will optimize as we want/expect.
But this require some time.
This proposal scenario:
for( auto& iter: const( cont ) ){
//.. what ever
}
Compiler will just add 'const', No optimization of any kind.
Much faster than c++17.
And again some people are very peaky regarding even for a smallest thing.
'goto' is almost banned, I have complain on using 'continue'.
'Companies rules' ( famous experiment with monkeys ) is fact, similarly it
is time to have 'C++ ( monkey ) rules'.
etc.
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_781_1023822690.1452262800397
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><br>I still give up on this, but if someone want this=
, I grant right to to that.</div><div><br></div><div>And a few thing for th=
e record.</div><div><br></div><div>In my eyes it is insignificant but there=
are some peoples who are waiting for opportunity to exaggerate.</div><div>=
<br></div><p>Scenario C++17:</p><p><font face=3D"courier new,monospace">for=
( auto& iter: std::as_const( cont ) ){<br>=C2=A0 //.. what ever<br>=C2=
=A0}</font></p><div>Compiler must enter in <font face=3D"courier new,monosp=
ace">as_const</font> to see what is inside and at the end it will optimize =
as we want/expect.<br>But this require some time.</div><div><br></div><p>Th=
is proposal scenario:<br><font face=3D"courier new,monospace">=C2=A0for( au=
to& iter: const( cont ) ){<br>=C2=A0=C2=A0 //.. what ever<br>=C2=A0 }</=
font></p><div>Compiler will just add 'const', No optimization of an=
y kind.<br>Much faster than c++17.</div><div><br></div><p>And again some pe=
ople are very peaky regarding even for a smallest thing. <br><font face=3D"=
courier new,monospace">'goto'</font> is almost banned, I have compl=
ain on using <font face=3D"courier new,monospace">'continue'</font>=
..</p><p>'Companies rules' ( famous experiment with monkeys ) is fac=
t, similarly it is time to have 'C++ ( monkey ) rules'.</p><p>etc.<=
br></p></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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_781_1023822690.1452262800397--
------=_Part_780_1510729374.1452262800397--
.