220 37289 <f2c867ca-f34f-e3ad-1f3e-b8aabc8e13b0@gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Jefferson Carpenter <jeffersoncarpenter2@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Pointer overload for ||
Date: Sun, 11 Mar 2018 04:01:41 -0500
Lines: 107
Approved: news@gmane.org
Message-ID: <f2c867ca-f34f-e3ad-1f3e-b8aabc8e13b0@gmail.com>
References: <1fea07df-46a6-4df2-865a-849be8f8d129@isocpp.org>
 <CAANG=kVsGNaXGZLtbNm=9cJxjLXwu0cgL=p_kYa1TCRSKfNCvg@mail.gmail.com>
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
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1520758785 15475 195.159.176.226 (11 Mar 2018 08:59:45 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 11 Mar 2018 08:59:45 +0000 (UTC)
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:52.0) Gecko/20100101
 Thunderbird/52.6.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDMNDCNA64OBB6XASPKQKGQEJHIHHOA@isocpp.org Sun Mar 11 09:59:41 2018
Return-path: <std-proposals+bncBDMNDCNA64OBB6XASPKQKGQEJHIHHOA@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+bncBDMNDCNA64OBB6XASPKQKGQEJHIHHOA@isocpp.org>)
	id 1euwpR-0003uo-6s
	for gclcip-std-proposals@m.gmane.org; Sun, 11 Mar 2018 09:59:41 +0100
