220 28750 <bc065abb-acc5-ce9a-2b8a-2c114c2542a2@suddenlink.net> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Larry Evans <cppljevans@suddenlink.net>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Ideas for extending std::tuple with field-name
 based access
Date: Wed, 12 Oct 2016 14:21:24 -0500
Lines: 77
Approved: news@gmane.org
Message-ID: <bc065abb-acc5-ce9a-2b8a-2c114c2542a2@suddenlink.net>
References: <CANu6V4VcQQxjb0LvEVjAeNkZ892Gn32cirgVwfjYuAJkkR5EPA@mail.gmail.com>
 <19048c95-770c-4413-b5ff-aa405c389621@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
X-Trace: blaine.gmane.org 1476300111 3548 195.159.176.226 (12 Oct 2016 19:21:51 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 12 Oct 2016 19:21:51 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.3.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDAYTI72VMGRBNM27K7QKGQETAIWDHY@isocpp.org Wed Oct 12 21:21:47 2016
Return-path: <std-proposals+bncBDAYTI72VMGRBNM27K7QKGQETAIWDHY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f71.google.com ([209.85.218.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDAYTI72VMGRBNM27K7QKGQETAIWDHY@isocpp.org>)
	id 1buP5g-0005uh-Et
	for gclcip-std-proposals@m.gmane.org; Wed, 12 Oct 2016 21:21:24 +0200
Original-Received: by mail-oi0-f71.google.com with SMTP id t73sf119452362oie.5
        for <gclcip-std-proposals@m.gmane.org>; Wed, 12 Oct 2016 12:21:26 -0700 (PDT)
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=FxNTh+sS1wcl4VvepNDTHmqvES5kRJI2lrW3PYhWYEI=;
        b=VLYHLypT4VjWrvamsnBfZXNFY0dnk7bftIE7aVAESsLxUNtjR0swkqvF8KUZcAQ2Gf
         KJ8QdG24SYTAduS4y0LfVeyxACvJzjEtW5YZ+LghByU6pOv8JxFHxE2u5KFhvqYlNO5G
         bOEF/YwXZ2BRzPnYEi4MbvXP91S0EzVy2FMYOZxhZ0FlVCpdUSWhdxw1WmU7egOH/Nz8
         7pYuxZO0qPBwzoDC69ducspui7erpfl+9/AJu7o6J0WUTzEhSUc2q5I4/bwOyuCj7/LR
         y7DrOhzh0JVa5J+MoCatn/oKnEuH4K67cxRtNndwEPYIMYeS76yxnkCujl+OJ3f4rOQj
         Nbaw==
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=FxNTh+sS1wcl4VvepNDTHmqvES5kRJI2lrW3PYhWYEI=;
        b=OtNEx5GMycSULlcxLrEn9ubdPcCC6aWP66YD+Lhy2uAMJdEqguMEOVQ4RR0V+TOcph
         c49KUr9Y3E/KuYWoYMUSXM5RVs6NsPiyir0+yUUkL3W2YcNcCtbFBFM6I1pwWe3xiI0G
         79m6vZP8BHhrQt6gttudhV8itCFQ82T4jwsC6VmToeARAaMpDqdAijdZCUVVRKrfLUiK
         S4goKZeUv4yrgxXWN6TfndfkA4GnQffltFmwTR4VJPHlP30aM3rwYej0KQyPMD83kuWO
         ostVkmp+g7xaT0O5mu+fk085E5mBZuIL5+z5JXxcwogH3w6M2eUVrk0iEKmh+cpX+Arc
         mSNQ==
X-Gm-Message-State: AA6/9RkLAYde4PharbdR5wFpX1BohwdFXqb92+HDzcnJNQiDeeAGSWIOZpO212NUanSxmA==
X-Received: by 10.157.58.35 with SMTP id j32mr690369otc.13.1476300086313;
        Wed, 12 Oct 2016 12:21:26 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.170.204 with SMTP id g73ls1615073ioj.2.gmail; Wed, 12 Oct
 2016 12:21:25 -0700 (PDT)
X-Received: by 10.98.57.84 with SMTP id g81mr4029109pfa.115.1476300085439;
        Wed, 12 Oct 2016 12:21:25 -0700 (PDT)
Original-Received: from omta01.suddenlink.net (omta01.suddenlink.net. [208.180.40.71])
        by mx.google.com with ESMTP id n5si7252079pgh.23.2016.10.12.12.21.25
        for <std-proposals@isocpp.org>;
        Wed, 12 Oct 2016 12:21:25 -0700 (PDT)
Received-SPF: pass (google.com: domain of cppljevans@suddenlink.net designates 208.180.40.71 as permitted sender) client-ip=208.180.40.71;
Original-Received: from [192.168.1.2] (really [50.24.16.38])
          by dalofep01.suddenlink.net
          (InterMail vM.8.04.03.22 201-2389-100-167-20150619) with ESMTP
          id <20161012192124.ULNT15195.dalofep01.suddenlink.net@[192.168.1.2]>
          for <std-proposals@isocpp.org>; Wed, 12 Oct 2016 14:21:24 -0500
In-Reply-To: <19048c95-770c-4413-b5ff-aa405c389621@isocpp.org>
X-Cloudmark-Analysis: v=2.2 cv=GYRVpkfL c=1 sm=0 tr=0 a=IkcTkHD0fZMA:10 a=CH0kA5CcgfcA:10 a=yRZ3NqUWEgmhbTA5eQwA:9 a=QEXdDO2ut3YA:10 a=chvjmp5bT-K0Np4W8Gpx:22
X-Original-Sender: cppljevans@suddenlink.net
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of cppljevans@suddenlink.net designates 208.180.40.71 as permitted
 sender) smtp.mailfrom=cppljevans@suddenlink.net
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:28750
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/28750>

On 10/12/2016 08:09 AM, TONGARI J wrote:
> On Wednesday, October 12, 2016 at 7:48:24 PM UTC+8, Johannes Schaub wrote:
>
>     Hello all,
>
>     Using type-tags to access tuple fields is a common technique to access
>     fields by "name"
>
>         struct position_tag : type<double> { };
>         struct color_tag : type<QColor> { };
>
>         my_tuple<field<position_tag, color_tag> m;
>
>         QColor c1 = std::get<color_tag>(m);
>         QColor c2 = std::get<QColor>(m);
>         QColor c3 = std::get<1>(m);
>
>     I was thinking about extending std::tuple with support for tags. This
>     can be done (i believe) most straight forward with string template
>     arguments, if we would have support for them in the future
>
>         std::tuple<field<double, "position">, field<QColor, "color">>
>     getStop();
>
>         auto m = getStop();
>         double pos = std::get<"position">(m);
>
>     An alternative (but uglier) implementation would abuse unnamed struct
>     definitions in template-arguments with the "type" baseclass of above
>     to communicate the type
>
>         std::tuple<struct : typed<double> { type position; },
>                          struct : typed<QColor> { type color; }> getStop();
>
>     Here, "type" is declared in base-class "typed" as a type-alias for its
>     template-parameter. When tuple sees a parameter has "typed<T>" as a
>     base class, it inherits from it. Therefore you could write
>
>         auto m = getStop();
>         QColor c = m.color;
>
>     std::get<N> would cast the unnamed-struct to "struct_type::type",
>     requiring a standard-layout struct (can be tested-for with a
>     type-trait). So the unnamed-struct cannot "escape" to the users of the
>     tuple.
>
>     What do you think about the two approaches? Are there existing papers
>     about perhaps other techniques?
>
>
> I'm not aware of any existing proposal, but some experimental language
> features I'm developing will allow you to do this:
>
> |
> std::tuple<double.position,QColor.color>getStop();
> autom =getStop();
> doublepos =m.position;
> QColorc =m.color;
> |
>
> Let me know if you need more detail.
What about something similar for variant?

   std::variant<double.position,QColor.color>
var_pos_color=std::tuple<double>(1.2);

then:
   assert(var_pos_color.position == 1.2);
   assert(var_pos_color.color == undefined);
   assert(var_pos_color.which == position);

-- 
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/bc065abb-acc5-ce9a-2b8a-2c114c2542a2%40suddenlink.net.

.
