220 29336 <2128372.NTAZafObDQ@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: std::byte thoughts
Date: Tue, 01 Nov 2016 23:43:31 -0700
Lines: 89
Approved: news@gmane.org
Message-ID: <2128372.NTAZafObDQ@tjmaciei-mobl1>
References: <7da80620-e4bd-40eb-a4ec-4f3c2dcb2c98@isocpp.org> <2350841.Z7lUCKSumT@tjmaciei-mobl1> <3e64b220-79ae-4108-ba1c-9785494fc434@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
Content-Transfer-Encoding: quoted-printable
X-Trace: blaine.gmane.org 1478069032 28828 195.159.176.226 (2 Nov 2016 06:43:52 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 2 Nov 2016 06:43:52 +0000 (UTC)
User-Agent: KMail/5.3.2 (Linux/4.8.4-1-default; KDE/5.27.0; x86_64; ; )
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBFUW43AAKGQEBGPPTDI@isocpp.org Wed Nov 02 07:43:48 2016
Return-path: <std-proposals+bncBCB4TK757YBRBFUW43AAKGQEBGPPTDI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wm0-f70.google.com ([74.125.82.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBFUW43AAKGQEBGPPTDI@isocpp.org>)
	id 1c1pGm-0004zG-B3
	for gclcip-std-proposals@m.gmane.org; Wed, 02 Nov 2016 07:43:32 +0100
Original-Received: by mail-wm0-f70.google.com with SMTP id 79sf3505165wmy.6
        for <gclcip-std-proposals@m.gmane.org>; Tue, 01 Nov 2016 23:43:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:user-agent:in-reply-to:references
         :mime-version: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=BrghJjlrwkTJW2ba28b1bwoMuN/WF/sjBrxqDrYZHOw=;
        b=frNphZQYOPH0hMm+/SAzaowAF2xuF5UjY9JEI8/O+bmDW/fR8Re4jp7rBNdxHhqczE
         xe4plEhV5Pg1J+/bbIVe8ZG+/sjIqks77AVy1kXpHG06lcZ9fcWXoYY7YN4iTVdsoN3o
         B/R9Rs9PZKJ054vNdrtqhUHLwurR02VqpydrIo8VJyyv24qgHQWl8o5VLzREQwgIpox9
         8qUPsgZzpiIo1jh9+c7yLaWpbYbu4ZKT/7H8fNpe85YN4QtilabeAEv0Wx6e8gYxr4V7
         hGe58lPNZ9VW4AfojvrCTkqjTnsZZeyVuH0/OhZW0xeLbpFzaglpaQJPXbkh5/4QLWDO
      
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:subject:date:message-id:user-agent
         :in-reply-to:references:mime-version: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=BrghJjlrwkTJW2ba28b1bwoMuN/WF/sjBrxqDrYZHOw=;
        b=YzABc282jRp62xMX/ID/zOqMIAHjoqC0gK7ZuCeJi7cDNDekXFcQIQWLIzQQoBdgOM
         xJFsWHu3lq21dCL4m5dR6UUSJv2fQeb6Ngqq6p1bbfLo7MWiy14JuLtRmFp6XcrRBxoH
         VHqv7olZ0w7mfCXmjVcswxPbmVRHYoy7XQMAsLDgIfkq9abSDxXi2Xmm7uTXXeJOn9v3
         iPPGWv7R9DhwpxnjzxpK30EpFiGiEAZ7CNCo9vCw/F/MT8hrQC0PRUQr8nGogEdtnNC8
         /bl0rTmdfTtrlnNqeQKLGV45T9Oy/3D7ZpJfv9tXEoW323InEqIsM4CMvrl25TZsqgtb
  
X-Gm-Message-State: ABUngvff2Iu6u3C04daO7hBYkitUAqmV4sG+OK4fXLcIrJErVbke9nIchutbLGlZKxLKhg==
X-Received: by 10.28.156.13 with SMTP id f13mr6541wme.10.1478069015344;
        Tue, 01 Nov 2016 23:43:35 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.193.15 with SMTP id r15ls196591wmf.20.gmail; Tue, 01 Nov
 2016 23:43:34 -0700 (PDT)
X-Received: by 10.28.4.4 with SMTP id 4mr1185039wme.23.1478069014125;
        Tue, 01 Nov 2016 23:43:34 -0700 (PDT)
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [78.47.120.188])
        by mx.google.com with ESMTP id 203si1440853wmm.118.2016.11.01.23.43.34
        for <std-proposals@isocpp.org>;
        Tue, 01 Nov 2016 23:43:34 -0700 (PDT)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) client-ip=78.47.120.188;
