220 23646 <56914870.3020407@wanadoo.fr> article
Path: news.gmane.org!not-for-mail
From: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: invoke and unpacking tuple-like type instances
Date: Sat, 9 Jan 2016 18:50:40 +0100
Lines: 111
Approved: news@gmane.org
Message-ID: <56914870.3020407@wanadoo.fr>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Trace: ger.gmane.org 1452361851 10674 80.91.229.3 (9 Jan 2016 17:50:51 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 9 Jan 2016 17:50:51 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDH67CONY4PBB4UQYW2AKGQE3GZ4DKA@isocpp.org Sat Jan 09 18:50:44 2016
Return-path: <std-proposals+bncBDH67CONY4PBB4UQYW2AKGQE3GZ4DKA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f70.google.com ([209.85.215.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDH67CONY4PBB4UQYW2AKGQE3GZ4DKA@isocpp.org>)
	id 1aHxf2-0001oN-0C
	for gclcip-std-proposals@m.gmane.org; Sat, 09 Jan 2016 18:50:44 +0100
Original-Received: by mail-lf0-f70.google.com with SMTP id k69sf15270572lfg.3
        for <gclcip-std-proposals@m.gmane.org>; Sat, 09 Jan 2016 09:50:43 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:subject:to:message-id:date:user-agent:mime-version
         :content-type: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=0MEdUYeAbAGurTeQk6A1SInec7F0Pt+MVPqlrLF4lHM=;
        b=wTgM48cEHclsjMeDxwVZ95FSiMLsqzlk0DzeTUHru5hijO7R/mrAk5RPNAdtr7+Ilt
         r4jH/SSl/AYFEWpN9bHpIcRT0ifD1a7ZsSX5W3WchMzieNgdlOyYdDhuxuXYoUtFzqQI
         wxrcrcoFxYT2ofFMXGQTyEYq0knINTwwT9T1nmIhCFJFMm8eCfMiHbPI6o7TxITaN+fy
         i4qJef2P/YMuZGxrgXcQIJc/V1CugXO8DLr9G37CAn6ik9qqJDvcbkwQ9BDKerJT1i/S
         Giu1ZhJlRPhwaVaWQLX8Zs24yOlcEvjjYICAc9Cf0kFOaFlQgjZoZgCB8FrKTdQ3EWKM
         gr+Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:subject:to:message-id:date:user-agent
         :mime-version:content-type: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=0MEdUYeAbAGurTeQk6A1SInec7F0Pt+MVPqlrLF4lHM=;
        b=LQIADqr3vEpEToqhE+ZZjGIA4p2SELfvkgyaVfVCRRHvBWE/PWUZ7ahDYjT7/00NKd
         BeLhc0pUJGgcFixaR61v0LWrCEbDjH0qJPHKKoaKIzhg8wXyHXDXa+7uFrq5ZN4zrRgi
         hCFgrN+Xxik3Mt62P9soltXQnW9Ku6hDxGmviI6zCQ8oJSZnZK91DFf+D4OIww3GPp6T
         F/fJ1mvQhgkEiRO+ncqnU4tVOKLpCfPtLQID+ocP51jClBohJWt3npde6WLJNmhBNwgp
         IKGCrmctuGUugh3l+xLtgHQxvY2rnjJ/PygoOeCgVfuB98UXp64cnpCsBeP7p9+Sys58
         dS2A==
X-Gm-Message-State: ALoCoQlUq6mkvEgRGp+7UvX43AYMywpnDh9aGrrAda+C+0QD/CCvI3Wa1dc1UbV8pLsGN8gSiFk+qUieiKH/fGXbUzClQRmvVQ==
X-Received: by 10.28.127.206 with SMTP id a197mr774432wmd.6.1452361843321;
        Sat, 09 Jan 2016 09:50:43 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.47.13 with SMTP id v13ls151449wmv.36.gmail; Sat, 09 Jan
 2016 09:50:41 -0800 (PST)
X-Received: by 10.28.17.8 with SMTP id 8mr4589930wmr.65.1452361841841;
        Sat, 09 Jan 2016 09:50:41 -0800 (PST)
Original-Received: from smtp.smtpout.orange.fr (smtp07.smtpout.orange.fr. [80.12.242.129])
        by mx.google.com with ESMTPS id v10si184074140wjx.223.2016.01.09.09.50.41
        for <std-proposals@isocpp.org>
        (version=TLS1 cipher=AES128-SHA bits=128/128);
        Sat, 09 Jan 2016 09:50:41 -0800 (PST)
Received-SPF: neutral (google.com: 80.12.242.129 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) client-ip=80.12.242.129;
Original-Received: from new-host.home ([86.214.79.135])
	by mwinf5d13 with ME
	id 3tqg1s00Q2v9yza03tqgvc; Sat, 09 Jan 2016 18:50:41 +0100
X-ME-Helo: new-host.home
X-ME-Auth: dmljZW50ZS5ib3RldEB3YW5hZG9vLmZy
X-ME-Date: Sat, 09 Jan 2016 18:50:41 +0100
X-ME-IP: 86.214.79.135
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0)
 Gecko/20100101 Thunderbird/38.4.0
X-Original-Sender: vicente.botet@wanadoo.fr
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 80.12.242.129 is neither permitted nor denied by best guess
 record for domain of vicente.botet@wanadoo.fr) smtp.mailfrom=vicente.botet@wanadoo.fr
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:23646
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/23646>

