Topic: regarding N4173 and smart_ref


Author: Cleiton Santoia <cleitonsantoia@gmail.com>
Date: Wed, 18 Mar 2015 15:04:25 -0700 (PDT)
Raw View
------=_Part_853_1086434157.1426716265368
Content-Type: multipart/alternative;
 boundary="----=_Part_854_1792909905.1426716265368"

------=_Part_854_1792909905.1426716265368
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


In the standard=20

4 Standard Conversion=20
2 [ Note: expressions with a given type will be implicitly converted to=20
other types in several contexts:=20
(2.1) =E2=80=94 When used as operands of operators. The operator=E2=80=99s =
requirements for=20
its operands dictate the destination type (Clause 5).

5 Certain language constructs require conversion to a value having one of a=
=20
specified set of types appropriate to the construct. An expression e of=20
class type E appearing in such a context is said to be contextually=20
implicitly converted to a specified type T and is well-formed if and only=
=20
if e can be implicitly converted to a type T that is determined as follows:=
=20
E is searched for conversion functions whose return type is cv T or=20
reference to cv T such that T is allowed by the context. There shall be=20
exactly one such T.


Consider the following:
struct  X {
   void foo();
};

template< typename T >
class Ref {
    T* t_;
public:
    operator T&() { return *t_; } //  nothing new here just a cast operator
};

Ref<X> x;
x.foo();    // implicit conversion from Ref<X> to X& in "." operator ?


So, without being overloaded, (since it=C2=B4s forbidden) operator dot in=
=20
"c.m()" should implicitly convert Ref<X> to X ?

(by the way, this code does not compile)




Cleiton

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

<div dir=3D"ltr"><div><br></div><div>In the standard&nbsp;<br></div><div><b=
r></div><div>4 Standard Conversion&nbsp;<br></div><div>2 [ Note: expression=
s with a given type will be implicitly converted to other types in several =
contexts:&nbsp;<br></div><div>(2.1) =E2=80=94 When used as operands of oper=
ators. The operator=E2=80=99s requirements for its operands dictate the des=
tination
type (Clause 5).<br></div><div><br></div><div>5 Certain language constructs=
 require conversion to a value having one of a specified set of types appro=
priate
to the construct. An expression e of class type E appearing in such a conte=
xt is said to be contextually
implicitly converted to a specified type T and is well-formed if and only i=
f e can be implicitly converted to
a type T that is determined as follows: E is searched for conversion functi=
ons whose return type is cv T or
reference to cv T such that T is allowed by the context. There shall be exa=
ctly one such T.<br></div><div><br></div><div><br></div><div>Consider the f=
ollowing:</div><div><div class=3D"subprettyprint" style=3D"font-family: mon=
ospace; background-color: rgb(250, 250, 250);"><div class=3D"prettyprint" s=
tyle=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgr=
ound-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"=
subprettyprint"><div class=3D"subprettyprint"><font face=3D"courier new, mo=
nospace">struct &nbsp;X {</font></div><div class=3D"subprettyprint"><font f=
ace=3D"courier new, monospace">&nbsp; &nbsp;void foo();</font></div><div cl=
ass=3D"subprettyprint"><font face=3D"courier new, monospace">};</font></div=
><div class=3D"subprettyprint"><font face=3D"courier new, monospace"><br></=
font></div><div class=3D"subprettyprint"><font face=3D"courier new, monospa=
ce">template&lt; typename T &gt;</font></div><div class=3D"subprettyprint">=
<font face=3D"courier new, monospace">class Ref {</font></div><div class=3D=
"subprettyprint"><font face=3D"courier new, monospace">&nbsp; &nbsp; T* t_;=
</font></div><div class=3D"subprettyprint"><font face=3D"courier new, monos=
pace">public:</font></div><div class=3D"subprettyprint"><font face=3D"couri=
er new, monospace">&nbsp; &nbsp; operator T&amp;() { return *t_; } // &nbsp=
;nothing new here just a cast operator<br></font></div><div class=3D"subpre=
ttyprint"><font face=3D"courier new, monospace">};<br></font><br>Ref&lt;X&g=
t; x;<br>x.foo(); &nbsp; &nbsp;// implicit conversion from Ref&lt;X&gt; to =
X&amp; in "." operator ?</div></div></code></div><br><br></div></div><div c=
lass=3D"subprettyprint" style=3D"font-family: monospace; background-color: =
rgb(250, 250, 250);"><span style=3D"font-family: Arial, Helvetica, sans-ser=
if; background-color: rgb(255, 255, 255);">So, without being overloaded, (s=
ince it=C2=B4s forbidden) operator dot in "c.m()" should implicitly convert=
 Ref&lt;X&gt; to X ?</span><br></div><div class=3D"subprettyprint" style=3D=
"font-family: monospace; background-color: rgb(250, 250, 250);"><span style=
=3D"font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 2=
55, 255);"><br></span></div><div class=3D"subprettyprint" style=3D"font-fam=
ily: monospace; background-color: rgb(250, 250, 250);"><span style=3D"font-=
family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);=
">(by the way, this code does not compile)</span></div><div class=3D"subpre=
ttyprint" style=3D"font-family: monospace; background-color: rgb(250, 250, =
250);"><span style=3D"font-family: Arial, Helvetica, sans-serif; background=
-color: rgb(255, 255, 255);"><br></span></div><div class=3D"subprettyprint"=
 style=3D"font-family: monospace; background-color: rgb(250, 250, 250);"><s=
pan style=3D"font-family: Arial, Helvetica, sans-serif; background-color: r=
gb(255, 255, 255);"><br></span></div><div class=3D"subprettyprint" style=3D=
"font-family: monospace; background-color: rgb(250, 250, 250);"><span style=
=3D"font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 2=
55, 255);"><br></span></div><div class=3D"subprettyprint" style=3D"font-fam=
ily: monospace; background-color: rgb(250, 250, 250);"><br></div><div class=
=3D"subprettyprint" style=3D"font-family: monospace; background-color: rgb(=
250, 250, 250);"><span style=3D"font-family: Arial, Helvetica, sans-serif; =
background-color: rgb(255, 255, 255);">Cleiton</span></div><div class=3D"su=
bprettyprint" style=3D"font-family: monospace; background-color: rgb(250, 2=
50, 250);"><br></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_854_1792909905.1426716265368--
------=_Part_853_1086434157.1426716265368--

.