220 37316 <CANiq72kDQVx6yaQQSBQCGvtZGtuYeVsSHNHFSanGXnDd82wa4A@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: Pointer overload for ||
Date: Mon, 12 Mar 2018 12:18:27 +0100
Lines: 55
Approved: news@gmane.org
Message-ID: <CANiq72kDQVx6yaQQSBQCGvtZGtuYeVsSHNHFSanGXnDd82wa4A@mail.gmail.com>
References: <1fea07df-46a6-4df2-865a-849be8f8d129@isocpp.org>
 <CANiq72kL7HQf2oS5THm8bxzurhzoc7uhNQq3S9+zvBce2yMZZQ@mail.gmail.com> <c7cd5d95-0031-4e50-b7a1-9adcff695bd2@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 1520853413 28108 195.159.176.226 (12 Mar 2018 11:16:53 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 12 Mar 2018 11:16:53 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDRZHGH43YJRBHWETHKQKGQESXMOUNA@isocpp.org Mon Mar 12 12:16:49 2018
Return-path: <std-proposals+bncBDRZHGH43YJRBHWETHKQKGQESXMOUNA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f198.google.com ([209.85.220.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDRZHGH43YJRBHWETHKQKGQESXMOUNA@isocpp.org>)
	id 1evLRg-0007B2-EZ
	for gclcip-std-proposals@m.gmane.org; Mon, 12 Mar 2018 12:16:48 +0100
Original-Received: by mail-qk0-f198.google.com with SMTP id x139sf7853359qkb.9
        for <gclcip-std-proposals@m.gmane.org>; Mon, 12 Mar 2018 04:18:55 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1520853534; cv=pass;
        d=google.com; s=arc-20160816;
        b=BGwQRw18M4DHY4Yk5DC0tvHChKllHzXv278I0yVbrl1cTVHflcw6h3cdOQ0em1P6xw
         xkaisMlfX5gdtzuSW4rb2RirvVIHERUkeFEyL9Mko94dw6EABXg9BJ2o/sZpYBP5laRt
         TRDJfrqBmXI5mHSNxXprI8lz7tr8DijhGR7Bhvb72VJjTycbuCaOcb1YufOzNXoq+N4j
         RxnoQQtECwSgcyyK+weBuSDwRInDJ1KupJ1yHNR0deXIS5ujS8UL9Jyi1gg8J5+srztm
         +Xreq1VKJY13QTDMti3N90BG10VeLEGuKnrKcsi2R3W/7Ve2aySJEtXIRy/IX10WnFG8
         7ZEw==
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:to:subject:message-id:date
         :from:references:in-reply-to:mime-version:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=WJgR+9b4RJJNRdo9XQUIvvFZ4Lkfcjik/UB/v/1L6Ws=;
        b=cSWPhdhHbSOkT3WPzpzEgVWwEBMeuFW/K4/193zSK3Om6yDJDl93Ppvu5xmlme7Bkb
         xE4L8Cbxs9mHZWiPj+Wxmf+BNSYlRrZ+b8SN4dmuilFfTiBfFHZHOaFWVQvjZv0EaXcZ
         ZFfVsSa3IxuPKQiDqDYYMAfrvjfh9nM5ntd7kqPdnjjvPK+LY2OxL64t/obd8ITFZ7IZ
         ERjSfOcGeqlw8x0dpCsti/ZjUzX7dXHSn7JH4atOSbwtZFyKD+tnQII3lSSryEdN1x0+
         33mB7nAcjkXjufVJzfvL08rQXn1zlKlxt7yflXCMZ3bMO72kLLQGGfma/mTJREq3pA2j
         45aQ==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=AaWs7mvk;
       spf=pass (google.com: domain of miguel.ojeda.sandonis@gmail.com designates 209.85.220.65 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
         :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=WJgR+9b4RJJNRdo9XQUIvvFZ4Lkfcjik/UB/v/1L6Ws=;
        b=V1DLxTFb4lZpX70Br9647kDKpqy1BwGvWTnN6HdKXvlvQwHfLogVH+zcJNzNC4C9Yz
         tlRsGZRa7QWqWOvzB2moG95Y8eD1PinLLarMQqRlxL4iEs7SKp+kyk5VHapov9XXbU9i
         z/Q45GtPO4XzlWaQALdINhdVCW15xpB3wBDnesEVveOqrXEpdF8K59qd/XblHGfM3xE8
         wdsoqe7JWB0rsKvV9ydgsIKjdjtEMo5Ltvssg0a+kFT2j1Bw4WhV0ODc/a2MukdDfqMK
         U/kG9yf7Nxm5ZSfnWq7J8Q15LzuNwYeTLy93/wsUrR3GkZx+jCCoujsY9P0C321c311h
         G0Zw==
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: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=WJgR+9b4RJJNRdo9XQUIvvFZ4Lkfcjik/UB/v/1L6Ws=;
        b=dWjIbD3IONV6xtkQ/MT2+ONRDfSvpkT9hY23GR/fMZpNord4DUP16Nxf1aQz1ondmv
         GQCz8/nt1T3I5qF9nP5Pzx2FlwmlMamH7cpiNwntAkKLPvlwyPUfaaXPVdvQS5BVrmyH
         UxF93XCwTTcOU62DAJE2HDENjv8fsuidtWGodMS1UogrDakkGtQMrZH3Rl3j5NjniSSr
         1LXynOjeWR8oAmj9s0PVTSOMnEUfhyCE4Y81ygOSAIuuv4WjvQeeBQNPavfBIs09IQ8R
         vL1Wk8cKxvtfs7IhsndVxe99WM5ksaP1Zg71EY7mzIAZSQH1phRUUZqZZym0AIG9TUHe
         SJxA==
X-Gm-Message-State: AElRT7ErsORFBm6tufGGzB1xaXangwvOaS/g+VuUjR5+VdPvaOSLv1o3
	APIM2BU6Y0ZsYC1XePUdW8M95w==
X-Google-Smtp-Source: AG47ELsfYMQmXtIAs0TC9kwXmdXbYjr5Odi+WVme3pWovwjtm2q5y28rxGgNWFkX/JM7LA44lOIL6g==
X-Received: by 10.237.39.219 with SMTP id m27mr3054550qtg.19.1520853534807;
        Mon, 12 Mar 2018 04:18:54 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.200.35.210 with SMTP id r18ls2327245qtr.2.gmail; Mon, 12 Mar
 2018 04:18:54 -0700 (PDT)
X-Received: by 10.237.36.105 with SMTP id s38mr11298065qtc.23.1520853533388;
        Mon, 12 Mar 2018 04:18:53 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1520853533; cv=none;
        d=google.com; s=arc-20160816;
        b=bBtQ4s6HVUO4hTKHv2K07AA4v5Vl8D++N2p4EUjFtbdULtgB7BTMRy6jLmSPvoSWXe
         kp8PkymnP6Fpp/NPhWl7DqmefrXIoPGcQVdIHAL7svLkLc1RZcaVWNUlhWeSsnbL0qLa
         8F4mwa1cRSulrFl0soiAXM8QfpVUuUxpFddqYJznci6ycl/6rnf15V9bpZcPBlAmG2yM
         OGnRf29xHb/etwzOhq+GfsNLrVq95RGXmwmiCdeAZ57TGH82q1rPjTdxvXyBjsnCVU30
         DbQQ3P7oy57gKGdB7iVTRPRlV34pDUVVkkPNsDhZ3Ek+/o1V0Y0/mba3Aoodbs/aX3oN
         jfkQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:references:in-reply-to:mime-version
         :dkim-signature:arc-authentication-results;
        bh=qkp7tqno2rnCJwaB+4zQ3GHosOZ0gmHREN+aW/t/0MM=;
        b=FSw/Bt8LxEns6nmVqo3w1SeLdWMNoaASCkDZc7jBhimWjC1AViDclrEVk7anBrDHXr
         HswWt9b8N8IFV6LmwDQItXeoB6wpie+ZJKRPg508y5jdPJgtOn6HK3uM4kY/DCYI9fDx
         STADwSeFCQJOfGlE/TOOII7RMJ7UPXRWnq12Al8h4IwRUyllGLV6ym2mjNy41cOQLaZk
         Hkv8TMBUNV1WFwrxc6hq12oc+gPjCjYYq+7HyZC+ssPIyYR6X5zKWtXEswNhWoOBRW0W
         B6WkUvq/5Kkkf2AkLywTNnw7DJNUFwZDukcQKc/jhhbB3YUoynaBcACqkjCrNGR00wM5
         rfcA==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=AaWs7mvk;
       spf=pass (google.com: domain of miguel.ojeda.sandonis@gmail.com designates 209.85.220.65 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-f65.google.com (mail-sor-f65.google.com. [209.85.220.65])
        by mx.google.com with SMTPS id q20sor1541211qtq.145.2018.03.12.04.18.53
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Mon, 12 Mar 2018 04:18:53 -0700 (PDT)
Received-SPF: pass (google.com: domain of miguel.ojeda.sandonis@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65;
X-Received: by 10.237.36.167 with SMTP id t36mr2001794qtc.136.1520853527634;
 Mon, 12 Mar 2018 04:18:47 -0700 (PDT)
Original-Received: by 10.200.52.247 with HTTP; Mon, 12 Mar 2018 04:18:27 -0700 (PDT)
In-Reply-To: <c7cd5d95-0031-4e50-b7a1-9adcff695bd2@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=AaWs7mvk;       spf=pass
 (google.com: domain of miguel.ojeda.sandonis@gmail.com designates
 209.85.220.65 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:37316
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37316>

On Mon, Mar 12, 2018 at 1:28 AM,  <inkwizytoryankes@gmail.com> wrote:
>
>
> On Sunday, March 11, 2018 at 7:06:59 PM UTC+1, Miguel Ojeda wrote:
>>
>> Your first version is the best one, to be honest :-) In any case, if
>> you really need something like you propose (a pseudo-DSL, generated
>> code, ...?), then a macro with a descriptive name would be the
>> simplest and most readable, e.g. for your second version:
>>
>>     #define OR_ELSE(v, e) ((v) ? (v) : (e))
>>
>>     // ...
>>     x = OR_ELSE(x, new int);
>>
>> For your third version:
>>
>>     #define ENSURE_INIT(v, e) do { if (not (v)) (v) = (e); } while(false)
>>
>>     // ...
>>     ENSURE_INIT(x, new int);
>>
>
> This solution is not perfect because it reuse `v` multiple times, if value
> is not simply value it could be problematic.
>
> Better would be using lambda similar like in your next point:
>
>
> #define OR_ELSE(v, e) ([&](auto MACRO_OR_ELSE_VALUE_X){ return
> (MACRO_OR_ELSE_VALUE_X ? MACRO_OR_ELSE_VALUE_X : (e)); }(v))
>
>
>
> This will allow evaluate `v` only once and can be inserted in other
> expressions:
>
> auto z = h() ? OR_ELSE(OR_ELSE(x, foo()), bar()) : zz();
>

Indeed! The usual problems (and workarounds) with macros apply --
which is why it would have been great if C++ would have had something
similar to the "expression E" thingy I put above. :-)

Thanks for pointing it out!

Cheers,
Miguel

-- 
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/CANiq72kDQVx6yaQQSBQCGvtZGtuYeVsSHNHFSanGXnDd82wa4A%40mail.gmail.com.

.
