220 11745 <CAFk2RUZDriC44MfJQ1SNU27CRgGyYnpKUPrKuE2xfCTZ++f0Zg@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Ville Voutilainen <ville.voutilainen@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: N4078: Rvalue reference overloads for value()
 method returns object by value
Date: Wed, 9 Jul 2014 21:57:00 +0300
Lines: 44
Approved: news@gmane.org
Message-ID: <CAFk2RUZDriC44MfJQ1SNU27CRgGyYnpKUPrKuE2xfCTZ++f0Zg@mail.gmail.com>
References: <b538efba-faf4-4ffc-a553-302b9d2ba2c0@isocpp.org>
	<764569c3-b26b-4938-970e-44a4681de132@isocpp.org>
	<CAFk2RUbRQ1WWrUV=fp7FRGVFJrG=FHW1qrYUfhT4aL=GeGL7Qg@mail.gmail.com>
	<b8450477-63cc-4855-b183-aed7af7781c3@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1404932232 5172 80.91.229.3 (9 Jul 2014 18:57:12 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 9 Jul 2014 18:57:12 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC5JHI7A7ALRB7FA62OQKGQEVS6SNLY@isocpp.org Wed Jul 09 20:57:06 2014
Return-path: <std-proposals+bncBC5JHI7A7ALRB7FA62OQKGQEVS6SNLY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f70.google.com ([209.85.220.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC5JHI7A7ALRB7FA62OQKGQEVS6SNLY@isocpp.org>)
	id 1X4x38-0005Ue-E2
	for gclcip-std-proposals@m.gmane.org; Wed, 09 Jul 2014 20:57:02 +0200
Original-Received: by mail-pa0-f70.google.com with SMTP id lj1sf53028952pab.9
        for <gclcip-std-proposals@m.gmane.org>; Wed, 09 Jul 2014 11:57:01 -0700 (PDT)
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:date
         :message-id:subject:from: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=YiwyNzFnRD8ND5wIrHW4cyb+7JJ8Z7kOJjJtKkyHoBI=;
        b=AajoMIy/tK97OoVTkWu0mgTiY47H2ZyKNLwlMAxd0enR4WStHiA4sX64Bn79i/cBZM
         cOFbKd/IcVB/upgdcbY7SnokIi4qdu3AXjgxa9JPCMdwXxXRq0AwIeTefGFJjr8yqiLo
         6svWV3QfP9kBPoTbD+Z8A1NzkOV8Lkqd04eUCKOy+FBc+y9mVzMq5i0JNmqjS8fnQac9
         oe4/MwY5aW5KRR2Cn5lSmrL1CbLZOD5p3eKP6gEBKt4QD2wvVpDSR9PZ9fU23jVf6uqt
         I7+0gXTselUGo92zQ034OKDdbmGb9LJcAjI5pPR2grYDJR5luTQq3Lu5VX9XurxCYkdA
         w+IA==
X-Gm-Message-State: ALoCoQlGhEIVXYnErbwllMI0ieb3PTOYlwI1U5buj7G/H0d+jyGS4d8wSUBt9lXeJRx9OaI+xnZl
X-Received: by 10.66.182.170 with SMTP id ef10mr9495208pac.0.1404932221364;
        Wed, 09 Jul 2014 11:57:01 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.81.106 with SMTP id e97ls2076220qgd.43.gmail; Wed, 09 Jul
 2014 11:57:00 -0700 (PDT)
X-Received: by 10.224.129.130 with SMTP id o2mr75276851qas.64.1404932220611;
        Wed, 09 Jul 2014 11:57:00 -0700 (PDT)
Original-Received: from mail-qc0-x236.google.com (mail-qc0-x236.google.com [2607:f8b0:400d:c01::236])
        by mx.google.com with ESMTPS id r6si22880908qcd.22.2014.07.09.11.57.00
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 09 Jul 2014 11:57:00 -0700 (PDT)
Received-SPF: pass (google.com: domain of ville.voutilainen@gmail.com designates 2607:f8b0:400d:c01::236 as permitted sender) client-ip=2607:f8b0:400d:c01::236;
Original-Received: by mail-qc0-f182.google.com with SMTP id m20so6909659qcx.27
        for <std-proposals@isocpp.org>; Wed, 09 Jul 2014 11:57:00 -0700 (PDT)
X-Received: by 10.229.252.130 with SMTP id mw2mr70371486qcb.12.1404932220527;
 Wed, 09 Jul 2014 11:57:00 -0700 (PDT)
Original-Received: by 10.224.31.137 with HTTP; Wed, 9 Jul 2014 11:57:00 -0700 (PDT)
In-Reply-To: <b8450477-63cc-4855-b183-aed7af7781c3@isocpp.org>
X-Original-Sender: ville.voutilainen@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of ville.voutilainen@gmail.com designates 2607:f8b0:400d:c01::236 as
 permitted sender) smtp.mail=ville.voutilainen@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:11745
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11745>

On 9 July 2014 21:34,  <tomaszkam@gmail.com> wrote:
> I want point out one other think that I run into, when I was creating a
> handle_value_or_optional in
> https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/std-proposals/RTUK2xO0tzs.
> I will provide here shorter version. Let assume we want to have the
> following function handle_optional(opt, fv, fn) that when opt has value will
> invoke fv(*opt) otherwis fn.
>
> I we have the r-value reference qualified operator* and value method
> (instead of returning by value) I can write:
> template<typename U, typename FV, typename FN> //I removed the checking form
> this function to make it simpler
> delctype(auto) handle_optional(U&& u, FV&& fv, FN&& fn)
> {
>   return u ? std::forward<FV>(fv)(*std::forward<U>(u)) :
> std::forward<FN>(fn);
> }
> Because *std::forward<U>(u) will return a rvalue reference if such overload
> exists. If the optional has no rvalue refence method
> or the one returning value I must write to avoid making uncessary
> temporaries:
> template<typename U, typename FV, typename FN> //I removed the checking form
> this function to make it simpler
> delctype(auto) handle_optional(U&& u, FV&& fv, FN&& fn)
> {
>   return u ? std::forward<FV>(fv)(std::forward<same_cv_ref_t<typename
> decay_t<U>::value_type, U&&>>(*u)) : std::forward<FN>(fn);
> }
> //The same_cv_ref_as_t is needed to use std::forward<T&&> if optional<T>&&
> is passed as first argument type. And actually this works because
> u is lvalue here.

Ah, I see. Forwarding a dereferenced named value will never create a
temporary, *forward<U>(u)
might.

-- 

--- 
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/.

.
