Topic: Comparison of Pointers to Members. In addition to N3624.


Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sun, 26 May 2013 05:10:58 -0700 (PDT)
Raw View
------=_Part_1966_25566283.1369570258624
Content-Type: text/plain; charset=ISO-8859-1

I would like to propose the following changes in addition to those
discussed in N3624
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3624.html

(1)
I propose to change the following wording  section 5.10 (N3485):

*Otherwise if either is a pointer to a virtual member function, the result
is unspecified. Otherwise they compare equal if and only if they would
refer to the same member of the same most derived object (1.8) or the same
subobject if indirection with a hypothetical object of the associated class
type were performed.*

Replace it with the following:


*Otherwise, pointers to member functions of the same class are considered
equal if and only if they refer to the same function. If they refer to
members of different classes and either is a pointer to a virtual member
function, the result is unspecified. Otherwise they compare equal if and
only if they would refer to the same member of the same most derived object
(1.8) or the same subobject if indirection with a hypothetical object of
the associated class type were performed.*

This will allow to compare member functions of the same class.

struct A
{
    double x;
    A(double x1):x(x1){}
    double add(double a) { return x+a; }
    double sub(double a) { return x-a; }
    virtual double f(double y) { return x*y; }
    virtual double f1(double y) { return x*y+1.0; }
};

double (A::*padd)(double) = &A::add;
double (A::*psub)(double) = &A::sub;
double (A::*pf)(double) = &A::f;
double (A::*pfx)(double) = &A::f;
double (A::*pf1)(double) = &A::f1;


std::cout << "padd == psub: " << (padd == psub) << std::endl;
std::cout << "padd !== psub: " << (padd != psub) << std::endl;
std::cout << "padd == pf: " << (padd == pf) << std::endl; // not specified
at present
std::cout << "pf == pf1: " << (pf == pf1) << std::endl;// not specified at
present
std::cout << "pf == pfx: " << (pf == pfx) << std::endl;// not specified at
present

This fix will allow the last three comparisons to be valid:
false,
false,
true

(2) Why cannot it be allowed to always compare (compatible) pointers to
member functions for < ? If two member pointers are unequal, why not allow
them to be compared for <.




--

---
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/?hl=en.



------=_Part_1966_25566283.1369570258624
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>I would like to propose the following changes in addition to those dis=
cussed in N3624</div><div><a href=3D"http://www.open-std.org/jtc1/sc22/wg21=
/docs/papers/2013/n3624.html">http://www.open-std.org/jtc1/sc22/wg21/docs/p=
apers/2013/n3624.html</a></div><div>&nbsp;</div><div><font color=3D"#000000=
" face=3D"Times New Roman" size=3D"3">

(1)<br>I propose to change the following wording&nbsp; section 5.10 (N3485)=
:</font></div><div><font color=3D"#000000" face=3D"Times New Roman" size=3D=
"3"></font>&nbsp;</div><div><font color=3D"#000000" face=3D"Times New Roman=
" size=3D"2"><strong>Otherwise if either is a pointer to a virtual member f=
unction, the result is unspecified. Otherwise they compare equal if and onl=
y if they would refer to the same member of the same most derived object (1=
..8) or the same subobject if indirection with a hypothetical object of the =
associated class type were performed.</strong></font></div><font color=3D"#=
000000" face=3D"Times New Roman" size=3D"3"><div><br>Replace it with the fo=
llowing:</div><div>&nbsp;</div><p><strong><font size=3D"2"><font color=3D"#=
0b5394">Otherwise, pointers to member functions of the same class are consi=
dered equal if and only if they refer to the same function.</font> If they =
refer to members of different classes and either is a pointer to a virtual =
member function, the result is unspecified. Otherwise they compare equal if=
 and only if they would refer to the same member of the same most derived o=
bject (1.8) or the same subobject if indirection with a hypothetical object=
 of the associated class type were performed.</font></strong></p><p>This wi=
ll allow to compare member functions of the same class. </p><p>struct A<br>=
{<br>&nbsp;&nbsp;&nbsp; double x;<br>&nbsp;&nbsp;&nbsp; A(double x1):x(x1){=
}<br>&nbsp;&nbsp;&nbsp; double add(double a) { return x+a; }<br>&nbsp;&nbsp=
;&nbsp; double sub(double a) { return x-a; }<br>&nbsp;&nbsp;&nbsp; virtual =
double f(double y) { return x*y; }<br>&nbsp;&nbsp;&nbsp; virtual double f1(=
double y) { return x*y+1.0; }<br>};</p><p>double (A::*padd)(double) =3D &am=
p;A::add;<br>double (A::*psub)(double) =3D &amp;A::sub;<br>double (A::*pf)(=
double) =3D &amp;A::f;<br>double (A::*pfx)(double) =3D &amp;A::f;<br>double=
 (A::*pf1)(double) =3D &amp;A::f1;</p><p><br>std::cout &lt;&lt; "padd =3D=
=3D psub: " &lt;&lt; (padd =3D=3D psub) &lt;&lt; std::endl;<br>std::cout &l=
t;&lt; "padd !=3D=3D psub: " &lt;&lt; (padd !=3D psub) &lt;&lt; std::endl;<=
br>std::cout &lt;&lt; "padd =3D=3D pf: " &lt;&lt; (padd =3D=3D pf) &lt;&lt;=
 std::endl; // not specified at present<br>std::cout &lt;&lt; "pf =3D=3D pf=
1: " &lt;&lt; (pf =3D=3D pf1) &lt;&lt; std::endl;// not specified at presen=
t<br>std::cout &lt;&lt; "pf =3D=3D pfx: " &lt;&lt; (pf =3D=3D pfx) &lt;&lt;=
 std::endl;// not specified at present</p><p>This fix will allow the last t=
hree comparisons to be valid:<br>false,<br>false,<br>true</p><p>(2) Why can=
not it be allowed to always compare (compatible) pointers to member functio=
ns for &lt; ? If two member pointers are unequal, why not allow them to be =
compared for &lt;.<br></p></font><p>&nbsp;</p><div></div><div><font color=
=3D"#000000" face=3D"Times New Roman" size=3D"3"></font>&nbsp;</div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_1966_25566283.1369570258624--

.