220 7869 <CANh-dXmcyBwj-ivNYJxhpbstK9-aWKZd-vs4ssLTyyZsTn9KCw@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Jeffrey Yasskin <jyasskin@google.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Proposal to add std::mem_to_fun
Date: Wed, 20 Nov 2013 00:51:58 -0500
Lines: 71
Approved: news@gmane.org
Message-ID: <CANh-dXmcyBwj-ivNYJxhpbstK9-aWKZd-vs4ssLTyyZsTn9KCw@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: text/plain; charset=ISO-8859-1
X-Trace: ger.gmane.org 1384926735 27070 80.91.229.3 (20 Nov 2013 05:52:15 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 20 Nov 2013 05:52:15 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDDM34EO6QDRBEU4WGKAKGQEIUX3HXA@isocpp.org Wed Nov 20 06:52:22 2013
Return-path: <std-proposals+bncBDDM34EO6QDRBEU4WGKAKGQEIUX3HXA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f200.google.com ([209.85.223.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDDM34EO6QDRBEU4WGKAKGQEIUX3HXA@isocpp.org>)
	id 1Vj0i4-00046N-EQ
	for gclcip-std-proposals@m.gmane.org; Wed, 20 Nov 2013 06:52:20 +0100
Original-Received: by mail-ie0-f200.google.com with SMTP id at1sf4415843iec.11
        for <gclcip-std-proposals@m.gmane.org>; Tue, 19 Nov 2013 21:52:19 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20120113;
        h=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=lma9El9NrFvyGGTU0kueiSVQOHlV9qeoEMudAwUuzCQ=;
        b=XSHsG2MfB7/VyMJbUFMg9Ow+YaqzDJPj5fu3vlpGdoaJ4R/sMf4n9IWyq/KBKmUYxh
         c+vu3XwWGFEnhnyHJIVB3+8s3MLeoyru8fJkCApQkzrxxTv8SFeu3oPtK2tScfkGWwhf
         6cc7LcHgD0NCaQSJzBs1GvqYNAUuMsJJydd2D3vvVaicgflxF2uVRyl2l7TE8CF/4HyY
         t9PrnIaCs9PB7nK8CUpRJZtgioKEIz6FIaT+GjvGRJfzoOo+nBMqRdxhxEgf48AuPSfi
         VUMMtuHph9wU7TVkarMnSAp/r0SyK8oSw15vgYd5kfsvEfxKrRf3xrfpFeTosGgeTftA
         yEag==
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=lma9El9NrFvyGGTU0kueiSVQOHlV9qeoEMudAwUuzCQ=;
        b=LlHepgULfIlU9r1hCxmJUsJbjaYRcGLvL0PifhZf5eXP1Tx2WqiPrfyOp7XDSyQ/LV
         LR8f/xai8nwHCis3VpL0y5AZ35FEb1hwl2Q3a/DgehbxlMyBzeVjne1ou+WfTKgp/MgB
         /wH9ElQfiovKsupX5zNh59NHdghd+yt/yjSH2ab0OnqYZNCuLzytkZzclnjdQqimvlUq
         wUXAiEw+KkrUOIPlG2EMctLboCzEbT1GTPQOObiNPSl1nEnNzZGA6dEu/8VdFng+B0DY
         jFl7AJiaq0CdXIXyUCmRA1zfR+OhcxA06HhAryCZyMwEfl6RJSQP4XvwZ/tAduPFcNSm
         ehJg==
X-Gm-Message-State: ALoCoQn9ZMIEw8HwJ+DmyB4kl+cnRSvfmOLZxKtV/7Mw4YJ1D610t/1Egt37JAn29JJQNkFbFsut
X-Received: by 10.182.66.193 with SMTP id h1mr18424obt.47.1384926739525;
        Tue, 19 Nov 2013 21:52:19 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.36.161 with SMTP id r1ls117830qej.71.gmail; Tue, 19 Nov
 2013 21:52:18 -0800 (PST)
X-Received: by 10.224.54.5 with SMTP id o5mr39091149qag.9.1384926738659;
        Tue, 19 Nov 2013 21:52:18 -0800 (PST)
Original-Received: from mail-qa0-x232.google.com (mail-qa0-x232.google.com [2607:f8b0:400d:c00::232])
        by mx.google.com with ESMTPS id k1si4992515qao.74.2013.11.19.21.52.18
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 19 Nov 2013 21:52:18 -0800 (PST)
Received-SPF: pass (google.com: domain of jyasskin@google.com designates 2607:f8b0:400d:c00::232 as permitted sender) client-ip=2607:f8b0:400d:c00::232;
Original-Received: by mail-qa0-f50.google.com with SMTP id i13so1910562qae.9
        for <std-proposals@isocpp.org>; Tue, 19 Nov 2013 21:52:18 -0800 (PST)
X-Received: by 10.224.29.67 with SMTP id p3mr49434630qac.30.1384926738414;
 Tue, 19 Nov 2013 21:52:18 -0800 (PST)
Original-Received: by 10.229.177.131 with HTTP; Tue, 19 Nov 2013 21:51:58 -0800 (PST)
In-Reply-To: <e16fa175-e5fa-4cd4-8635-9682b89b545c@isocpp.org>
X-Original-Sender: jyasskin@google.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of jyasskin@google.com designates 2607:f8b0:400d:c00::232 as permitted
 sender) smtp.mail=jyasskin@google.com;       dkim=pass header.i=@google.com;
       dmarc=pass (p=REJECT dis=NONE) header.from=google.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:7869
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7869>

I think std::mem_fn already supports this:
http://en.cppreference.com/w/cpp/utility/functional/mem_fn

On Tue, Nov 19, 2013 at 11: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/.

.
