220 7867 <CAPBZbvyQdkV5XPve4pQUgEeVZg=SWAwXxfkHjiiMF=HP5DYQjA@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: "Billy O'Neal" <billy.oneal@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal to add std::mem_to_fun
Date: Tue, 19 Nov 2013 21:19:16 -0800
Lines: 299
Approved: news@gmane.org
Message-ID: <CAPBZbvyQdkV5XPve4pQUgEeVZg=SWAwXxfkHjiiMF=HP5DYQjA@mail.gmail.com>
References: <e16fa175-e5fa-4cd4-8635-9682b89b545c@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a1133073a9a639504eb94eebd
X-Trace: ger.gmane.org 1384924793 9008 80.91.229.3 (20 Nov 2013 05:19:53 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 20 Nov 2013 05:19:53 +0000 (UTC)
To: std-proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDKLBLVE6ADBB7UMWGKAKGQEYC74GBI@isocpp.org Wed Nov 20 06:20:00 2013
Return-path: <std-proposals+bncBDKLBLVE6ADBB7UMWGKAKGQEYC74GBI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDKLBLVE6ADBB7UMWGKAKGQEYC74GBI@isocpp.org>)
	id 1Vj0Cl-0007GY-Vm
	for gclcip-std-proposals@m.gmane.org; Wed, 20 Nov 2013 06:20:00 +0100
Original-Received: by mail-ob0-f199.google.com with SMTP id gq1sf11666263obb.2
        for <gclcip-std-proposals@m.gmane.org>; Tue, 19 Nov 2013 21:19:58 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=bE4ltlBaSmbnOWETotxftuxrnzo+3QeSld23GZiY4ZM=;
        b=b7DPxNw1xXrcgsIS4eh70c+DADfERjyytOAd15V+wSOWh3T9kRFu3aa6ONd0X/VZop
         0TOQgqAqwHeIvr0wpaH83IrCG2iTug7h82pVjqKPyuXnRJ6dCdvEdEE4K6CA3jBhw1ah
         1N7BwOn5/otePu2AxK9mm/EoNDQDooLbJn1GvHsXpg73gn5RzWb1vujGjdPlAQpmvh1S
         t63pveH52d+UVExdwIflmMehjU2yCCsS6tTf3NzI/J65L0hqgDIAmzl/yeWnsXC0RoCV
         QsgOVysGp93ykAc12TesJsoLQrgfSOWvesHK0cgr8DdhJB4IRvVJgnsyGLbGrsms1Orf
         guBg==
X-Gm-Message-State: ALoCoQmdM59zg9e8qHragSAlDDrP468emJ0aMUGFSKGXtPymA5+NLMesW4DJtZSZA65ZF2ugiU/I
X-Received: by 10.182.53.165 with SMTP id c5mr11299835obp.0.1384924798806;
        Tue, 19 Nov 2013 21:19:58 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.26.227 with SMTP id o3ls3508006qeg.5.gmail; Tue, 19 Nov
 2013 21:19:58 -0800 (PST)
X-Received: by 10.236.14.202 with SMTP id d50mr26668807yhd.47.1384924798057;
        Tue, 19 Nov 2013 21:19:58 -0800 (PST)
Original-Received: from mail-oa0-x22b.google.com (mail-oa0-x22b.google.com [2607:f8b0:4003:c02::22b])
        by mx.google.com with ESMTPS id 41si3628033yhf.227.2013.11.19.21.19.57
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 19 Nov 2013 21:19:58 -0800 (PST)
Received-SPF: pass (google.com: domain of billy.oneal@gmail.com designates 2607:f8b0:4003:c02::22b as permitted sender) client-ip=2607:f8b0:4003:c02::22b;
Original-Received: by mail-oa0-f43.google.com with SMTP id g12so9991161oah.2
        for <std-proposals@isocpp.org>; Tue, 19 Nov 2013 21:19:57 -0800 (PST)
X-Received: by 10.60.52.81 with SMTP id r17mr28798207oeo.3.1384924797623; Tue,
 19 Nov 2013 21:19:57 -0800 (PST)
Original-Received: by 10.182.87.37 with HTTP; Tue, 19 Nov 2013 21:19:16 -0800 (PST)
In-Reply-To: <e16fa175-e5fa-4cd4-8635-9682b89b545c@isocpp.org>
X-Original-Sender: billy.oneal@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of billy.oneal@gmail.com designates 2607:f8b0:4003:c02::22b as
 permitted sender) smtp.mail=billy.oneal@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:7867
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7867>

