220 37308 <CALvx3hYz84MdBu_WsixPmWf8N=9FY4BiqOv+Lon21nF2m_f0Ow@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Richard Hodges <hodges.r@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Pointer overload for ||
Date: Mon, 12 Mar 2018 08:33:51 +0100
Lines: 360
Approved: news@gmane.org
Message-ID: <CALvx3hYz84MdBu_WsixPmWf8N=9FY4BiqOv+Lon21nF2m_f0Ow@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: multipart/alternative; boundary="f403045fc23cdf5af00567322995"
X-Trace: blaine.gmane.org 1520839912 22324 195.159.176.226 (12 Mar 2018 07:31:52 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 12 Mar 2018 07:31:52 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD4PBM7UWAHRBYO2TDKQKGQEN2HWPGY@isocpp.org Mon Mar 12 08:31:48 2018
Return-path: <std-proposals+bncBD4PBM7UWAHRBYO2TDKQKGQEN2HWPGY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-it0-f70.google.com ([209.85.214.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD4PBM7UWAHRBYO2TDKQKGQEN2HWPGY@isocpp.org>)
	id 1evHvv-0005ge-QX
	for gclcip-std-proposals@m.gmane.org; Mon, 12 Mar 2018 08:31:48 +0100
Original-Received: by mail-it0-f70.google.com with SMTP id m37sf8276666iti.9
        for <gclcip-std-proposals@m.gmane.org>; Mon, 12 Mar 2018 00:33:54 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1520840034; cv=pass;
        d=google.com; s=arc-20160816;
        b=cKBPxA2otUL0w1x8Xgh9wgnLmIXjXqGHuy/G5OktHBgH4GIeDvSwF4eb5ENSybNN/n
         3JGVaxM2e3QyMya5ujm7vegYgEGZ/NVeBaWQSPgV68a8kZpCVgaLPC6IP+WzMYnkujC0
         A0HwKp0tbZh2v91jimTFgDimikbndjUmUgVcG8kdMS20hsAFaR4b9FjfGoyeQP2wtr+S
         B8VeB4vNrxHlxRvMzvuVAsjNs+HvZsYaqd6bvM9zSZ2W8UvTlIqT4fwmaSTQ/+pd9H0T
         VTtvqmSwjrqTjCm/qFXUvmbBDptr5yJIYmA7f4E27Wn+MOHa3utM4FZmDFwvU611Usy6
         Z56A==
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=+Lh+WnlorlHWyGlj79mSGtWczvw4Xq8vPyta/TDR5YI=;
        b=Dwx+DyOifRPc8t7jS4ZTyUCG709J663Gs1lqW2jds02qLATDKDO/Id0yKRXX+Sq5fq
         hgU+W6Xpz8mrJsIY/3HTRiXw41Z+MDdAG8Ka6VN0tPfjvi9KG0J4CEFY13JcSgbwRIVH
         MyAZ6l3dhj0BHl0qVgSpXmj9XBeDVJUQ4JuYj7282vE4SYUNyAc3UV22ETmHdMxghpFi
         actsVbm7/9piK+bNiEwhvHIeTPQNzgFko+VS/c7iIDPEibsv79uYdyZQ7UaqvcpxpQTI
         72LRVn4iMPiUzy1aEHFwRrwBMfFxx7vY/ViQQh2WkUEkroFMSaSMP2IpesXcqqvymJjz
         d5NA==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=PXzerKbG;
       spf=pass (google.com: domain of hodges.r@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hodges.r@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=+Lh+WnlorlHWyGlj79mSGtWczvw4Xq8vPyta/TDR5YI=;
        b=S96zHHqxPZ2f1yRRAJKMih7D5czzE0opjlQEvTXN3VodNGJY1/QzgthQ8tSCcOhBg3
         PEXFAhJbj7o4inJBebN9f5i86lqCkDDIlRxdRV52+ODa/SHQXuBLEsKHccMSPnZrHZdZ
         t6Ov4GokT0HC75EIjSFSmcMamg+5ZYxd4TdMp829aiEU3kmlWnkFlbSVQ+svzpXg31Od
         XJAjlS5EHa4NkjZjnrxX8j8KbvWnhWx1GFnzQc3mgRpZ5cznETDe0YGGnWANxDxTr0U1
         AEF7Cg5ySlgnAIyHtiAWmLDp5zP0XgRdAspoz7ZmnuU7NsLPcyXJ+D+Sxyy3EGLCdtdX
         G7gg==
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=+Lh+WnlorlHWyGlj79mSGtWczvw4Xq8vPyta/TDR5YI=;
        b=d4ydTGFKiiwkgVdtAI3qAdMCVKatJJmpBHyEQSKV3ygv3ASR/fcqzfnKS+HvERmQRk
         cgF6AJ4x7zC/FiWKlJr6DQ5K2zLtEh4EaNZ88yuZ6EjBz2fvYHFTumCMEVWJ44TAubUz
         NoLsop2b8XW1SzKkMSxodXPKJmLgR/FPbcZKTZoXy4nTqgUdshcxDsRTNT4hMCiP4/eZ
         FYDDccfhD0IGqL5/W2OSIhljixQDU3Y0Pnd0irOK6BtXAWiPe6i9gRHwVB0f8Vle9LhH
         y0/UwvHdLHm3VDYC2IN+zrsNaj9jzCRS32L0aTieTpKNJzG27aDRhIHxSwux0Bllw8rq
         xBYA==
X-Gm-Message-State: AElRT7GFlj4XkzbNV7R8gza+kZZsfZCUqfvfDAbQf/TcuYGYF16ubxHk
	ZaFkfmrYXiUgs2u9gRZwa3lIgA==
X-Google-Smtp-Source: AG47ELsOaKPPQA7lTldLVn83kNaaAxznWKbLA+Qm3Gj9vFfa9PpN0Xt8vIj2ZGVSF0boeP4wHNpAPg==
X-Received: by 10.36.208.196 with SMTP id m187mr3766769itg.42.1520840034054;
        Mon, 12 Mar 2018 00:33:54 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.213.2 with SMTP id m2ls487149iog.11.gmail; Mon, 12 Mar
 2018 00:33:52 -0700 (PDT)
X-Received: by 10.107.56.139 with SMTP id f133mr8092492ioa.34.1520840032548;
        Mon, 12 Mar 2018 00:33:52 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1520840032; cv=none;
        d=google.com; s=arc-20160816;
        b=INXC5b6/50D784j2uY0y/O7QQYS+NLAUSuN4gIZV5KzktXlicmO3yI36Ya/3Qt8ZY2
         8dES79tRYG5LBm228k8DeDQGzrxTyXiwEwqKKdsA/RJMbmbz4yfb6fpfRzkKszgTWseK
         KTDlm49P1sJCeoMSmxka8OEH4ziSC5xnOEOXLNPR3aO16rRH32gi77Mi5mDqRv65Fz6I
         T2osAhnX3TkJajYMRW0zCynQXHgB6zNBThpur5MqYOvvYHEVQuu0GlWgHMP8cpOY5b+A
         dpBqNpT/cQS7sokU0lGs4JIJe4TNwfFdpLw3nxYCOjvSHN2CyWd4GDaw/4wVzPm5DgCE
         g2aA==
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=0QSfeAVvLbv8sXhkMyyGgFi3Fw4GTBV9355Vt4r7Hww=;
        b=CwLZHqhEB06dGIXIibFu9BxUS7DozccIqugSjGsAiaK4LSWaxWYYHzRY+aKUACu6P7
         FCSd0Wn32+oQWzS0s+dv4BLve8rgUItmfH/IUEyYbauL7YOHIet3fxFCNuLvv2sGR77t
         OuVcWijgUlOC7RSZoZy1ukeahHKNBv+95PP0QUkq96xAao/Oyr288+7/VE+rhWWs5tPy
         z3epye2SOVdSNlst/UerlWyvc74/Senwv1GDPS8Uoxt62KBZaTz4A+WQoxwBz2Xvgs6a
         WCrjwByKFf4OOafYUhxrznFuSDKsmhEZsxSPyUNGrlzcke0WBzjO1B4CX+oMTXZrlAnl
         lXLA==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=PXzerKbG;
       spf=pass (google.com: domain of hodges.r@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hodges.r@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 67sor2173285ite.142.2018.03.12.00.33.52
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Mon, 12 Mar 2018 00:33:52 -0700 (PDT)
Received-SPF: pass (google.com: domain of hodges.r@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65;
X-Received: by 10.36.240.77 with SMTP id p13mr6635789iti.72.1520840032081;
 Mon, 12 Mar 2018 00:33:52 -0700 (PDT)
Original-Received: by 10.2.102.105 with HTTP; Mon, 12 Mar 2018 00:33:51 -0700 (PDT)
In-Reply-To: <c7cd5d95-0031-4e50-b7a1-9adcff695bd2@isocpp.org>
X-Original-Sender: hodges.r@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=PXzerKbG;       spf=pass
 (google.com: domain of hodges.r@gmail.com designates 209.85.220.65 as
 permitted sender) smtp.mailfrom=hodges.r@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:37308
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37308>

--f403045fc23cdf5af00567322995
Content-Type: text/plain; charset="UTF-8"

I am a little surprised and dismayed at the eagerness to resort to macros.

We can already safely overload operators with a custom generator type. No
need for macros, language extensions or any other magic.

live demonstration: http://coliru.stacked-crooked.com/a/bc751df610a220ce





On 12 March 2018 at 01:28, <inkwizytoryankes@gmail.com> wrote:

>
>
> On Sunday, March 11, 2018 at 7:06:59 PM UTC+1, Miguel Ojeda wrote:
>
>> On Sun, Mar 11, 2018 at 9:38 AM,  <jefferson...@gmail.com> wrote:
>> > Not sure how this will be received -- I haven't posted here much.  Just
>> > thought it would be worth mentioning this idea.
>> >
>> > Suppose you have an API that you want to optionally allocate storage
>> for
>> > your user.  They can either pass in a pointer to some existing
>> allocated
>> > space, or pass in a null pointer and space is allocated for them.
>> >
>> > void foo(int *x) {
>> >   if (x == nullptr) {
>> >     x = new int;
>> >   }
>> >   // etc.
>> > }
>> >
>> > Just figured it would be a decent idea if the || operator received a
>> pointer
>> > overload.  Then you could write the more succinct
>> >
>> > void foo(int *x) {
>> >   x = x || new int;
>> > }
>> >
>> > or even (ducks for cover)
>> >
>> > void foo(int *x) {
>> >   x ||= new int;
>> > }
>>
>> 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();
>
>
>
>
>> If you are really keen on having the operator, you could always
>> approximate like:
>>
>>     #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);
>>
>> Similar for |=; and add something to restrict the overloads as needed.
>>
>> Now, if you want to make a cool proposal:
>>
>>     template <typename T, expression E>
>>     T operator||(T p, E e)
>>     {
>>        if (p)
>>            return p;
>>        return e;
>>     }
>>
>>     // ...
>>     x = x || new int;
>>
>> ;-)
>>
>> 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/c7cd5d95-0031-4e50-
> b7a1-9adcff695bd2%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/c7cd5d95-0031-4e50-b7a1-9adcff695bd2%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CALvx3hYz84MdBu_WsixPmWf8N%3D9FY4BiqOv%2BLon21nF2m_f0Ow%40mail.gmail.com.

--f403045fc23cdf5af00567322995
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I am a little surprised and dismayed at the eagerness to r=
esort to macros.<div><br></div><div>We can already safely overload operator=
s with a custom generator type. No need for macros, language extensions or =
any other magic.</div><div><br></div><div>live demonstration:=C2=A0<a href=
=3D"http://coliru.stacked-crooked.com/a/bc751df610a220ce">http://coliru.sta=
cked-crooked.com/a/bc751df610a220ce</a><br></div><div><br></div><div><br></=
div><div><br></div><div><br></div></div><div class=3D"gmail_extra"><br><div=
 class=3D"gmail_quote">On 12 March 2018 at 01:28,  <span dir=3D"ltr">&lt;<a=
 href=3D"mailto:inkwizytoryankes@gmail.com" target=3D"_blank">inkwizytoryan=
kes@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"ltr"><br><br>On Sunday, March 11, 2018 at 7:06:59 PM UTC+1, Miguel O=
jeda wrote:<div><div class=3D"h5"><blockquote class=3D"gmail_quote" style=
=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"=
>On Sun, Mar 11, 2018 at 9:38 AM, =C2=A0&lt;<a rel=3D"nofollow">jefferson..=
..@gmail.com</a>&gt; wrote:
<br>&gt; Not sure how this will be received -- I haven&#39;t posted here mu=
ch.=C2=A0 Just
<br>&gt; thought it would be worth mentioning this idea.
<br>&gt;
<br>&gt; Suppose you have an API that you want to optionally allocate stora=
ge for
<br>&gt; your user.=C2=A0 They can either pass in a pointer to some existin=
g allocated
<br>&gt; space, or pass in a null pointer and space is allocated for them.
<br>&gt;
<br>&gt; void foo(int *x) {
<br>&gt; =C2=A0 if (x =3D=3D nullptr) {
<br>&gt; =C2=A0 =C2=A0 x =3D new int;
<br>&gt; =C2=A0 }
<br>&gt; =C2=A0 // etc.
<br>&gt; }
<br>&gt;
<br>&gt; Just figured it would be a decent idea if the || operator received=
 a pointer
<br>&gt; overload.=C2=A0 Then you could write the more succinct
<br>&gt;
<br>&gt; void foo(int *x) {
<br>&gt; =C2=A0 x =3D x || new int;
<br>&gt; }
<br>&gt;
<br>&gt; or even (ducks for cover)
<br>&gt;
<br>&gt; void foo(int *x) {
<br>&gt; =C2=A0 x ||=3D new int;
<br>&gt; }
<br>
<br>Your first version is the best one, to be honest :-) In any case, if
<br>you really need something like you propose (a pseudo-DSL, generated
<br>code, ...?), then a macro with a descriptive name would be the
<br>simplest and most readable, e.g. for your second version:
<br>
<br>=C2=A0 =C2=A0 #define OR_ELSE(v, e) ((v) ? (v) : (e))
<br>
<br>=C2=A0 =C2=A0 // ...
<br>=C2=A0 =C2=A0 x =3D OR_ELSE(x, new int);
<br>
<br>For your third version:
<br>
<br>=C2=A0 =C2=A0 #define ENSURE_INIT(v, e) do { if (not (v)) (v) =3D (e); =
} while(false)
<br>
<br>=C2=A0 =C2=A0 // ...
<br>=C2=A0 =C2=A0 ENSURE_INIT(x, new int);
<br>
<br></blockquote></div></div><div><br>This solution is not perfect because =
it reuse `v` multiple times, if value is not simply value it could be probl=
ematic.<br><br>Better would be using lambda similar like in your next point=
:<br><br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(1=
87,187,187);border-style:solid;border-width:1px" class=3D"m_867575031714103=
5639prettyprint"><code class=3D"m_8675750317141035639prettyprint"><div clas=
s=3D"m_8675750317141035639subprettyprint"><span style=3D"color:#000" class=
=3D"m_8675750317141035639styled-by-prettify"><br></span><span style=3D"colo=
r:#800" class=3D"m_8675750317141035639styled-by-prettify">#define</span><sp=
an style=3D"color:#000" class=3D"m_8675750317141035639styled-by-prettify"> =
OR_ELSE</span><span style=3D"color:#660" class=3D"m_8675750317141035639styl=
ed-by-prettify">(</span><span style=3D"color:#000" class=3D"m_8675750317141=
035639styled-by-prettify">v</span><span style=3D"color:#660" class=3D"m_867=
5750317141035639styled-by-prettify">,</span><span style=3D"color:#000" clas=
s=3D"m_8675750317141035639styled-by-prettify"> e</span><span style=3D"color=
:#660" class=3D"m_8675750317141035639styled-by-prettify">)</span><span styl=
e=3D"color:#000" class=3D"m_8675750317141035639styled-by-prettify"> </span>=
<span style=3D"color:#660" class=3D"m_8675750317141035639styled-by-prettify=
">([&amp;](</span><span style=3D"color:#008" class=3D"m_8675750317141035639=
styled-by-prettify">auto</span><span style=3D"color:#000" class=3D"m_867575=
0317141035639styled-by-prettify"> MACRO_OR_ELSE_VALUE_X</span><span style=
=3D"color:#660" class=3D"m_8675750317141035639styled-by-prettify">){</span>=
<span style=3D"color:#000" class=3D"m_8675750317141035639styled-by-prettify=
"> </span><span style=3D"color:#008" class=3D"m_8675750317141035639styled-b=
y-prettify">return</span><span style=3D"color:#000" class=3D"m_867575031714=
1035639styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_86=
75750317141035639styled-by-prettify">(</span><span style=3D"color:#000" cla=
ss=3D"m_8675750317141035639styled-by-prettify">MACRO_OR_ELSE_VALUE_X </span=
><span style=3D"color:#660" class=3D"m_8675750317141035639styled-by-prettif=
y">?</span><span style=3D"color:#000" class=3D"m_8675750317141035639styled-=
by-prettify"> MACRO_OR_ELSE_VALUE_X </span><span style=3D"color:#660" class=
=3D"m_8675750317141035639styled-by-prettify">:</span><span style=3D"color:#=
000" class=3D"m_8675750317141035639styled-by-prettify"> </span><span style=
=3D"color:#660" class=3D"m_8675750317141035639styled-by-prettify">(</span><=
span style=3D"color:#000" class=3D"m_8675750317141035639styled-by-prettify"=
>e</span><span style=3D"color:#660" class=3D"m_8675750317141035639styled-by=
-prettify">));</span><span style=3D"color:#000" class=3D"m_8675750317141035=
639styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_867575=
0317141035639styled-by-prettify">}(</span><span style=3D"color:#000" class=
=3D"m_8675750317141035639styled-by-prettify">v</span><span style=3D"color:#=
660" class=3D"m_8675750317141035639styled-by-prettify">))</span><span style=
=3D"color:#000" class=3D"m_8675750317141035639styled-by-prettify"><br><br><=
/span></div></code></div><br><br>This will allow evaluate `v` only once and=
 can be inserted in other expressions:<br><br><div style=3D"background-colo=
r:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-=
width:1px" class=3D"m_8675750317141035639prettyprint"><code class=3D"m_8675=
750317141035639prettyprint"><div class=3D"m_8675750317141035639subprettypri=
nt"><span style=3D"color:#008" class=3D"m_8675750317141035639styled-by-pret=
tify">auto</span><span style=3D"color:#000" class=3D"m_8675750317141035639s=
tyled-by-prettify"> z </span><span style=3D"color:#660" class=3D"m_86757503=
17141035639styled-by-prettify">=3D</span><span style=3D"color:#000" class=
=3D"m_8675750317141035639styled-by-prettify"> h</span><span style=3D"color:=
#660" class=3D"m_8675750317141035639styled-by-prettify">()</span><span styl=
e=3D"color:#000" class=3D"m_8675750317141035639styled-by-prettify"> </span>=
<span style=3D"color:#660" class=3D"m_8675750317141035639styled-by-prettify=
">?</span><span style=3D"color:#000" class=3D"m_8675750317141035639styled-b=
y-prettify"> OR_ELSE</span><span style=3D"color:#660" class=3D"m_8675750317=
141035639styled-by-prettify">(</span><span style=3D"color:#000" class=3D"m_=
8675750317141035639styled-by-prettify">OR_ELSE</span><span style=3D"color:#=
660" class=3D"m_8675750317141035639styled-by-prettify">(</span><span style=
=3D"color:#000" class=3D"m_8675750317141035639styled-by-prettify">x</span><=
span style=3D"color:#660" class=3D"m_8675750317141035639styled-by-prettify"=
>,</span><span style=3D"color:#000" class=3D"m_8675750317141035639styled-by=
-prettify"> foo</span><span style=3D"color:#660" class=3D"m_867575031714103=
5639styled-by-prettify">()),</span><span style=3D"color:#000" class=3D"m_86=
75750317141035639styled-by-prettify"> bar</span><span style=3D"color:#660" =
class=3D"m_8675750317141035639styled-by-prettify">())</span><span style=3D"=
color:#000" class=3D"m_8675750317141035639styled-by-prettify"> </span><span=
 style=3D"color:#660" class=3D"m_8675750317141035639styled-by-prettify">:</=
span><span style=3D"color:#000" class=3D"m_8675750317141035639styled-by-pre=
ttify"> zz</span><span style=3D"color:#660" class=3D"m_8675750317141035639s=
tyled-by-prettify">();</span><span style=3D"color:#000" class=3D"m_86757503=
17141035639styled-by-prettify"><br></span></div></code></div><br><br>=C2=A0=
</div><div><div class=3D"h5"><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">If you=
 are really keen on having the operator, you could always
<br>approximate like:
<br>
<br>=C2=A0 =C2=A0 #define LAZY(x) [](){ return (x); }
<br>
<br>=C2=A0 =C2=A0 template &lt;typename T, typename E&gt;
<br>=C2=A0 =C2=A0 T operator||(T p, E e)
<br>=C2=A0 =C2=A0 {
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0if (p)
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return p;
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0return e();
<br>=C2=A0 =C2=A0 }
<br>
<br>=C2=A0 =C2=A0 // ...
<br>=C2=A0 =C2=A0 x =3D x || LAZY(new int);
<br>
<br>Similar for |=3D; and add something to restrict the overloads as needed=
..
<br>
<br>Now, if you want to make a cool proposal:
<br>
<br>=C2=A0 =C2=A0 template &lt;typename T, expression E&gt;
<br>=C2=A0 =C2=A0 T operator||(T p, E e)
<br>=C2=A0 =C2=A0 {
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0if (p)
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return p;
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0return e;
<br>=C2=A0 =C2=A0 }
<br>
<br>=C2=A0 =C2=A0 // ...
<br>=C2=A0 =C2=A0 x =3D x || new int;
<br>
<br>;-)
<br>
<br>Cheers,
<br>Miguel
<br></blockquote></div></div></div><div><div class=3D"h5">

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></div></div>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/c7cd5d95-0031-4e50-b7a1-9adcff695bd2%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/c7cd=
5d95-0031-4e50-<wbr>b7a1-9adcff695bd2%40isocpp.org</a><wbr>.<br>
</blockquote></div><br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CALvx3hYz84MdBu_WsixPmWf8N%3D9FY4BiqO=
v%2BLon21nF2m_f0Ow%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hYz84Md=
Bu_WsixPmWf8N%3D9FY4BiqOv%2BLon21nF2m_f0Ow%40mail.gmail.com</a>.<br />

--f403045fc23cdf5af00567322995--

.
