Topic: Comments on P0060R0: Function Object-Based


Author: Giovanni Piero Deretta <gpderetta@gmail.com>
Date: Fri, 2 Oct 2015 15:31:23 -0700 (PDT)
Raw View
------=_Part_1324_1671412814.1443825083014
Content-Type: multipart/alternative;
 boundary="----=_Part_1325_2120019181.1443825083014"

------=_Part_1325_2120019181.1443825083014
Content-Type: text/plain; charset=UTF-8

Hi Mathias, Dietmar

I like quite a lot the the new version of this paper (BTW, thanks for the
acknowledgement). I have an additional suggestion:
The member function and plain member synthesised_function_type should
actually be the same object, and operator() calls will use SFINAE to decide
which variant to call.  This is needed to handle some cases anyway:

struct foo { void (*fn)(int); };

struct foo_ref {
    foo * fp;
    auto operator.(auto f) { return f(*fp); }
};

foo_ref x = ...;
x.fn(0);

In fact operator. would retain the same power even if only the unary
version were allowed, although it would be slightly more inconvenient to
implement.

As an alternate take on the Unified Call Syntax, I would suggest to go as
far as finding non member functions via adl (of course, if UCS becomes part
of the language, this would happen regardless). Finally static functions
can be found by attempting sfinale with the omission of the first
parameter.
In order of priority, operator() would call: member, member function,
static function and global function via adl.

Such a feature would subsume P0119R0 and N3617 (first class Overload Sets):

struct with_t {
    auto operator.(auto x) { return x; };
};
static constexpr with_t with{};

struct pair {
   int first;
   int second;
   void sum(){ return first+second; }
};
void print(pair x);

std::vector <pair> pair_vector;
std::vector <int> output;

std::transform(pair_vector, std::back_inserter(output), with.second);
std::transform(pair_vector, std::back_inserter(output), with.sum);
std::for_each(pair_vector, with.print)

Another nifty use case (the definition of order_by is left as an exercise):

std::sort(pair_vector, order_by.b);


HTH,

-- gpd

--

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

<div dir=3D"ltr">Hi Mathias, Dietmar<br><br>I like quite a lot the the new =
version of this paper (BTW, thanks for the acknowledgement). I have an addi=
tional suggestion:<br>The member function and plain member synthesised_func=
tion_type should actually be the same object, and operator() calls will use=
 SFINAE to decide which variant to call.=C2=A0 This is needed to handle som=
e cases anyway:<br><br>struct foo { void (*fn)(int); };<br><br>struct foo_r=
ef {<br>=C2=A0=C2=A0=C2=A0 foo * fp;<br>=C2=A0=C2=A0=C2=A0 auto operator.(a=
uto f) { return f(*fp); }<br>};<br><br>foo_ref x =3D ...;<br>x.fn(0);<br><b=
r>In
 fact operator. would retain the same power even if only the unary=20
version were allowed, although it would be slightly more inconvenient to
 implement.<br><br>As an alternate take on the Unified Call Syntax, I would=
 suggest to go as far as finding non member functions via adl (of course, i=
f UCS becomes part of the language, this would happen regardless). Finally =
static functions can be found by attempting sfinale with the omission of th=
e first parameter. <br>In order of priority, operator() would call: member,=
 member function, static function and global function via adl.<br><br>Such =
a feature would subsume P0119R0 and N3617 (first class Overload Sets):<br><=
br>struct with_t {<br>=C2=A0=C2=A0=C2=A0 auto operator.(auto x) { return x;=
 };<br>};<br>static constexpr with_t with{};<br><br>struct pair { <br>=C2=
=A0=C2=A0 int first; <br>=C2=A0=C2=A0 int second; <br>=C2=A0=C2=A0 void sum=
(){ return first+second; }<br>};<br>void print(pair x);<br><br>std::vector =
&lt;pair&gt; pair_vector;<br>std::vector &lt;int&gt; output;<br><br>std::tr=
ansform(pair_vector, std::back_inserter(output), with.second);<br>std::tran=
sform(pair_vector, std::back_inserter(output), with.sum);<br>std::for_each(=
pair_vector, with.print)<br><br>Another nifty use case (the definition of o=
rder_by is left as an exercise):<br><br>std::sort(pair_vector, order_by.b);=
<br><br><br>HTH,<br><br>-- gpd<br><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&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_1325_2120019181.1443825083014--
------=_Part_1324_1671412814.1443825083014--

.