--001a1133073a9a639504eb94eebd
Content-Type: text/plain; charset=ISO-8859-1

IMHO, this could go either way. I've never gone to a standards meeting or
anything like that, but it seems the committee seems against messing with
additional binders now that lambdas are in the core language.

I'm not sure the name "mem_to_fun" makes sense -- the name "mem_fun" refers
to making a binder to a "MEMber_FUNction" -- but you're not binding to a
function at all here. This smooths over the syntactical issue of member
function calls needing the syntax x->y, but the STL only accepting the
syntax y(x).

Perhaps the name you're looking for is "project" -- because what you're
actually doing here is a projection.

An alternate solution proposed by Sean Parent in his Going::Native 2013
talk involves defining different versions of the standard algorithms that
accept optional projection functions as parameters.

Billy O'Neal
https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
http://stackoverflow.com/users/82320/billy-oneal
Malware Response Instructor - BleepingComputer.com


On Tue, Nov 19, 2013 at 8:41 PM, <dacamara.cameron@gmail.com> wrote:

> So I noticed browsing <functional> that there is currently not a way to
> create a function object that can return just a member of an object. There
> is a structure that converts a member function into a function object
> callable via the class as an argument (std::mem_fun_t). My question is why
> can't this exist for accessing members of a POD struct or even a class?
> That could be useful for standard algorithms when you need access to a
> specific member but don't wanna write out the lambda for it, eg:
>
> struct Books {
>   std::string author;
>   std::string title;
> };
>
>
> // all we want is to make a set of titles of books from our library vector
> std::set<std::string> uniqTitles;
> std::transform(library.begin(), library.end(), std::inserter(uniqTitles,uniqTitles
> .end()),
>                [] (const Books& b) -> std::string
>                {
>                   return b.title;
>                }
> ); // why can't there be a standard way to just grab the member?
>
> so really the implementation / interface would look a lot like
> std::mem_fun:
>
> template <typename T, typename M>
> struct mem_to_fun_t {
>   M T::*_mem;
>   explicit mem_to_fun_t(M T::*mem): _mem(mem) { }
>
>   const M& operator()(const T& c) const{return c.*_mem;}
>   M& operator()(T& c) {return c.*_mem;}
> };
>
>
> template <typename T, typename M> inline
> auto mem_to_fun(M T::*mem) -> mem_to_fun_t<T,M> {
>   return mem_to_fun_t<T,M>{mem};
> }
>
> it doesn't have to be exactly like this but perhaps a similar
> implementation.
>
> Here is the ideone link if you wanna see how it could be used:
> http://ideone.com/3uoDPV
>
>
>  --
>
> ---
> 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/.

--001a1133073a9a639504eb94eebd
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">IMHO, this could go either way. I&#39;ve never gone to a s=
tandards meeting or anything like that, but it seems the committee seems ag=
ainst messing with additional binders now that lambdas are in the core lang=
uage.<div>

<br></div><div>I&#39;m not sure the name &quot;mem_to_fun&quot; makes sense=
 -- the name &quot;mem_fun&quot; refers to making a binder to a &quot;MEMbe=
r_FUNction&quot; -- but you&#39;re not binding to a function at all here. T=
his smooths over the syntactical issue of member function calls needing the=
 syntax x-&gt;y, but the STL only accepting the syntax y(x).</div>

<div><br></div><div>Perhaps the name you&#39;re looking for is &quot;projec=
t&quot; -- because what you&#39;re actually doing here is a projection.</di=
v><div><br></div><div>An alternate solution proposed by Sean Parent in his =
Going::Native 2013 talk involves defining different versions of the standar=
d algorithms that accept optional projection functions as parameters.</div>

</div><div class=3D"gmail_extra"><br clear=3D"all"><div><div dir=3D"ltr"><d=
iv>Billy O&#39;Neal</div><div><a href=3D"https://bitbucket.org/BillyONeal/"=
 target=3D"_blank">https://github.com/BillyONeal/</a></div><div><a href=3D"=
http://stackoverflow.com/users/82320/billy-oneal" target=3D"_blank">http://=
stackoverflow.com/users/82320/billy-oneal</a></div>