Original-Received: by mail-it0-f70.google.com with SMTP id a79-v6sf6516366itc.3
        for <gclcip-std-proposals@m.gmane.org>; Sun, 11 Mar 2018 01:01:48 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1520758907; cv=pass;
        d=google.com; s=arc-20160816;
        b=Ix1hM8sFLAzANdhpRqWZpBAa9urh9hQCBbjcar4afG6v3RZDTOTT/c+YbevJapc3YV
         bmrgVjVEYkolVyUDwScGFghw/XUa9rSHkc1EfIOuBFT0jzUzla0gIutmMhAhkBFhQ6NG
         3XdXyLwL8eTlF2wICkHxyVZoFpiJ1lEV97xD1qMVAm1AqCsneLDQ0zVD383H8eph1jGK
         5bLt3B4Xh78I7UzN96lsCKk/+fWXZyBZWkMJYfoWRYiTfI+KYLmtMCKovZ9qr0MlvTUf
         2SNjzGGSrXo6Cn4GJV19MXTMQYKX0usdCIZ+55ekaX1qw+e9gB4GPdM6tx8i9rAFchse
         Su1A==
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:content-transfer-encoding
         :content-language:in-reply-to:mime-version:user-agent:date
         :message-id:from:references:to:subject:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=YciLVzNUenn3zwqEGzg+IZZCn5h5lqFbeDfceoTka0c=;
        b=rG6vVQqRiipQWmuuYsQCGlJEHxMkDd37BgyYqMXBgIaSkXfyxREfn1wQfE3daSKO59
         TIZ0qmbFIk5HjkO4HAeT40HtDptjCsOpiBoZexpUQfhPu6f67qhWZ98WHafuwK6hRoMK
         /lWGmZhao3XiKWP6xCrt16jwC1mOdrGaBJJNPMi1Jo/XAtksigAMFSiM6Nem4Q8jicic
         b3kM8aCElz3Hh9YS2lQAtZkt/rm0REntPrITjFgAwlh9aQyCDlj++lBVSUWEX8Eh3mJ+
         AJwc8a7giqc3L/Hdg5WalLheL5RTA5/OEnDhlzE0lL1Nb3g+FRGk01iTwQ/SYe 
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=Duqp7hFQ;
       spf=pass (google.com: domain of jeffersoncarpenter2@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jeffersoncarpenter2@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=subject:to:references:from:message-id:date:user-agent:mime-version
         :in-reply-to:content-language:content-transfer-encoding
         :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=YciLVzNUenn3zwqEGzg+IZZCn5h5lqFbeDfceoTka0c=;
        b=JAzR4mB5QKSTuTW8h1MEc2grR0GbVreRITCYKndgJ45/ie2/3oRML+Zz/VaNP6KTgR
         4dLCI2Vw95GVOuu5vQA5AkatDrm42pNOEE9Vpyv4ulsC5j7NWtOSvj6OA51PTAeh/6jI
         80vuYPYWkL00lJWMfDX1Avo+Z+KLC68zALHK8pWZvfkrS3O5l9H6haO50QPep5FwGMDb
         O1N1hJ1q6DRiHssYHf7TxYDXq6YKWwhyEL6cwSwE2mRPOP6k3+jNtjn3dv3FEHUCtMMM
         hMUQYwsa5EbQp855U44LtjHzD5yKmbk19mAsnulBAwgF7FqjecdcvrO9wOVBRtLFxwkt
         Yxb 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-language
         :content-transfer-encoding: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=YciLVzNUenn3zwqEGzg+IZZCn5h5lqFbeDfceoTka0c=;
        b=BNeApDH2RbJvBzGlhEMvU947wIOgMFYzyP8wI/FEOfYezmSE46wHg/GB8MsjPMlsGh
         fmvxQ3KRWS8+k85OVmODMsBXRVHB0ZfgztCnF3foFwZ6Q0XNfubqmCQ3C1eSihXYHxuQ
         rZbiIpp+zviHIChppCzrP2XxNgagRe3EBAUB68WHA+6Y8/+OffHmFkt6Q6hxthegfhn4
         bYdniKmSUzZCglLyLWo3iAV5DX8cRrp5HPNm47EOubnVvDxpKQKnGYypzvAxRr+PaNpG
         WDr28ft6mU2irsXoeffZ5KE3VYYPztdplPr3Z70GTyO 
X-Gm-Message-State: AElRT7G2Nq+7GUM8xvevbQaDgqFMEpaGGru1SYnidFvC+oM02dk0hSIN
	4T40Mk47JXXRRbm/A0PlnRWu3w==
X-Google-Smtp-Source: AG47ELsYn8xySSE6AWeBKqRhjQSIuk3/ftLvzlyOAT+gCdxxb9e6ChysGsolOKEW1KSiK3/PCxUXFA==
X-Received: by 10.107.6.12 with SMTP id 12mr416995iog.111.1520758907673;
        Sun, 11 Mar 2018 01:01:47 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.11.223 with SMTP id 92ls2303509iol.14.gmail; Sun, 11 Mar
 2018 01:01:46 -0800 (PST)
X-Received: by 10.107.16.65 with SMTP id y62mr1116262ioi.213.1520758906583;
        Sun, 11 Mar 2018 01:01:46 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1520758906; cv=none;
        d=google.com; s=arc-20160816;
        b=jAffNL5xnp+L7n5B7FH7OKYSnPY2nJ2iIXszS02mYIimVLAJYE2Q6lSZwwU+c+8ghT
         9E2v3K1BMHP/TKF0W/D1y0mrA2wgsRS4l97yipj8CFwEh5RM6R/LKXFnUqsIgT+/ktaW
         HTekS4Imm684MPYxmMhcfTSePFSwkCq8RL9zbZCdIT+LGVKc7kmAjDGN3qe4aqLzuxzq
         9fYBcB35v7NgM8p6tQ43/RHO6wHSssG3OVxvACOxeVr+sILfSroRdlX4VeUlUDRDS6iY
         NdDPOtT7gOBsK4h1nD5mgAW0uPIVtdlIw9tuKCqEhiKdj49ORhqIPEwN5SuYI+PeFVOC
         lv5A==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:content-language:in-reply-to:mime-version
         :user-agent:date:message-id:from:references:to:subject
         :dkim-signature:arc-authentication-results;
        bh=vZ7QreQ7zx7ltr9iiZCY9DnMfQeHqvt87S+MffhynPg=;
        b=pdrPh4/XigK7LPsVXOXlGO7T2lf+xG0f/lEL9ZH+TT1Ak3xI8PJNJg9Qeam2P4Uec0
         IgWVKacuCef99Hgiw31CmLfhtiIAkRQDNJCmlPDZVZu6DkGg+MRpXbGyPu5tfkCfCYeF
         7Mo1d2l5NDxWkSeQiFRDGB2f6IcPyBUFAa3wkj3LUNBZs1IzPDke8NOcUHCabwR5/jP+
         v1WJfG/rgCLta6VqacYsdXIPGXrN2q/TinKcA3xBBMf/GwgTt/Yv+UDHYWBvaMpzlcQn
         /vffoS/o5kzUUJWHlwiyG6+Q+46URYLisc6ICkYtXzw7UbGfASsozG/Ri4GQ/415yrif
         xiqQ==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=Duqp7hFQ;
       spf=pass (google.com: domain of jeffersoncarpenter2@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jeffersoncarpenter2@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 v64sor1305012itg.18.2018.03.11.01.01.46
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Sun, 11 Mar 2018 01:01:46 -0800 (PST)
Received-SPF: pass (google.com: domain of jeffersoncarpenter2@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 10.36.172.93 with SMTP id m29mr4057895iti.133.1520758905844;
        Sun, 11 Mar 2018 01:01:45 -0800 (PST)
Original-Received: from ?IPv6:2601:441:8680:4631:ecd0:a4aa:6a04:1146? ([2601:441:8680:4631:ecd0:a4aa:6a04:1146])
        by smtp.gmail.com with ESMTPSA id 30sm3290224iop.73.2018.03.11.01.01.44
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 11 Mar 2018 01:01:44 -0800 (PST)
In-Reply-To: <CAANG=kVsGNaXGZLtbNm=9cJxjLXwu0cgL=p_kYa1TCRSKfNCvg@mail.gmail.com>
Content-Language: en-US
X-Original-Sender: jeffersonCarpenter2@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=Duqp7hFQ;       spf=pass
 (google.com: domain of jeffersoncarpenter2@gmail.com designates 209.85.220.41
 as permitted sender) smtp.mailfrom=jeffersoncarpenter2@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:37289
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/37289>

Indeed, that's very nice.

On 3/11/2018 3:58 AM, Ga=C5=A1per A=C5=BEman wrote:
> There is a binary form of the conditional operator that is a gnu extensio=
n:
>=20
> void foo(int *x) {
>    x =3D x?:new int;
> }
>=20
> It's defined as
>=20
> CEXPR ?: FEXPR;
>=20
> and rewritten into
>=20
> {
>     auto&& x =3D CEXPR;
>     if (x) { return x; } else { return FEXPR; }
> }
>=20
> Perhaps you could propose that instead, as it's far more general. It's a
> GNU extension because certain macros (assert comes to mind) are much easi=
er
> to implement if you have it.
>=20
> G
>=20
>=20
>=20
>=20
> On Sun, Mar 11, 2018, 08:38 <jeffersoncarpenter2@gmail.com> wrote:
>=20
>> 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 =3D=3D nullptr) {
>>      x =3D 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 =3D x || new int;
>> }
>>
>> or even (ducks for cover)
>>
>> void foo(int *x) {
>>    x ||=3D new int;
>> }
>>
>> would be nice.
>>
>> Currently, if I am not mistaken, || (excluding user-defined overloads) i=
s
>> a boolean-only operator.  It is indeed the case that nullptr is the only
>> value that becomes false when cast to a boolean, and all other pointer
>> values become true.  So I don't see how adding an || overload for pointe=
rs
>> would break any existing code.
>>
>> The main thing that would make this a no-go would be if the semantics of
>> || required that both operands be evaluated -- whether or not the left-h=
and
>> one is false.  Then the whole point as I see it would be lost - the abov=
e
>> examples would merely leak memory.
>>
>> - Jefferson Carpenter
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> 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/1fea07df-46a6-4df2-
>> 865a-849be8f8d129%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1fea07df-4=
6a6-4df2-865a-849be8f8d129%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>=20

--=20
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 e=
mail 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/f2c867ca-f34f-e3ad-1f3e-b8aabc8e13b0%40gmail.com=
..

.