Hi,


I would like to have some feedback on a function that acts as unpacking 
tuple-like classes in the context of the invoke function. This was 
presented already with the name args(t) as an alternative library 
solution to unpack tuple in the thread "[std-discussion] Distinction 
between Argument packs and tuples" [1] where an operator... on tuple was 
proposed. The proposed operator... introduced breaking changes and so 
another operator would be needed.

make_tuple packs some elements in a tuple. It seem natural to think of 
unpacking a tuple into its elements, so that

     make_tuple(unpack(t)) == t  // that is (pack . unpack = id)

The same applies to forward_as_tuple:

     forward_as_tuple(unpack(g())) == g()

The result of unpack could be a wrapper unpacked<T> as ref wraps a 
reference in a reference wrapper.

Having this, we can adapt invoke so that, if some of its args are 
unpacked<T>, invoke would work as if

invoke(f, a, b, unpack(t1), d, unpack(t2)) =
     apply(f, tuple_cat(forward_as_tuple(a), forward_as_tuple(b), 
forward_as_tuple(unpack(t1)), forward_as_tuple(d), 
forward_as_tuple(unpack(t2))))
     apply(f, tuple_cat(forward_as_tuple(a), forward_as_tuple(b), t1, 
forward_as_tuple(d), t2))
     apply(f, tuple{a, b, get<0>(t1), ..., get<N1-1>(t1), d, get<0>(t2), 
...., get<N2-1>(t2}));
     invoke(f, a, b, get<0>(t1), ..., get<N1-1>(t1), d, get<0>(t2), ..., 
get<N2-1>(t2));
     f(a, b, get<0>(t1), ..., get<N1-1>(t1), d, get<0>(t2), ..., 
get<N2-1>(t2));

where Ni is the tuple_size<decltype(ti)>::value


Definition when one of Args is unpacked<T>

template <class F, class ...Args>
auto invoke(F&& f, Args args...) {
     return apply(forward<F>(f), forward_as_tuple(forward<Args>(args)...);
}


unpack shoudl works with lvalue and rvalues

     template <class TL>
     unpacked<reference_wrapper<TL>> unpack(TL & tl);

     template <class TL>
     unpacked<decay<TL>> unpack(TL && tl);


and unpack on unpacked doesn't changes anything as ref with 
reference_wrapper

     template <class T>
     unpacked<T>& unpack(unpacked<T> & tl);

     template <class T>
     unpacked<T> const& unpack(unpacked<T> const& tl);

     template <class T>
     unpacked<T> && unpack(unpacked<T> && tl);

In addition, given a tuple t, what could be the meaning of *t? Well t is 
not a pointer, but it contains things as optional does, so we can define 
tuple::operator*() as if we unpacked it

     std::tuple<int, string> t;
     ...
     invoke(f, a, b, *t1, d) == f(a, b, get<0>(t1), ..., get<N1-1>(t1), d);

Note that if as_const is accepted there is no need for a specific 
cunpack function as unpack(as_const(t)).

Note also that unpack would works not only for std::tuple, but with any 
tuple-like type providing get<I> access.
However the operator* need to be defined explicitly for each tuple-like 
type :(

Bike-shading:
     unpack/unpacked
     unpack/tuple_like_wrapper
     ...

Waiting for a language-based proposal, is there an interest in a library 
proposal providing a partial solution (unpack needs invoke to be expanded)?

Best,
Vicente

P.S. Any

[1] 
https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/qsM_4DijZFM

-- 

--- 
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.

.