<div>Malware Response Instructor - BleepingComputer.com</div></div></div>
<br><br><div class=3D"gmail_quote">On Tue, Nov 19, 2013 at 8:41 PM,  <span =
dir=3D"ltr">&lt;<a href=3D"mailto:dacamara.cameron@gmail.com" target=3D"_bl=
ank">dacamara.cameron@gmail.com</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">

<div dir=3D"ltr">So I noticed browsing &lt;functional&gt; that there is cur=
rently not a way to create a function object that can return just a member =
of an object. There is a structure that converts a member function into a f=
unction object callable via the class as an argument (std::mem_fun_t). My q=
uestion is why can&#39;t this exist for accessing members of a POD struct o=
r even a class? That could be useful for standard algorithms when you need =
access to a specific member but don&#39;t wanna write out the lambda for it=
, eg:<br>

<br><div style=3D"background-color:rgb(250,250,250);border:1px solid rgb(18=
7,187,187);word-wrap:break-word"><code><div><span style=3D"color:#008">stru=
ct</span><span style> </span><span style=3D"color:#606">Books</span><span s=
tyle> </span><span style=3D"color:#660">{</span><span style><br>

=A0 std</span><span style=3D"color:#660">::</span><span style=3D"color:#008=
">string</span><span style> author</span><span style=3D"color:#660">;</span=
><span style><br>=A0 std</span><span style=3D"color:#660">::</span><span st=
yle=3D"color:#008">string</span><span style> title</span><span style=3D"col=
or:#660">;</span><span style><br>

</span><span style=3D"color:#660">};</span><span style><br><br><br></span><=
span style=3D"color:#800">// all we want is to make a set of titles of book=
s from our library vector</span><span style><br>std</span><span style=3D"co=
lor:#660">::</span><span style=3D"color:#008">set</span><span style=3D"colo=
r:#660">&lt;</span><span style>std</span><span style=3D"color:#660">::</spa=
n><span style=3D"color:#008">string</span><span style=3D"color:#660">&gt;</=
span><span style> uniqTitles</span><span style=3D"color:#660">;</span><span=
 style><br>

std</span><span style=3D"color:#660">::</span><span style>transform</span><=
span style=3D"color:#660">(</span><span style>library</span><span style=3D"=
color:#660">.</span><span style=3D"color:#008">begin</span><span style=3D"c=
olor:#660">(),</span><span style> library</span><span style=3D"color:#660">=
..</span><span style=3D"color:#008">end</span><span style=3D"color:#660">(),=
</span><span style> std</span><span style=3D"color:#660">::</span><span sty=
le>inserter</span><span style=3D"color:#660">(</span><span style>uniqTitles=
</span><span style=3D"color:#660">,</span><span style> uniqTitles</span><sp=
an style=3D"color:#660">.</span><span style=3D"color:#008">end</span><span =
style=3D"color:#660">()),</span><span style> <br>

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</span><span style=3D"color:#660">[]</span><=
span style> </span><span style=3D"color:#660">(</span><span style=3D"color:=
#008">const</span><span style> </span><span style=3D"color:#606">Books</spa=
n><span style=3D"color:#660">&amp;</span><span style> b</span><span style=
=3D"color:#660">)</span><span style> </span><span style=3D"color:#660">-&gt=
;</span><span style> std</span><span style=3D"color:#660">::</span><span st=
yle=3D"color:#008">string</span><span style> <br>

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</span><span style=3D"color:#660">{</span><s=
pan style><br>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </span><span style=3D"col=
or:#008">return</span><span style> b</span><span style=3D"color:#660">.</sp=
an><span style>title</span><span style=3D"color:#660">;</span><span style><=
br>

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0</span><span style=3D"color:#660">}</span><s=
pan style><br></span><span style=3D"color:#660">);</span><span style> </spa=
n><span style=3D"color:#800">// why can&#39;t there be a standard way to ju=
st grab the member? </span></div>

</code></div><div><br></div><div>so really the implementation / interface w=
ould look a lot like std::mem_fun:</div><div><br></div><div><div style=3D"b=
ackground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wra=
p:break-word">

<code><div><div style=3D"background-color:rgb(250,250,250);border:1px solid=
 rgb(187,187,187);word-wrap:break-word"><code><div><span style=3D"color:#00=
8">template</span><span style> </span><span style=3D"color:#660">&lt;</span=
><span style=3D"color:#008">typename</span><span style> T</span><span style=
=3D"color:#660">,</span><span style> </span><span style=3D"color:#008">type=
name</span><span style> M</span><span style=3D"color:#660">&gt;</span><span=
 style><br>

