220 13943 <997390c5-072b-407a-bce9-22a29fc5e228@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Edward Catmur <ed@catmur.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Default values for n4191 fold expressions
Date: Wed, 15 Oct 2014 16:53:46 -0700 (PDT)
Lines: 41
Approved: news@gmane.org
Message-ID: <997390c5-072b-407a-bce9-22a29fc5e228@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1413417235 22643 80.91.229.3 (15 Oct 2014 23:53:55 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 15 Oct 2014 23:53:55 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDZLZTXF7UJBBCUS7SQQKGQELPI73KQ@isocpp.org Thu Oct 16 01:53:48 2014
Return-path: <std-proposals+bncBDZLZTXF7UJBBCUS7SQQKGQELPI73KQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f199.google.com ([209.85.192.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDZLZTXF7UJBBCUS7SQQKGQELPI73KQ@isocpp.org>)
	id 1XeYO4-0003jT-Kn
	for gclcip-std-proposals@m.gmane.org; Thu, 16 Oct 2014 01:53:48 +0200
Original-Received: by mail-pd0-f199.google.com with SMTP id g10sf11759846pdj.10
        for <gclcip-std-proposals@m.gmane.org>; Wed, 15 Oct 2014 16:53:47 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type:content-transfer-encoding;
        bh=63a0qAZ4wd3opBhOLzSNJq956E/4NCVWSt7CEQ3oaQM=;
        b=eN/imoOK0cOVFNHfuXJRT89yG/hqBXpSXx2YJ49Q0qw41P6Zeid5obuJkYs/bUhbuX
         nl6UB4XTtJivx6Oj1v7yM7GbNijLs6rTk+CVEBb0ip9zyt75teWYT3ZpiXQnA06wj7p/
         DX34XOrTqiwzgUmlr3di7P25+Bd3QlWSO3saTy+1NIyaFqrd1Hu4ggXlTMfp+Rm0p1mt
         JtOh9d6JjSqaZvlUimEq9h0gmTEzjAyJNbAgZ8tBxQjaSIMuF2K50J7jHWNVMNKyhgAp
         qOVrA9SIEz6eNolPZSOw7qtWvN/kudXyvisqLJl/om88+3etykGzybtugRPDwq9IDEIL
         a4Kg==
X-Gm-Message-State: ALoCoQl318QLP4nvKr1PM4LrD2BKSTtiDBtosyNPxFeQKChj11ln6cHYCM5nb8DjSveTxkhHd5mZ
X-Received: by 10.66.139.167 with SMTP id qz7mr10793057pab.23.1413417227567;
        Wed, 15 Oct 2014 16:53:47 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.18.143 with SMTP id 15ls478523qgf.70.gmail; Wed, 15 Oct
 2014 16:53:46 -0700 (PDT)
X-Received: by 10.140.19.1 with SMTP id 1mr64424qgg.19.1413417226819;
        Wed, 15 Oct 2014 16:53:46 -0700 (PDT)
X-Original-Sender: ed@catmur.co.uk
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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:13943
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13943>

N4191 provides that the fold of an empty parameter pack is defined for the =
binary operators + * & | && || , to 0 1 0 -1 false true void() respectively=
.. I am concerned that this may result in confusing or undefined behavior, e=
specially for types that overload these operators.

Consider string s =3D (to_string(args) + ...); if the 0 is the literal and =
so can be interpreted as a null pointer constant this results in undefined =
behavior, while if it is a prvalue int this gives a string of length 1 cont=
aining a nul character. Other types give different errors; std::chrono::dur=
ation fails as its constructor from int is explicit.=20

For binary * the library type valarray is unlikely to behave as desired; si=
milarly a square matrix type could give incorrect results. The binary bitwi=
se operators present a similar issue, and even for primitive types -1 is li=
kely to be of the wrong length and/or signedness (what happens when 32-bit =
-1 is promoted to uint64_t?)

I would therefore argue to disallow empty parameter pack fold expansions fo=
r the arithmetic and bitwise operators. The binary boolean operators and co=
mma operator can stay; they are far less often overloaded and the default v=
alues are simultaneously more obviously correct and unique, more difficult =
to remember, and require more typing than for the arithmetic and bitwise op=
erators.

Regards, Ed=20

PS. If we are doing bitwise operators, what about ^?

PPS. Is ~ really supposed to be in there?=20

--=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.
