220 33019 <CAFk2RUbRhek+uf3sjX9o8dugGMLbTMxEpLjqB43gEMOhNfirhg@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Ville Voutilainen <ville.voutilainen@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: std::optional - support for sentinel values
Date: Thu, 29 Jun 2017 13:30:28 +0300
Lines: 49
Approved: news@gmane.org
Message-ID: <CAFk2RUbRhek+uf3sjX9o8dugGMLbTMxEpLjqB43gEMOhNfirhg@mail.gmail.com>
References: <6e23864f-827a-4bdb-89de-a60d8f5be993@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"
X-Trace: blaine.gmane.org 1498732233 31763 195.159.176.226 (29 Jun 2017 10:30:33 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 29 Jun 2017 10:30:33 +0000 (UTC)
To: "ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC5JHI7A7ALRBRVN2PFAKGQEC5HBGUA@isocpp.org Thu Jun 29 12:30:27 2017
Return-path: <std-proposals+bncBC5JHI7A7ALRBRVN2PFAKGQEC5HBGUA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qt0-f198.google.com ([209.85.216.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC5JHI7A7ALRBRVN2PFAKGQEC5HBGUA@isocpp.org>)
	id 1dQWiQ-0007xs-Bt
	for gclcip-std-proposals@m.gmane.org; Thu, 29 Jun 2017 12:30:26 +0200
Original-Received: by mail-qt0-f198.google.com with SMTP id h47sf30429233qta.12
        for <gclcip-std-proposals@m.gmane.org>; Thu, 29 Jun 2017 03:30:31 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1498732231; cv=pass;
        d=google.com; s=arc-20160816;
        b=LDi19z5Gcq01rtwpbSEKKZu7Lx7KPP1alYyWMgXsMvR/AAoRBn+Ac0A9DdyzIhJ5dW
         72ewLbjeAJ2dvpadKnqwXjuR/no57CQll8vgmWCT+sslQTz/Dksajcis49iLcmA8YXWd
         aw5mZp+7+qbQlDLLdsInzrtLTBLiLGtx4ktR3me8IKy62aF0u8AeCQ38da35K0LAwpMk
         +tGKESGjBbTu30U4kw9Wv5okKvbLnpn4YEz/6+ih1noUOO5+tHH/v8X2Skl/tci+L/KB
         M9NlrLbcLfRDHk0y2MqGzLwP/cE2vSEz4OeBnIh7d2sGxUEu7BRgNXEkT1U2r2fjgjZj
         7lFA==
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=SmF1TEY7Vxhuk77wVzWGiybVoiQh0B2kJJCrJlF0Kiw=;
        b=Oc/joddQFaDHcXGr2TDD9aRig7Cgfp72Qh+z0tm9fNmiWZAzlMEJUbm0fXykDhuEC6
         kY6NqgfIWUPrLWwSdmAXqQHdgP8Qi5vOhDQhMWqWOB/D/uPYAoXUM+iZKvI6IjGoy9yk
         lp2IcGS+bNk/FCSiWj5RYo3ztO+2Rg2boUezmTBjQFP8l7x1jqTNUwq/Nemt1NaOxIAx
         cM81wmrilo3t0SvaDMdMaDWmfABVbBBQF1yHvdLjGnD6ga90pqToMSCHV1F5TaMQ9bcO
         sJFKrI7lLwl29bO+9Vj7nCzIk+Oi1veSpk7eNAAYACUrocjl61ova9P91Dw8M0l7Y7th
         RuDA==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=ITsuM34H;
       spf=pass (google.com: domain of ville.voutilainen@gmail.com designates 2607:f8b0:4001:c0b::230 as permitted sender) smtp.mailfrom=ville.voutilainen@gmail.com;
       dmarc=pass (p=NONE sp=NONE 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=SmF1TEY7Vxhuk77wVzWGiybVoiQh0B2kJJCrJlF0Kiw=;
        b=Wn7w5dRTu8XeGuIV8JqEPze97cnWaLz4j9yNHjBdIG+3xEAmZdh9FrZz5NfQqP+7hW
         qKGamD12HnverV7rFK8CFl3TeYdI8fMaDvhr1wuzvWbef0lyMFNvsT32Rw3P13+K6Iy6
         mftskBJhu1UZp0kuOi3AYMggoN5yOZYTj2Op7t2uaZyAPvK0TFUnsSW6GPcjUSS18My1
         hkTh6oocHDz5qax0xxb0C92sFe/x0WaUfdtfpfBf/PEQRLgGn+a+it7pqu4bnjx2ap/k
         3vbf8DjmupNmFEicfsyFJ6zc+W2ut9GP49Zq7y5gNpoUW9ubL0B9AU71yIHL9IAvNJWY
         rnYg==
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=SmF1TEY7Vxhuk77wVzWGiybVoiQh0B2kJJCrJlF0Kiw=;
        b=Oipal8hQGDx830kcNc1dSK4jaTEA7Rsa2hapKAad1LVa/ts1GnFPRMxDo3KZ2TbGPC
         9exagpmlcgwfaCvmzRiziJB/+cQB98EWdHMRE3gF983C9vGuj/jaQV+u1nsXNStG/W1B
         YZcU29rpuNeDFP0AzGwykxet0OADpjPozTh8Hi4xo/F3Ow3T8NwVI3FO1tALXBSKga2z
         2H63v4zYLEVat5J5jJ/6EnbVuENrymzRo4lJB9GbG5BlTSfFb7ngn1Jgfz5GoDpPztUX
         yg+62W14A+MgTu85ANy3N+kaMBNs1F7pR4Oby5ZRvJuYStH9A1HtXdYrF9AKLw+s46Nv
         MwDA==
X-Gm-Message-State: AKS2vOyRt0XfbAwdhAILCYxf1H/zZ4uhBwsSaIM4Ih93njso9DTKRNtl
	agOAHs8z5yHOl8FY
X-Received: by 10.237.34.23 with SMTP id n23mr4899122qtc.36.1498732231418;
        Thu, 29 Jun 2017 03:30:31 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.46.103 with SMTP id i100ls460717ioo.43.gmail; Thu, 29 Jun
 2017 03:30:30 -0700 (PDT)
X-Received: by 10.107.137.152 with SMTP id t24mr16663775ioi.218.1498732229964;
        Thu, 29 Jun 2017 03:30:29 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1498732229; cv=none;
        d=google.com; s=arc-20160816;
        b=zeKn+TYFvxD+1McWrpL/GmKT5hj3hDXjhBNFuccVp0JVpm0FgGXUTe0DJIyhmm6CjV
         bl20uxm4uXOSi2vkBj+5lsh3/XhQq5hRLOhsyQq6Qc5+T51/dlv0XHC5UCycxX2CYszH
         5HJFeqRQ5Pq9W3AcufF+KWabh7YP5UOX0D2ifD2Qbks8FCJVlSJUCDeySmTKZ318aliH
         qPm+1TlQjfO1KTBLfX3hGmjrzfLBWMxCwIU+e97Yyv1vT5ADR2rYuLmPnqMrmwNwdZ2C
         3hBFpjmPX+1ug/Ta9UIQDVcBjF9MdbNGbhGxdvMrzWyYerBpU1m7kurIYfTzBZmp2Rju
         zrkQ==
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=5FOCvoRmC4l+VGg0wcQNCEfepdIYOpVHmzj/OKy2/Oc=;
        b=ynXHm8iWecHW50MJgYYYjjM5vkhXaOcbpJ8iaN/kca/jbLH6fgXL0RSJXV9OQG8FHk
         QesLn4czVUYONdoMbUuRFBojHP9KO95lyE5jqbkbj+lqlJ3BMDTgaRk0mnYmRQXLGbju
         Qs6lKrXjgOqXcQLHn9VYcbVEempT2rDtt4e5RQJoTOXAqQ8mj97WfQ7l+YR9EoVfjtPU
         J+wDGSaOHiIT1EfEpoZl7TPOg2wHshXboJ7TBI3PJhrrV+rr+e9NqWz8lxNO8wehXECp
         RP1koB5B9t7F9IqJpDFR0VmruYe/KUq2dTVJk40wsw2XonagoyRecH4YQ7jjtV78FzHh
         J3/w==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=ITsuM34H;
       spf=pass (google.com: domain of ville.voutilainen@gmail.com designates 2607:f8b0:4001:c0b::230 as permitted sender) smtp.mailfrom=ville.voutilainen@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Original-Received: from mail-it0-x230.google.com (mail-it0-x230.google.com. [2607:f8b0:4001:c0b::230])
        by mx.google.com with ESMTPS id a128si734091ita.122.2017.06.29.03.30.29
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 29 Jun 2017 03:30:29 -0700 (PDT)
Received-SPF: pass (google.com: domain of ville.voutilainen@gmail.com designates 2607:f8b0:4001:c0b::230 as permitted sender) client-ip=2607:f8b0:4001:c0b::230;
Original-Received: by mail-it0-x230.google.com with SMTP id m84so4520324ita.0
        for <std-proposals@isocpp.org>; Thu, 29 Jun 2017 03:30:29 -0700 (PDT)
X-Received: by 10.36.33.202 with SMTP id e193mr12406254ita.92.1498732229307;
 Thu, 29 Jun 2017 03:30:29 -0700 (PDT)
Original-Received: by 10.36.122.211 with HTTP; Thu, 29 Jun 2017 03:30:28 -0700 (PDT)
In-Reply-To: <6e23864f-827a-4bdb-89de-a60d8f5be993@isocpp.org>
X-Original-Sender: ville.voutilainen@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.b=ITsuM34H;       spf=pass (google.com: domain of
 ville.voutilainen@gmail.com designates 2607:f8b0:4001:c0b::230 as permitted
 sender) smtp.mailfrom=ville.voutilainen@gmail.com;       dmarc=pass (p=NONE
 sp=NONE 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-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:33019
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33019>

On 29 June 2017 at 12:51, Igor Baidiuk <target.san@gmail.com> wrote:
> At the moment, std::optional type, in the way it was accepted by committee,
> always has storage block for its value and a flag field, which determines if
> actual value is present.
> Although, there are often safe wrapper types (like std::reference_wrapper,
> or wrapper around OS handle, or a raw pointer) which have kind of
> "impossible state" on their own. For such types, it's perfectly possible to
> represent std::nullopt state as this "impossible" value:
>
> Allow to define optional sentinel value for a type. Current approach in STL
> seems to be trait struct for the type and trait adaptor used in
> std::optional to access values (similar to std::allocator<T> +
> std::allocator_traits<Alloc>). There might be a requirement that sentinel
> value should be constexpr.
> If type defines sentinel value, then std::optional's nullopt is represented
> with that sentinel value, and there's no additional flag
>
> There are several benefits coming with this approach:
>
> Space efficiency for types with "invalid value"
> Type safety. Sentinel value simply cannot be used the same way as normal
> value. Roughly saying, no "null pointer dereference" issue
>
> The other extension, orthogonal to first one, is to allow value to be stored
> using alternate representation. As an example, reference type can be stored
> as a pointer and simply presented as reference. This will also allow to have
> cheap and relatively easy support for storing references in std::optional,
> without need of completely separate type specialization.
>
>
> Any thoughts on this?


That's a type different from optional. And optional-with-sentinel that
considers a certain raw
pointer value to be the sentinel value is not the same thing as an
optional that adds a nullopt
state. The latter can't be made to act like the former the way you
suggest, because once a trait
is present, it can't be removed, or we have an odr violation.

You need a new type.

-- 
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/CAFk2RUbRhek%2Buf3sjX9o8dugGMLbTMxEpLjqB43gEMOhNfirhg%40mail.gmail.com.

.