Original-Received: from tjmaciei-mobl1.localnet (unknown [IPv6:2601:1c0:4501:5f9f:d130:7f7c:ebed:53ad])
	by gondolin.macieira.info (Postfix) with ESMTPSA id 8D06A11B3B5
	for <std-proposals@isocpp.org>; Tue,  1 Nov 2016 23:43:33 -0700 (PDT)
In-Reply-To: <3e64b220-79ae-4108-ba1c-9785494fc434@isocpp.org>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 78.47.120.188 as permitted sender) smtp.mailfrom=thiago@macieira.org
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: <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:29336
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29336>

Em ter=C3=A7a-feira, 1 de novembro de 2016, =C3=A0s 22:16:32 PDT, Nicol Bol=
as escreveu:
> On Wednesday, November 2, 2016 at 12:55:46 AM UTC-4, Thiago Macieira wrot=
e:
> > That would also not be a good idea because, unsigned char is, by
> > defintion, a
> > byte. Why should we have (more) types that mean exactly the same thing,
> > and
> > this time in all platforms, by definition?
>=20
> Because "unsigned char" *also* means "unsigned character". With just
> `unsigned char`, there is no way to distinguish between manipulating byte=
s
> and manipulating unsigned characters.
>=20
> That's what `byte` is for, as a type: a way to semantically differentiate
> between operations on bytes and operations on characters. The types can b=
e
> inter-convertible, numerically speaking, but they don't mean the same thi=
ng.

I'm sorry, I don't agree that there's a distinction in the first place. Byt=
es=20
are used more often than just copying around. If you add, subtract, shift l=
eft=20
or right, perform bitwise operations, etc, you need the value. If I need th=
e=20
value, then a zero is a zero is a zero, a 0x40 is still a 0x40.

Also, I can assign 'a' to any integer type. Maybe this was the main issue:=
=20
that single-quote character literals automatically convert to integral,=20
instead of staying a character. We're 40 years too late to change this, tho=
ugh=20
(since B).

> My problem with using C++ enum chicanery is that, if you use the type
> traits mechanisms to ask what `std::byte` is, it will say that it's an
> enum, not that it's an integral type. There's no reason why `byte` should
> not be an integral type.

Agreed, but I'm going to go further and say that it's pretty useless for a =
lot=20
of use-cases. I need a value of a lot of operations and an enum won't give =
it=20
to me unless I cast it to a suitable integral in the first place -- unsigne=
d=20
char (that is, a *real* byte).

This week I've been spending time working on hashing algorithms, notably=20
SipHash (btw, implementations should reconsider their std::hash algorithms)=
..=20
In order to implement it, I needed to access the byte array and do byte-lev=
el=20
operations like rotating left, XOR, and additions. Not only would std::byte=
=20
not work for me, I fail to see how the operations I'm doing are any differe=
nt=20
than the operations on an unsigned char.

> It's the same reason why we have `char16_t` as a distinct type from
> `uint_least16_t`. Because there is a fundamental semantic difference
> between an array of unsigned integers that are at least 16-bits in size a=
nd
> an array of UTF-16 code units. One of this is a string; the other is not.

The only benefit I see there is allowing overloading.

But while that may be true, what's the point of an *unsigned* char? If you=
=20
want to do character operations, you use char. If you're using unsigned cha=
r,=20
that's because you want a byte, plain and simple. By this argument, we alre=
ady=20
have the distinction between character operations and byte operations.

--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--=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/2128372.NTAZafObDQ%40tjmaciei-mobl1.

.