</span><span style=3D"color:#008">struct</span><span style> mem_to_fun_t </=
span><span style=3D"color:#660">{</span><span style><br>=A0 M T</span><span=
 style=3D"color:#660">::*</span><span style>_mem</span><span style=3D"color=
:#660">;</span><span style><br>

=A0 </span><span style=3D"color:#008">explicit</span><span style> mem_to_fu=
n_t</span><span style=3D"color:#660">(</span><span style>M T</span><span st=
yle=3D"color:#660">::*</span><span style>mem</span><span style=3D"color:#66=
0">):</span><span style> _mem</span><span style=3D"color:#660">(</span><spa=
n style>mem</span><span style=3D"color:#660">)</span><span style> </span><s=
pan style=3D"color:#660">{</span><span style> </span><span style=3D"color:#=
660">}</span><span style><br>

=A0 <br>=A0 </span><span style=3D"color:#008">const</span><span style> M</s=
pan><span style=3D"color:#660">&amp;</span><span style> </span><span style=
=3D"color:#008">operator</span><span style=3D"color:#660">()(</span><span s=
tyle=3D"color:#008">const</span><span style> T</span><span style=3D"color:#=
660">&amp;</span><span style> c</span><span style=3D"color:#660">)</span><s=
pan style> </span><span style=3D"color:#008">const</span><span style=3D"col=
or:#660">{</span><span style=3D"color:#008">return</span><span style> c</sp=
an><span style=3D"color:#660">.*</span><span style>_mem</span><span style=
=3D"color:#660">;}</span><span style><br>

=A0 M</span><span style=3D"color:#660">&amp;</span><span style> </span><spa=
n style=3D"color:#008">operator</span><span style=3D"color:#660">()(</span>=
<span style>T</span><span style=3D"color:#660">&amp;</span><span style> c</=
span><span style=3D"color:#660">)</span><span style> </span><span style=3D"=
color:#660">{</span><span style=3D"color:#008">return</span><span style> c<=
/span><span style=3D"color:#660">.*</span><span style>_mem</span><span styl=
e=3D"color:#660">;}</span><span style><br>

</span><span style=3D"color:#660">};</span><span style><br><br><br></span><=
span style=3D"color:#008">template</span><span style> </span><span style=3D=
"color:#660">&lt;</span><span style=3D"color:#008">typename</span><span sty=
le> T</span><span style=3D"color:#660">,</span><span style> </span><span st=
yle=3D"color:#008">typename</span><span style> M</span><span style=3D"color=
:#660">&gt;</span><span style> </span><span style=3D"color:#008">inline</sp=
an><span style><br>

</span><span style=3D"color:#008">auto</span><span style> mem_to_fun</span>=
<span style=3D"color:#660">(</span><span style>M T</span><span style=3D"col=
or:#660">::*</span><span style>mem</span><span style=3D"color:#660">)</span=
><span style> </span><span style=3D"color:#660">-&gt;</span><span style> me=
m_to_fun_t</span><span style=3D"color:#660">&lt;</span><span style>T</span>=
<span style=3D"color:#660">,</span><span style>M</span><span style=3D"color=
:#660">&gt;</span><span style> </span><span style=3D"color:#660">{</span><s=
pan style><br>

=A0 </span><span style=3D"color:#008">return</span><span style> mem_to_fun_=
t</span><span style=3D"color:#660">&lt;</span><span style>T</span><span sty=
le=3D"color:#660">,</span><span style>M</span><span style=3D"color:#660">&g=
t;{</span><span style>mem</span><span style=3D"color:#660">};</span><span s=
tyle><br>

</span><span style=3D"color:#660">}</span></div></code></div></div></code><=
/div><br></div><div>it doesn&#39;t have to be exactly like this but perhaps=
 a similar implementation.</div><div><br></div><div>Here is the ideone link=
 if you wanna see how it could be used:=A0<a href=3D"http://ideone.com/3uoD=
PV" target=3D"_blank">http://ideone.com/3uoDPV</a></div>

<span class=3D"HOEnZb"><font color=3D"#888888"><div><br></div><div><br></di=
v></font></span></div><span class=3D"HOEnZb"><font color=3D"#888888">

<p></p>

-- <br>
=A0<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%2Bunsubscribe@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 />
&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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a1133073a9a639504eb94eebd--

.
