220 40141 <CANiq72k7K+U2Gtjhe8rFk5TjdW8aQLyDO0Qw4pop3G1ftJ-OAQ@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Parametric Expression
Date: Wed, 12 Sep 2018 18:26:16 +0200
Lines: 107
Approved: news@gmane.org
Message-ID: <CANiq72k7K+U2Gtjhe8rFk5TjdW8aQLyDO0Qw4pop3G1ftJ-OAQ@mail.gmail.com>
References: <95ae303b-329c-4121-aa5f-69edf040d5b5@isocpp.org>
 <CAOfiQqknXM3=8x4wmGGboSYh=tuMfrUU2MuxVM0XtEur95LhgA@mail.gmail.com>
 <80215dcb-875f-42c0-8f7f-e8030c2145e7@isocpp.org> <ab3a09d5-6c45-43d1-9666-9749dbf7051c@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"
X-Trace: blaine.gmane.org 1536769476 28520 195.159.176.226 (12 Sep 2018 16:24:36 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 12 Sep 2018 16:24:36 +0000 (UTC)
Cc: swac31@gmail.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDRZHGH43YJRBP744TOAKGQEU5AWQ7A@isocpp.org Wed Sep 12 18:24:31 2018
Return-path: <std-proposals+bncBDRZHGH43YJRBP744TOAKGQEU5AWQ7A@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qt0-f197.google.com ([209.85.216.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDRZHGH43YJRBP744TOAKGQEU5AWQ7A@isocpp.org>)
	id 1g07wM-0007HW-P5
	for gclcip-std-proposals@m.gmane.org; Wed, 12 Sep 2018 18:24:30 +0200
Original-Received: by mail-qt0-f197.google.com with SMTP id z44-v6sf2064631qtg.5
        for <gclcip-std-proposals@m.gmane.org>; Wed, 12 Sep 2018 09:26:41 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1536769600; cv=pass;
        d=google.com; s=arc-20160816;
        b=brxSaWGY5rAamEhnOwim42n0Pp9B9qzPNXOocRoolhLReClUHekvGXNwpfxZuqsEbO
         ul9PdylIMMquI6Ac2qTag+tGna1LQjf/viDyn8d97J6LA0qfd2PuPCKtehVTFMRKeI8D
         ZQeZ05VZ0BqOAaF522M5O8HgQfQfRlLyy0gvvd6Ajx+Co0ssDRT2czkPnbvf6CG08g6Y
         xaq9ErAEVNSzgq5Q+v0TeFHqIjTpeS2NZe+9eKWiAz7GhQ07mnCb5LxVFTztxOUpwd/1
         qcEXfZ5M3YyrP6J8bkhjtTEAbW3fapy9DogV5L9kZ3qXQlUd2yb061+NU5qMybrYnSJx
         ZznQ==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:cc:to:subject:message-id
         :date:from:references:in-reply-to:mime-version:dkim-signature;
        bh=XOtqBEJFDU/DytAh78ymWpI8V+eHP5waH22nAgOIjCU=;
        b=DEBCkFnKIwC4esizzNOJzUSeDCR6pOV4NG1OM0DO5J5UF7IHnzMphhGkRi2JQi68jI
         8/d5O/x1hRKywJkmi1EU/CLXSO/TEN77ZcSRBUjO1lr2BVUnneL8/37x6l1nxTLjVDOo
         tQL33L1yFEgUyXvQaTVJPBegOXZU0r5EKT9M/Z3RhuF0V86tOxHPN8HuwmVay3rKLwOO
         faLSlykeCgLiFsoYwLyGWX1ncad4G4UiVXtUJaxH0Jw0zERWNnJGorhxqwp8ZwRVggvg
         0ISdSCpei/ULaK4qGiBRTnX1kK3MJVACfuaLnxukdDvB4TKuIMmQH9YIQuw+DMhqXY24
         UD5Q==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=cX1gevwJ;
       spf=pass (google.com: domain of miguel.ojeda.sandonis@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=miguel.ojeda.sandonis@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :cc:x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=XOtqBEJFDU/DytAh78ymWpI8V+eHP5waH22nAgOIjCU=;
        b=Wazra/L9RMGAoccEdIYvSMgFVMtUHkRq8l44x7ycdjqlvUpJyZ5klJ6JxlUq7MCiqN
         rTbyyKEid+A1O2HwINiECCp/Jblygl5S/uxbDpDHzdCfTnNfpiW2HduBHe9tiVC079f/
         vRixK9tP5aJ+BvkQoUKJiMP5u9yj3cBShrOBEIpyv83Za86nz2wQ5RQtkjFPtZ9xcQXw
         9PabHa7gTmUaaB1s5q+u6GpS68367g8+M4N5GDCwvDpJ0+RncqTZnxWd6XvCFhA+2dtm
         66D+YJSsKtv8Q1WQkLaL7oSpJ4kLr+7l/nxtUSQRsYp0CAcmFLRpHN2aXfKHM0xBjU1D
         cWAg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:cc: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=XOtqBEJFDU/DytAh78ymWpI8V+eHP5waH22nAgOIjCU=;
        b=BnUYIgD348iBfGwT1y65ydAaKAKYq53I9Gk0yNN7dMWPPgNJ+ygaNPIshZ/2uHNFDB
         EDjZqM60RneQWGY2zs7qLN39lACoa3cIPAuGqUHQ5ThUNPPaPV+UEhF/zKOBi8e5K7xA
         p12SqOnLTjC7eb9ycP1LPkRaIUwVWgOQckF78a4yAJRWX+ETRcf8ZluB9jPW1/5XAT+r
         hgSzE4vQdUP6US6xcXysGgaIklYf30/GHvB1a3tA4HVBq8lisf57jxnrd5mZgwMMROFX
         tFZl+5o+OaQioKUHVRg+K+DxPmhh37micODtIix1dF+PbqPEk1BGylAW+wudNHM9Lhcu
         Njnw==
X-Gm-Message-State: APzg51C3iYD27G6AtcZY8qxgyWkGnEb1wEbXdq1lnYoIVk0QcubXANZn
	UO8LQ5RsSSLUegRvZB9UOGqtvA==
X-Google-Smtp-Source: ANB0VdZhKHr7WfkyH9jPwuylQEvbvRcHXLsq9GjaD8YdG+WVDzB6tkoLOEhu9m/owE6wL7WCV7MYrA==
X-Received: by 2002:aed:2452:: with SMTP id s18-v6mr856591qtc.20.1536769600634;
        Wed, 12 Sep 2018 09:26:40 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:aed:243c:: with SMTP id r57-v6ls841529qtc.7.gmail; Wed, 12
 Sep 2018 09:26:39 -0700 (PDT)
X-Received: by 2002:ac8:72d4:: with SMTP id o20-v6mr2151284qtp.126.1536769599719;
        Wed, 12 Sep 2018 09:26:39 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1536769599; cv=none;
        d=google.com; s=arc-20160816;
        b=uZGrEpa6Vq1jurFaNK6to7BFYmraMIhwuJd8hEcmhncIaQ42mk2ZfA4VIIvb1wIB5Q
         ACUqDtUwb8HmmLpf+y6IfBN/Nz2iVM/uWMfiTx58PjRSScL43A6St+F5ezL53cPRQF2D
         uRdrXlorap00i48TysGRgmEYsn388a9V9Rz9r7dz078ZbJivo23O9ctRpATPV+1qv/v/
         JtEaWF0PBR0D/hLjiHwLcEgTWEk1UXbo9dpaxIwatMp3vazj/iDZeY1kQBaqsAe6kATF
         Q2N6t7mgdsIUPtifISTeJZUMZpNOI16oGdhWo7NoOY+C1j/8+AbXo81HL0KKUVBVPhFj
         G+3g==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=cc:to:subject:message-id:date:from:references:in-reply-to
         :mime-version:dkim-signature;
        bh=SDdziaGWYh0ons2GW0lQGvZgx3HyPJfVOsvd+sOze5o=;
        b=jxt8oByxWlTt/YvMyKhRtT8vMuMhcLNlKOz+LUVAU+p3h2dDPE8zkXKvhqC/gn59g/
         O4mxpo0OlOMUja2YujGKQCr++9xw6Q7WXRkSFvYAkHppBXMe5UYujeS9lQyS9H0AaDUF
         dHJXjw2Fhymx1jz67vN2WdnQKRH7qZEPFEIiuULEPFFhe69jHviQfo6+x9fu5RxfgkKu
         jXGw0eQFtdBp+0yMrCzu5LiokNLQXP/Ivx5MpozdCz0wpf4d270JSm22YsCDF2Y1VpW5
         Vr7xN2Myyj11G2d93HD73gK5iLxP1xrtDT/0xSDo1Mwqv52bWVd5/WC52beb4rrUpZrw
         dnHg==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=cX1gevwJ;
       spf=pass (google.com: domain of miguel.ojeda.sandonis@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=miguel.ojeda.sandonis@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id g58-v6sor512204qtb.110.2018.09.12.09.26.39
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Wed, 12 Sep 2018 09:26:39 -0700 (PDT)
Received-SPF: pass (google.com: domain of miguel.ojeda.sandonis@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 2002:aed:3fd3:: with SMTP id w19-v6mr2135891qth.226.1536769597866;
 Wed, 12 Sep 2018 09:26:37 -0700 (PDT)
Original-Received: by 2002:ac8:7494:0:0:0:0:0 with HTTP; Wed, 12 Sep 2018 09:26:16
 -0700 (PDT)
In-Reply-To: <ab3a09d5-6c45-43d1-9666-9749dbf7051c@isocpp.org>
X-Original-Sender: miguel.ojeda.sandonis@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=cX1gevwJ;       spf=pass
 (google.com: domain of miguel.ojeda.sandonis@gmail.com designates
 209.85.220.41 as permitted sender) smtp.mailfrom=miguel.ojeda.sandonis@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE 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-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:40141
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40141>

Hi Jason,

On Mon, Sep 10, 2018 at 10:13 PM, Jason Rice <ricejasonf@gmail.com> wrote:
> The feedback on this so far has been greatly appreciated.
>
> I added a couple of examples and refactored the rules to address some of the
> concerns that were brought up.
>
> https://gist.github.com/ricejasonf/84c11ac6bb093c1ea8c380a9a466d8cb


We had a quick discussion a few months ago [1] on how to implement
something that would allow you to write things like:

    x = x || new int;

In other words, an operator|| with short-circuit semantics. There were
suggestions on changing the language (the topic starter), on
standardizing language extensions (the binary ?: GNU operator) and on
doing some tricks with a macro and a lambda, e.g:

    #define LAZY(x) [](){ return (x); }

    template <typename T, typename E>
    T operator||(T p, E e)
    {
        if (p)
            return p;
        return e();
    }

    x = x || LAZY(new int);

Half-jokingly, I suggested working with expressions instead would look
very nice and would allow to implement these things directly in the
language, e.g.:

    template <typename T, expression E>
    T operator||(T p, E e)
    {
        if (p)
            return p;
        return e;
    }

    x = x || new int;

How would your add() example look using this "expression" syntax?
Maybe something like:

    template <typename T, expression E>
    E add(T a, T b)
    {
        return a + b;
    }

Now, the other way around, let's take a look at the operator||()
example using your "using" syntax:

    using operator||(auto p, ???) {
        if (p)
            return p;
        return ???;
    }

Almost there! I am sure you are seeing what I am getting at here. If
we are going to get almost-macro-like entities, we are basically
talking about manipulating (or rather, being able to express)
expressions. Your approach, if I interpreted it correctly, allows to
return a C++ expression given a function-like call, but does not allow
to pick expressions themselves as parameters --- which would allow to
implement things like those short-circuit operators and replace even
more macros.

We could implement operators already existing in the language in terms
of the language itself:

    using myOwnTernary(auto c, expression t, expression f) {
        if (c)
            return t;
        return f;
    }

    // foo() only called if the condition is true
    int x = myOwnTernary(something, 1, foo());

Inexpensive logging is another place where it is useful (to avoid
evaluating parameters, e.g. Boost's LOG_WARNING):

    using logWarning(expression... es) {
        if (level >= warning)
            doLog(es...);
    }

Think about it!

Cheers,
Miguel

[1] https://groups.google.com/a/isocpp.org/d/msg/std-proposals/jB5TIcRZeic/qZqxtxSDAQAJ

-- 
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/CANiq72k7K%2BU2Gtjhe8rFk5TjdW8aQLyDO0Qw4pop3G1ftJ-OAQ%40mail.gmail.com.

.
