220 29466 <582F2738.7040209@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: for...(T : t) // fold expression improvement
Date: Fri, 18 Nov 2016 11:07:20 -0500
Lines: 38
Approved: news@gmane.org
Message-ID: <582F2738.7040209@gmail.com>
References: <7c87350a-7ac2-489b-b107-ea25a7bd6c74@isocpp.org>
 <110fecc1-a731-f6ad-fa8d-cfe2cb36faaa@gmail.com>
 <CAFk2RUY6eJ2VpP2wVUcZBM5yJBbrwrJ3TdWBZRoH0Eho+YacfA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: blaine.gmane.org 1479485247 5243 195.159.176.226 (18 Nov 2016 16:07:27 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 18 Nov 2016 16:07:27 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.1.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBPOOXTAQKGQEAETCZYI@isocpp.org Fri Nov 18 17:07:23 2016
Return-path: <std-proposals+bncBC37LBFWUIFBBPOOXTAQKGQEAETCZYI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f69.google.com ([74.125.83.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBPOOXTAQKGQEAETCZYI@isocpp.org>)
	id 1c7lhC-0000Ai-NQ
	for gclcip-std-proposals@m.gmane.org; Fri, 18 Nov 2016 17:07:22 +0100
Original-Received: by mail-pg0-f69.google.com with SMTP id y71sf259372455pgd.0
        for <gclcip-std-proposals@m.gmane.org>; Fri, 18 Nov 2016 08:07:26 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:x-original-sender:x-original-authentication-results
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=ZAYhcLiifFGoVLRuS3O5dF1rKELx02GPF4q4aGz/Xn8=;
        b=STOXxM5Jap7qSeQYZBlncZXUseCII9nlAZtNBf3OzB+/VsBHqlUcWGHPAHM6AqjdIg
         s66uyHo5yIl6hDMPqPUyEW1WluBg6Oz9JBSdlbarT3v0Ix/YMDrtkFWkRJHHtCOq885f
         OS+lxzWVCdFBeBQ+XcoQrIzoLJ/M7TX7Rkp8WIL4iPlouS0+wuVs5Vtp8qgb0rFWu4JT
         /Wuxev/jp1gmfr6qKTuQ7zSpdKEoZdS9pgoQt7YXnbr6XiDW7T12HbwrdQ4j+isnIOzJ
         wVr8jtounXSCsqZXmvWOVvvv6QVHDKdMefIjokzvZeT5gSVxE1sBWraQFG/PoYuIItkZ
         E3mA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=ZAYhcLiifFGoVLRuS3O5dF1rKELx02GPF4q4aGz/Xn8=;
        b=XN+19P27f7fxZzHZbUNYSwAbL3EENcQWO94qDIiifUtYnqvtV3WLryYI8+qks7nNXW
         +owhTCqdQZ3lY61DOgcfjTxUKoQ4Nk58zrgCvRDV/T5VkAC2wb/0NkYEC2rThcJQuaei
         QsK3proFCflYdQ0pVDIsIERooNB+srXnC1pgzhzMu3Y8i/PLXO0J6GNzvi1jWrvNnHdV
         Sb00zP0U/p0MmugYk0T/g9kRBmVQvwrEfrbtHQY1f+Z7baB10pPEsEbTzv9F/ii5h/Y/
         VQ0lxfioWl6b+liBEumkFktul14pK6UGV0TtyuhFyOF8cSw7dPOjvkOaylzbXhU2/ngg
         b8HA==
X-Gm-Message-State: AKaTC03ADzALM/38/F98ugNaDWY2zrtrGDvj0nl3Mt96QocEKCnGW2wS4bNp/BUleECqzA==
X-Received: by 10.99.126.11 with SMTP id z11mr101118pgc.79.1479485245941;
        Fri, 18 Nov 2016 08:07:25 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.29.137 with SMTP id y9ls6986901otd.39.gmail; Fri, 18 Nov
 2016 08:07:25 -0800 (PST)
X-Received: by 10.55.207.134 with SMTP id v6mr569126qkl.105.1479485245109;
        Fri, 18 Nov 2016 08:07:25 -0800 (PST)
Original-Received: from mail-qk0-x22e.google.com (mail-qk0-x22e.google.com. [2607:f8b0:400d:c09::22e])
        by mx.google.com with ESMTPS id z47si2578565qtb.204.2016.11.18.08.07.25
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 18 Nov 2016 08:07:25 -0800 (PST)
Received-SPF: pass (google.com: domain of mwoehlke.floss@gmail.com designates 2607:f8b0:400d:c09::22e as permitted sender) client-ip=2607:f8b0:400d:c09::22e;
Original-Received: by mail-qk0-x22e.google.com with SMTP id q130so269071014qke.1
        for <std-proposals@isocpp.org>; Fri, 18 Nov 2016 08:07:25 -0800 (PST)
X-Received: by 10.55.16.10 with SMTP id a10mr558228qkh.66.1479485244661;
        Fri, 18 Nov 2016 08:07:24 -0800 (PST)
Original-Received: from [192.168.1.173] (tripoint.kitware.com. [66.194.253.20])
        by smtp.googlemail.com with ESMTPSA id q21sm4351152qkq.8.2016.11.18.08.07.20
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 18 Nov 2016 08:07:21 -0800 (PST)
In-Reply-To: <CAFk2RUY6eJ2VpP2wVUcZBM5yJBbrwrJ3TdWBZRoH0Eho+YacfA@mail.gmail.com>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of
 mwoehlke.floss@gmail.com designates 2607:f8b0:400d:c09::22e as permitted
 sender) smtp.mailfrom=mwoehlke.floss@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:29466
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29466>

On 2016-11-18 03:36, Ville Voutilainen wrote:
> Alternatively, fold over a lambda:
> 
> template<typename... T>
> void foo(T... a) {
>     ([&]() {
>         std::cout << a << std::endl;
>     }(),...);
> }

Wow... that's twisty :-). I didn't know you could do that with fold
expressions! (That... actually creates a *different lambda* for each
item in `a`!)

> Caveat emptor, it doesn't work with gcc or msvc yet.

This version should work:

  template<typename... T>
  void foo(T... a) {
      ([&](auto&& ai) {
          std::cout << ai << std::endl;
      }(a),...);
  }

....and is less surprising that it does ;-). Instead of folding on the
lambda itself, this version folds on invocation of the lambda (albeit a
templated lambda).

-- 
Matthew

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/582F2738.7040209%40gmail.com.

.
