220 20296 <55EB2F54.3060008@gmail.com> article
Path: news.gmane.org!not-for-mail
From: Andrey Semashev <andrey.semashev@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Draft proposal - std::recover_cast: undoing type erasure
Date: Sat, 5 Sep 2015 21:07:16 +0300
Lines: 66
Approved: news@gmane.org
Message-ID: <55EB2F54.3060008@gmail.com>
References: <7935FD03-ACA3-4D49-90B2-BDD107C2EF0B@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1441476444 6051 80.91.229.3 (5 Sep 2015 18:07:24 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 5 Sep 2015 18:07:24 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCXY5TXHWYJRBVW6VSXQKGQE2CTGSJA@isocpp.org Sat Sep 05 20:07:18 2015
Return-path: <std-proposals+bncBCXY5TXHWYJRBVW6VSXQKGQE2CTGSJA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wi0-f197.google.com ([209.85.212.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCXY5TXHWYJRBVW6VSXQKGQE2CTGSJA@isocpp.org>)
	id 1ZYHry-0000kx-Al
	for gclcip-std-proposals@m.gmane.org; Sat, 05 Sep 2015 20:07:18 +0200
Original-Received: by wisv5 with SMTP id v5sf15204840wis.0
        for <gclcip-std-proposals@m.gmane.org>; Sat, 05 Sep 2015 11:07:19 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:subject:to:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-type
         :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=et8Jym4ww9Lh+8r65mBO25jF39wCdbLhvX7J+zICLwY=;
        b=GTr0qHaBxYptPMZOPf+d3d2Rr+eBkM3aNDdReBPz3aAmiw8KomjoKZZMU82rNU81L2
         xcmO3ZxCod+YxzNAU95fZUGX651qUMpk8cjx5YC93fzPHeoqj6vHP+4Ajr5mR7U7xvJY
         olXchGgBNzFkU2ehfD7o/p4VkAP32Uzj7yoDKBIy4SHl0d/lKORuIlONOOhU657OX8Ki
         aLH1XdQjTsfT94wm4vYFXfNwrasBzfpVwgYLc//oQSdCBfGEJ+pz9dL96mWM0ZyN8CtE
         6ofUj1XeSyOiwKw6QLTs64A1Q52FLNvOFMR73zgA/eI8dk8 
X-Gm-Message-State: ALoCoQkpj2yb80kYcJatQbbLP0V+2RWgtRQyBF54smtLQoVEVeFdAhLNypCq5csYPSwFaZ/dUofp
X-Received: by 10.112.149.39 with SMTP id tx7mr2703495lbb.11.1441476439188;
        Sat, 05 Sep 2015 11:07:19 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.6.196 with SMTP id d4ls508912laa.91.gmail; Sat, 05 Sep
 2015 11:07:17 -0700 (PDT)
X-Received: by 10.112.54.132 with SMTP id j4mr9404501lbp.84.1441476437652;
        Sat, 05 Sep 2015 11:07:17 -0700 (PDT)
Original-Received: from mail-la0-x232.google.com (mail-la0-x232.google.com. [2a00:1450:4010:c03::232])
        by mx.google.com with ESMTPS id d9si4929334laf.139.2015.09.05.11.07.17
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 05 Sep 2015 11:07:17 -0700 (PDT)
Received-SPF: pass (google.com: domain of andrey.semashev@gmail.com designates 2a00:1450:4010:c03::232 as permitted sender) client-ip=2a00:1450:4010:c03::232;
Original-Received: by laeb10 with SMTP id b10so30812448lae.1
        for <std-proposals@isocpp.org>; Sat, 05 Sep 2015 11:07:17 -0700 (PDT)
X-Received: by 10.112.171.227 with SMTP id ax3mr9200823lbc.118.1441476437561;
        Sat, 05 Sep 2015 11:07:17 -0700 (PDT)
Original-Received: from [192.168.1.2] (broadband-178-140-129-233.nationalcablenetworks.ru. [178.140.129.233])
        by smtp.googlemail.com with ESMTPSA id n6sm1568806laf.18.2015.09.05.11.07.16
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sat, 05 Sep 2015 11:07:17 -0700 (PDT)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.2.0
In-Reply-To: <7935FD03-ACA3-4D49-90B2-BDD107C2EF0B@gmail.com>
X-Original-Sender: andrey.semashev@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of andrey.semashev@gmail.com designates 2a00:1450:4010:c03::232 as
 permitted sender) smtp.mailfrom=andrey.semashev@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=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-Spam-Checked-In-Group: 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:20296
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20296>

On 05.09.2015 12:12, David Krauss wrote:
> Abstract:
>
> C++ has a couple built-in type erasure mechanisms, with respective
> facilities to recover the original object: polymorphic classes with
> dynamic_cast, and void pointers with static_cast or reinterpret_cast. A
> library facility recover_cast is proposed to analogously handle erasure
> classes like std::function, any, and variant.

I can also add std::locale, which can be considered as a collection of=20
type erased facets.

> Besides being a uniform,
> generic interface, it simplifies implementation and and even improves
> performance.
>
>
> Highlight:
>
> template< typename T, typename ErasureClass >
> constexpr auto *
>
> recover_cast( ErasureClass /cq /* e ) noexcept;// /cq//is /const/or empty=
../
>
> /Requires:/ ErasureClass is capable of erasing T. (Thus, T shall not be
> void. A class may not assign semantics to =E2=80=9Cerased values of type =
void,=E2=80=9D
> and the implementation should diagnose an attempt to use recover_cast<
> void >( & e ) as a substitute for static_cast< void * >( e ).)

Why the special treatment of type void?

> /Returns:/ ( remove_reference_t< T /cq/ > * ) e.operator void const *
> ()if econtains type Taccording to e.verify_type< T >(). Otherwise, nullpt=
r.
>
> template< typename T, typename ErasureClass >
> auto &&// /cq//is /const/or empty. //ref//is /&/or /&&/./
>
> recover_cast( ErasureClass /cq ref/ e ) noexcept;
>
> /Requires:/ ErasureClass is capable of erasing T.
>
> /Effects:/ Let /p/ be recover_cast< T >( & e ). If /p/ is a null
> pointer, throw an object of class bad_type_recovery. Otherwise, return
> static_cast< T /cq ref/ >( * /p/ ).

I didn't like that the protocol you described in pdf is intrusive (i.e.=20
requires support built into the type erasing type). I would very much=20
preferred it to be decoupled from the type erasing wrapper. This would=20
allow to support the tool in non-standard type erasing types. Just=20
remove the ErasureClass concept and use functional API, in the=20
std::begin/end style.

--=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/.

.
