220 33041 <cebea1ab-9c29-4c7d-acea-9d3ff6b4062c@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: inkwizytoryankes@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: std::optional - support for sentinel values
Date: Fri, 30 Jun 2017 10:24:04 -0700 (PDT)
Lines: 145
Approved: news@gmane.org
Message-ID: <cebea1ab-9c29-4c7d-acea-9d3ff6b4062c@isocpp.org>
References: <6e23864f-827a-4bdb-89de-a60d8f5be993@isocpp.org>
 <c44c5d09-9124-488f-aa92-f9ab59797268@isocpp.org>
 <c039c5e5-13d0-4052-89f7-b2af50f1e0fc@isocpp.org>
 <0dd0a5ae-5fc2-020f-73a9-f5c7959fed0f@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_468_1176146734.1498843444502"
X-Trace: blaine.gmane.org 1498843451 13678 195.159.176.226 (30 Jun 2017 17:24:11 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 30 Jun 2017 17:24:11 +0000 (UTC)
Cc: target.san@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDDLTAGNTIBBBNMS3LFAKGQEIC2QLIA@isocpp.org Fri Jun 30 19:24:05 2017
Return-path: <std-proposals+bncBDDLTAGNTIBBBNMS3LFAKGQEIC2QLIA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f197.google.com ([209.85.192.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDDLTAGNTIBBBNMS3LFAKGQEIC2QLIA@isocpp.org>)
	id 1dQzeD-00031z-PE
	for gclcip-std-proposals@m.gmane.org; Fri, 30 Jun 2017 19:24:01 +0200
Original-Received: by mail-pf0-f197.google.com with SMTP id v26sf69494411pfa.0
        for <gclcip-std-proposals@m.gmane.org>; Fri, 30 Jun 2017 10:24:07 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=Tpq0VbjEQbqMPORaeo3JhsQ6g7pho+bUgQeYEgkmszQ=;
        b=Se0rLtyu49dJNEXarGLFC/Hnq7TquBZzuvkXVoZf0tHxxSmbnS6PNSmyaY49miuFop
         Plh4k+oQkuW8JF0In65xiROl0vud7qGX/x0h3xNYjfVZD3s3zrwbKe714yp4+PRxTJH3
         1CtX2N/22Td7txkW1gAlNNAE8wac71L5kxDfZSvvzETbexN/RS0KNBlKE6D03X15lGMj
         Qe/vbT9OB4+GPCnbUYkMfQj6cX0Y1u1BeGOBki5f06neJTJZcmm3rJ494I/zsjKNVmwM
         yyzrKF4v51D3NjdUIOwdEXssaEWw7Q8MXBc1aB8ezCp11rmy3tqZsvgVZQvpXGv61oS7
         Xt0g==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=Tpq0VbjEQbqMPORaeo3JhsQ6g7pho+bUgQeYEgkmszQ=;
        b=KNw8M0dLrgQSVrcxinRwtU3aqQzkY+K9TV+Pab3qV1g2OlYXUugEWLV3NX3ecGPWb0
         mrhi4bRwH7Dl5eYywtpQGP4gx8nS5v2BleAhMItPsBQi/ltByJjLmyOpBGXpSFm2tLTU
         kxx2xEfsb/K82FU48xbMxzxom/4AqZ74wj9HNUEM4NweV11hCq6sE5oYAQ81zHAlrQQ0
         N17mO+6kmUYxQiH7ZYYW9DtAKFdPjT+MKs4i+vgq9FTKYE9pRut0p5Ry0qQQPxDeAaC1
         L2DbDyV1X2H1MBjcRAlQgH8dQ/ZC3mlH6BFj/KpXr5Jt0bAvEUu7FrGKMw3KMaKZPotH
         9WAQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=Tpq0VbjEQbqMPORaeo3JhsQ6g7pho+bUgQeYEgkmszQ=;
        b=rsQLluJmnw+qg2300/73/qFMkgH9x2ZOSDLZNHQAYZrSnfwG/VF0g6E7fz42VHE/P4
         /Xj5o4Hs4hAx3DWHuRH9AVBxlT0GKzzQAsjBGAGb45YqFuZwHzjgkpY21FKdFTmrWpmo
         +BiYeNZUhHvdBjcsEQElqZTBkxuwb/FVQJYCGLOXBd3PqOx4q2nHpgU96BATWi/jj7Ph
         5IHzvvRZZ4ZOa5qzudJwIAhBIIjDFdixSh6Hf9MsgGUxPJghX27JwOa+w3+iANqSzQOS
         zsnbsFTHcFpqX6K6SE7Tj88ce8hd1cK38OehNqimeE1iQAcf0QxsJ9G43muYitgh7Qzn
         PgKw==
X-Gm-Message-State: AKS2vOxwBkKfuLsKST6XjvhzM/HkPAb4JVrbliYmqOikJsDeDCUWf7jy
	/085tX2GReNxhBv8
X-Received: by 10.99.56.25 with SMTP id f25mr13673490pga.135.1498843446453;
        Fri, 30 Jun 2017 10:24:06 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.172.109 with SMTP id m45ls2708032iti.11.canary-gmail; Fri,
 30 Jun 2017 10:24:05 -0700 (PDT)
X-Received: by 10.36.34.10 with SMTP id o10mr369176ito.10.1498843445074;
        Fri, 30 Jun 2017 10:24:05 -0700 (PDT)
In-Reply-To: <0dd0a5ae-5fc2-020f-73a9-f5c7959fed0f@gmail.com>
X-Original-Sender: inkwizytoryankes@gmail.com
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:33041
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33041>

------=_Part_468_1176146734.1498843444502
Content-Type: multipart/alternative; 
	boundary="----=_Part_469_1199741472.1498843444502"

------=_Part_469_1199741472.1498843444502
Content-Type: text/plain; charset="UTF-8"



On Friday, June 30, 2017 at 5:44:57 PM UTC+2, Matthew Woehlke wrote:
>
> On 2017-06-30 10:21, Igor Baidiuk wrote: 
> > On Friday, June 30, 2017 at 2:05:35 AM UTC+3, Arthur O'Dwyer wrote: 
> >> - In fact, if you can enumerate the available bit-patterns, you can 
> store 
> >> a *lot* of extra information in the unused bits of a T. My STL uses 
> this 
> >> fact to make sizeof(optional<optional<optional<bool>>>) == 1. Your 
> >> approach would be completely unable to optimize this; you'd have to use 
> at 
> >> least 4 bytes. 
> > 
> > Let's imagine someone tries to take reference to doubly-optional bool 
> from 
> > your triple-optional bool. And assign it some value. 
>
> I can imagine ways this can still work. (The complexity will depend on 
> what happens when you assign `true` to the inner-most `bool`, i.e. if it 
> stores 1 (0x1) or -1 (0xff).) 
>
> > Also note that 
> > Some(Some(Some(false))), Some(Some(None)), Some(None) are three 
> different 
> > state of your triply-optional bool. Even with space compression, you'll 
> > need at least 2 bytes. 
>
> Er... why? 
>
> An `optional<T>` needs `bitsof(T)+1` bits of storage. A `bool` has two 
> legal states, so `bitsof(bool) == 1`. Thus, an `optional<bool>` needs 2 
> bits of storage. 
>
> Applying this recursively: 
>
>   bitsof(optional<bool>) == 2 
>   bitsof(optional<optional<bool>>) == 3 
>   bitsof(optional<optional<optional<bool>>>) == 4 
>
> Last I checked, there are (probably / at least) 8 bits in a byte. I 
> hardly need *16* bits to store optional^3<bool>. In fact, I could 
> (theoretically) store up to optional^7<bool> in *one* byte. 
>
> -- 
> Matthew 
>

16 because you need full byte object in optional otherwise you will get 
`std::vector<bool>` mk2.

-- 
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/cebea1ab-9c29-4c7d-acea-9d3ff6b4062c%40isocpp.org.

------=_Part_469_1199741472.1498843444502
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, June 30, 2017 at 5:44:57 PM UTC+2, Matt=
hew Woehlke wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2017-06-3=
0 10:21, Igor Baidiuk wrote:
<br>&gt; On Friday, June 30, 2017 at 2:05:35 AM UTC+3, Arthur O&#39;Dwyer w=
rote:
<br>&gt;&gt; - In fact, if you can enumerate the available bit-patterns, yo=
u can store=20
<br>&gt;&gt; a *lot* of extra information in the unused bits of a T. My STL=
 uses this=20
<br>&gt;&gt; fact to make sizeof(optional&lt;optional&lt;<wbr>optional&lt;b=
ool&gt;&gt;&gt;) =3D=3D 1. Your=20
<br>&gt;&gt; approach would be completely unable to optimize this; you&#39;=
d have to use at=20
<br>&gt;&gt; least 4 bytes.
<br>&gt;
<br>&gt; Let&#39;s imagine someone tries to take reference to doubly-option=
al bool from=20
<br>&gt; your triple-optional bool. And assign it some value.
<br>
<br>I can imagine ways this can still work. (The complexity will depend on
<br>what happens when you assign `true` to the inner-most `bool`, i.e. if i=
t
<br>stores 1 (0x1) or -1 (0xff).)
<br>
<br>&gt; Also note that=20
<br>&gt; Some(Some(Some(false))), Some(Some(None)), Some(None) are three di=
fferent=20
<br>&gt; state of your triply-optional bool. Even with space compression, y=
ou&#39;ll=20
<br>&gt; need at least 2 bytes.
<br>
<br>Er... why?
<br>
<br>An `optional&lt;T&gt;` needs `bitsof(T)+1` bits of storage. A `bool` ha=
s two
<br>legal states, so `bitsof(bool) =3D=3D 1`. Thus, an `optional&lt;bool&gt=
;` needs 2
<br>bits of storage.
<br>
<br>Applying this recursively:
<br>
<br>=C2=A0 bitsof(optional&lt;bool&gt;) =3D=3D 2
<br>=C2=A0 bitsof(optional&lt;optional&lt;bool&gt;<wbr>&gt;) =3D=3D 3
<br>=C2=A0 bitsof(optional&lt;optional&lt;<wbr>optional&lt;bool&gt;&gt;&gt;=
) =3D=3D 4
<br>
<br>Last I checked, there are (probably / at least) 8 bits in a byte. I
<br>hardly need *16* bits to store optional^3&lt;bool&gt;. In fact, I could
<br>(theoretically) store up to optional^7&lt;bool&gt; in *one* byte.
<br>
<br>--=20
<br>Matthew
<br></blockquote><div><br>16 because you need full byte object in optional =
otherwise you will get `std::vector&lt;bool&gt;` mk2.<br></div></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/cebea1ab-9c29-4c7d-acea-9d3ff6b4062c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cebea1ab-9c29-4c7d-acea-9d3ff6b4062c=
%40isocpp.org</a>.<br />

------=_Part_469_1199741472.1498843444502--

------=_Part_468_1176146734.1498843444502--

.
