220 34969 <68690e5c-f466-4fbe-ab41-80be58257259@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Aleksey Loginov <aleksey.loginov@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Idea about "std::pmr::memory_resource"
Date: Mon, 16 Oct 2017 10:39:33 -0700 (PDT)
Lines: 310
Approved: news@gmane.org
Message-ID: <68690e5c-f466-4fbe-ab41-80be58257259@isocpp.org>
References: <0a8293b4-3246-47a5-9881-bc1ca4b91772@isocpp.org>
 <07ddb1f6-d3af-43df-bf96-8975c1ab4313@isocpp.org>
 <2e191a96-1952-479b-b78b-22e31f8e03de@isocpp.org>
 <0e37b5ae-64f6-4a8a-86bd-f44b119ed40a@isocpp.org>
 <15f8c5ba-3a6a-4441-9620-92e157c66094@isocpp.org>
 <26fe4cb4-98ca-41cc-ac96-5c51851799d1@isocpp.org>
 <fee0a310-5dc5-4421-bf49-bc8fa164fe29@isocpp.org>
 <784ffce8-ace7-449d-a13d-a99d7336117a@isocpp.org>
 <d029c18a-12ee-4a7d-828c-ab1bd07b58c6@isocpp.org>
 <6d0ad98b-87d5-43dd-ac54-2b7d3e03e31b@isocpp.org>
 <bd58ac93-5d20-48e6-93cc-b07a727ce892@isocpp.org>
 <4af80cf7-244c-4137-9133-1a36a209e4ca@isocpp.org>
 <7f22751b-91d1-4de4-81d2-421046ceb963@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_17984_1292694928.1508175573386"
X-Trace: blaine.gmane.org 1508175590 29107 195.159.176.226 (16 Oct 2017 17:39:50 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 16 Oct 2017 17:39:50 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCGIDMXA5AJRBVW5SPHQKGQE37VWZ2Q@isocpp.org Mon Oct 16 19:39:44 2017
Return-path: <std-proposals+bncBCGIDMXA5AJRBVW5SPHQKGQE37VWZ2Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ua0-f198.google.com ([209.85.217.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCGIDMXA5AJRBVW5SPHQKGQE37VWZ2Q@isocpp.org>)
	id 1e49MN-0004xw-Na
	for gclcip-std-proposals@m.gmane.org; Mon, 16 Oct 2017 19:39:28 +0200
Original-Received: by mail-ua0-f198.google.com with SMTP id h34sf8042166uaa.8
        for <gclcip-std-proposals@m.gmane.org>; Mon, 16 Oct 2017 10:39:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to: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=iuC1b6VN8nRbJybVkWRACDsskdN7cKAZ/0CJ/aBByVE=;
        b=TbMDbrf/atOBUO18IMaLoTCgHqUDw/2cpfXYC7TLcLcmYwDxK3rb11L1y+8VMiLQzh
         rPo2EiKQFQml7pygF3llkPMX7KEfWIXmRkqOqYPdSyC8FDnr4RfvTTR/J1NcR9QkNC5n
         KmYOoqOM7VWpzBqfa3JILIpXBTgYtSbsxPMz5odE3qQqh7qsxKmGkaZtchAREE97mjZK
         /CRcmet8pwV0tbLa+QRYVcFJss7RgK9miPGuYnVkjOOkJuNo8kbYpjAG3XkV7WJwXiDe
         +esyGNkvM5BlkGSvA2b7hk96vVeH5AafwMDNl0IJ8MsBFowoJkW9Ua4+h5QC9Zm5uvKs
         jPWQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to: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=iuC1b6VN8nRbJybVkWRACDsskdN7cKAZ/0CJ/aBByVE=;
        b=G1OGnbYV9shwo31B1oQFMdNNM/W+Sh17bhwGcuyAfbQyd1X5gbdGp8FTGt0p0aHqoj
         x2v8t+1PGUedMJ9K5s7s62flX79liP5H1jSl7Kuucfnfb4gy0/wbCZQBN/nflh8+FWe+
         Dsj+gwppm2kf6HABDP8WrDm9oD2Y/wq1o5PBmCv9+VHaM27ov2J25Tiy3rsgmGu8i/is
         c8QfbupZS38vOUScjgYfTHweXag7b6tbaXhogwAPcuA5LwRaq/OsAGN3zlP3mCLJj0jW
         DlW/tKs5cPBWL1d3FoCH8Phzb+3PTkw9Z1AFvvxZooqU2SpTRWvg9+/lDuoGa5yoRLV/
         3IQg==
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: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=iuC1b6VN8nRbJybVkWRACDsskdN7cKAZ/0CJ/aBByVE=;
        b=d8OqBN7EZxgsynEg6GufPcQo3GUKIIIeNHnZcDwfV+yvXoquOzPQ5IgQmHSGnlWo1i
         gJ72AGYaIzFehmjXjfm45vJkcBV4HM6TNdS1F5rAhLKsijVjHGWYPnXJ8lGWsD0lLcXz
         Uwm3k/cdiaSOLiVPcUYV1OtGzMzP5D1u7cdAA1kOBqtG5m2B2Lomwc/uhVHeooeKEmW5
         5vdOFSlkJNaWeVjG/lJB3ZV5pSL+ZGCjv2THb52Xh3yzHCq/ru8Y7x5n3NiusWENXSU4
         DLHBkT7OUo10Q2i0uMxxRKlHY1hD4LsZVKt7aBXAXreOiJVs+eET8rBW6xszwkcRodqf
         hTqQ==
X-Gm-Message-State: AMCzsaUkWrwymgP8nYY1b/t1qDEK4CalxJNczp6m/qhswq01pv520dBu
	IbFr5nc7chmFp6BIaL3iMLE9jg==
X-Google-Smtp-Source: AOwi7QCeK0r9qdp9xxvh3w0UzVhnw9awOJRQq/MM+P5fhkbdOy+hGC+zvuwMGCarIyfCmKQVNNmbnw==
X-Received: by 10.31.65.207 with SMTP id o198mr5701261vka.103.1508175575096;
        Mon, 16 Oct 2017 10:39:35 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.31.188.207 with SMTP id m198ls3374935vkf.21.gmail; Mon, 16 Oct
 2017 10:39:34 -0700 (PDT)
X-Received: by 10.31.69.204 with SMTP id s195mr788700vka.12.1508175573987;
        Mon, 16 Oct 2017 10:39:33 -0700 (PDT)
In-Reply-To: <7f22751b-91d1-4de4-81d2-421046ceb963@isocpp.org>
X-Original-Sender: Aleksey.Loginov@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:34969
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/34969>

------=_Part_17984_1292694928.1508175573386
Content-Type: multipart/alternative; 
	boundary="----=_Part_17985_2069008231.1508175573386"

------=_Part_17985_2069008231.1508175573386
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable



=D0=BF=D0=BE=D0=BD=D0=B5=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA, 16 =D0=
=BE=D0=BA=D1=82=D1=8F=D0=B1=D1=80=D1=8F 2017 =D0=B3., 18:11:02 UTC+3 =D0=BF=
=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Mingxin =
Wang=20
=D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>
> On Monday, October 16, 2017 at 8:26:57 PM UTC+8, Aleksey Loginov wrote:
>>
>> =D0=BF=D0=BE=D0=BD=D0=B5=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA, 16 =
=D0=BE=D0=BA=D1=82=D1=8F=D0=B1=D1=80=D1=8F 2017 =D0=B3., 15:08:45 UTC+3 =D0=
=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Mingx=
in Wang=20
>> =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>>>
>>> On Monday, October 16, 2017 at 6:55:41 PM UTC+8, Aleksey Loginov wrote:
>>>>
>>>> Let's look at a more applied example:
>>>> =20
>>>>
>>> template<size_t Size>=20
>>>> struct static_resource : memory_resource { aligned_storage_t<Size>=20
>>>> m_data; };
>>>>
>>>> template<typename MR>
>>>> struct my_any;
>>>>
>>>>
>>>> my_any<default_memory_resource> x1;
>>>> my_any<static_resource<32>> x2;
>>>>
>>>> x1 =3D 1;
>>>> x2 =3D x1;
>>>>
>>>> assert(x2 =3D=3D 1);
>>>>
>>>>
>>>> How can you do this without RTTI?
>>>>
>>>
>>> The class template `my_any` may declare any `my_any` types as friend=20
> have overloads of `operator=3D` for them:
>
> template <class _MR>
> friend class my_any;
>
> template <class _MR>
> my_any& operator=3D(const my_any<_MR>&);
>
> template <class _MR>
> my_any& operator=3D(my_any<_MR>&&);
>
> In order to prove that the class template `my_any` is implementable, I=20
> have roughly implemented one that supports various of constructors,=20
> `operator=3D`, `type()` and `get()`. You may use `type()` and `get()` to=
=20
> implement those non-member function templates like `any_cast`.
>
> struct manager_t {
>  public:
>   template <class T>
>   constexpr explicit manager_t(std::in_place_type_t<T>)
>       : type(typeid(T)),
>         do_copy(do_copy_impl<T>),
>         do_move(do_move_impl<T>),
>         do_destroy(do_destroy_impl<T>),
>         size(sizeof(T)) {}
>
>     template <class MR>
>   void copy(void** from, void** to, MR& mr) const {
>     if (soo_activated()) {
>       do_copy(from, to);
>     } else {
>       *to =3D mr.allocate(size, ALIGNMENT);
>       do_copy(*from, *to);
>     }
>   }
>
>     const std::type_info& type;
>
>  private:
>   void(*do_copy)(void*, void*);
>   void(*do_move)(void*, void*);
>   void(*do_destroy)(void*);
>   std::size_t size;
>
>   template <class T>
>   static inline void do_copy_impl(void* from, void* to) {
>     new (reinterpret_cast<T*>(to)) T(*reinterpret_cast<const T*>(from));
>   }
>
> };
>
> template <class T>
> inline constexpr manager_t MANAGER{std::in_place_type<T>};
>
> template <class MR>
> struct memory_resource_user {
>   MR mr_;
> };
>
> template <class MR>
> class my_any : public memory_resource_user<MR> {
>   template <class>
>   friend class my_any;
>
>  public:
>     my_any(const my_any& rhs) { copy_init(rhs); }
>
>   template <class _MR>
>   my_any(const my_any<_MR>& rhs) { copy_init(rhs); }
>
>    ~my_any() { deinit(); }
>
>  private:
>   void init() { manager_ =3D &NULL_MANAGER; }
>
>     template <class _MR>
>   void copy_init(const my_any<_MR>& rhs) {
>     manager_ =3D rhs.manager_;
>     manager_->copy(&rhs.data_, &data_, this->mr_);
>   }
>
>   void deinit() {
>     manager_->destroy(&data_, this->mr_);
>   }
>
>   const manager_t* manager_;
>   mutable void* data_;
> };
>
> Mingxin Wang
>
>
In other words, by hand-made RTTI, and only for fixed allocation=20
starategies (for example, data_ can not be a shared_ptr<T> or cow_ptr<T>)
=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/68690e5c-f466-4fbe-ab41-80be58257259%40isocpp.or=
g.

------=_Part_17985_2069008231.1508175573386
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>=D0=BF=D0=BE=D0=BD=D0=B5=D0=B4=D0=B5=D0=BB=D1=8C=
=D0=BD=D0=B8=D0=BA, 16 =D0=BE=D0=BA=D1=82=D1=8F=D0=B1=D1=80=D1=8F 2017 =D0=
=B3., 18:11:02 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=
=D0=B5=D0=BB=D1=8C Mingxin Wang =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Monday, Oc=
tober 16, 2017 at 8:26:57 PM UTC+8, Aleksey Loginov wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">=D0=BF=D0=BE=D0=BD=D0=B5=D0=B4=D0=
=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA, 16 =D0=BE=D0=BA=D1=82=D1=8F=D0=B1=D1=80=
=D1=8F 2017 =D0=B3., 15:08:45 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=
=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Mingxin Wang =D0=BD=D0=B0=D0=BF=D0=B8=D1=
=81=D0=B0=D0=BB:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-=
left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">On=
 Monday, October 16, 2017 at 6:55:41 PM UTC+8, Aleksey Loginov wrote:<block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>Let&#39;s look at a=
 more applied example:</div><div>=C2=A0<br></div></div></blockquote></div><=
/blockquote></div></blockquote></div></blockquote><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><div dir=3D"ltr"><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin:0;marg=
in-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"=
><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bord=
er-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div></div><div><=
div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187=
);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><spa=
n style=3D"color:#008">template</span><span style=3D"color:#660">&lt;</span=
><span style=3D"color:#000">size_t </span><span style=3D"color:#606">Size</=
span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> <br>=
</span><span style=3D"color:#008">struct</span><span style=3D"color:#000"> =
static_resource </span><span style=3D"color:#660">:</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:rgb(34,34,34)"><span style=3D"color:=
#000">memory_resource </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span></span><span style=3D"color:rgb(0,0,0);font-family:=
DejaVuSansMono,&quot;DejaVu Sans Mono&quot;,courier,monospace;font-size:12.=
8px;white-space:nowrap;background-color:rgb(255,255,255)"><span style=3D"co=
lor:#000">aligned_storage_t</span><span style=3D"color:#660">&lt;</span></s=
pan><span style=3D"color:rgb(102,0,102);font-family:Arial,Helvetica,sans-se=
rif">Size</span><span style=3D"color:rgb(0,0,0);font-family:DejaVuSansMono,=
&quot;DejaVu Sans Mono&quot;,courier,monospace;font-size:12.8px;white-space=
:nowrap;background-color:rgb(255,255,255)"><span style=3D"color:#660">&gt;<=
/span></span><span style=3D"font-family:Arial,Helvetica,sans-serif"><span s=
tyle=3D"color:#000"> m_data</span><span style=3D"color:#660">;</span><span =
style=3D"color:#000"> </span><span style=3D"color:#660">};</span></span></d=
iv><div><span style=3D"color:#000"><br></span><span style=3D"color:#008">te=
mplate</span><span style=3D"color:#660">&lt;</span><span><font color=3D"#00=
0000">typename MR</font></span><span style=3D"color:#660">&gt;</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#008">struct</span><sp=
an style=3D"color:#000">=C2=A0my_any;<br><br><br>my_any&lt;default_</span><=
span style=3D"color:rgb(0,0,0)">memory_resource</span><span style=3D"color:=
rgb(0,0,0);font-family:Arial,Helvetica,sans-serif"><wbr>&gt; x1;</span></di=
v><div><span style=3D"color:#000"><span>my_any&lt;</span><span style=3D"fon=
t-family:Arial,Helvetica,sans-serif">static_resource&lt;32&gt;</span><span =
style=3D"font-family:Arial,Helvetica,sans-serif">&gt; x2;</span><br><br><sp=
an style=3D"font-family:Arial,Helvetica,sans-serif">x1 =3D 1;<br>x2 =3D x1;=
<br></span><br>assert(</span><span style=3D"color:rgb(0,0,0);font-family:Ar=
ial,Helvetica,sans-serif">x2 =3D=3D 1</span><span style=3D"color:rgb(0,0,0)=
;font-family:Arial,Helvetica,sans-serif">);</span></div><div><span style=3D=
"color:#000"><br></span></div></code></div><br></div><div>How can you=C2=A0=
do this without RTTI?</div></div></blockquote><div><br></div></div></blockq=
uote></div></blockquote><div>The class template `my_any` may declare any `m=
y_any` types as friend have overloads of `operator=3D` for them:</div><div>=
<br></div><div><div style=3D"background-color:rgb(250,250,250);border-color=
:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"=
><code><div><div><div>template &lt;class _MR&gt;</div><div>friend class my_=
any;</div><div><br></div><div>template &lt;class _MR&gt;</div><div>my_any&a=
mp; operator=3D(const my_any&lt;_MR&gt;&amp;);</div><div><br></div><div>tem=
plate &lt;class _MR&gt;</div><div>my_any&amp; operator=3D(my_any&lt;_MR&gt;=
&amp;&amp;);</div></div></div></code></div><br>In order to prove that the c=
lass template `my_any` is implementable, I have roughly implemented one tha=
t supports various of constructors, `operator=3D`, `type()` and `get()`. Yo=
u may use `type()` and `get()` to implement those=C2=A0non-member function =
templates like `any_cast`.</div><div><br></div><div><div style=3D"backgroun=
d-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;b=
order-width:1px;word-wrap:break-word"><code><font color=3D"#660066"><div>st=
ruct manager_t {</div><div>=C2=A0public:</div><div>=C2=A0 template &lt;clas=
s T&gt;</div><div>=C2=A0 constexpr explicit manager_t(std::in_place_type_<w=
br>t&lt;T&gt;)</div><div>=C2=A0 =C2=A0 =C2=A0 : type(typeid(T)),</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 do_copy(do_copy_impl&lt;T&gt;),</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 do_move(do_move_impl&lt;T&gt;),</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 do_destroy(do_destroy_impl&lt;T&gt;)<wbr>,</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 size(sizeof(T)) {}</div><div><br></div><div><sp=
an style=3D"font-family: Arial, Helvetica, sans-serif;">=C2=A0 =C2=A0 templ=
ate &lt;class MR&gt;</span><br></div><div>=C2=A0 void copy(void** from, voi=
d** to, MR&amp; mr) const {</div><div>=C2=A0 =C2=A0 if (soo_activated()) {<=
/div><div>=C2=A0 =C2=A0 =C2=A0 do_copy(from, to);</div><div>=C2=A0 =C2=A0 }=
 else {</div><div>=C2=A0 =C2=A0 =C2=A0 *to =3D mr.allocate(size, ALIGNMENT)=
;</div><div>=C2=A0 =C2=A0 =C2=A0 do_copy(*from, *to);</div><div>=C2=A0 =C2=
=A0 }</div><div>=C2=A0 }</div><div><br></div><div><span style=3D"font-famil=
y: Arial, Helvetica, sans-serif;">=C2=A0 =C2=A0 const std::type_info&amp; t=
ype;</span><br></div><div><br></div><div><span style=3D"font-family: Arial,=
 Helvetica, sans-serif;">=C2=A0private:</span><br></div><div>=C2=A0 void(*d=
o_copy)(void*, void*);</div><div>=C2=A0 void(*do_move)(void*, void*);</div>=
<div>=C2=A0 void(*do_destroy)(void*);</div><div>=C2=A0 std::size_t size;</d=
iv><div><br></div><div>=C2=A0 template &lt;class T&gt;</div><div>=C2=A0 sta=
tic inline void do_copy_impl(void* from, void* to) {</div><div>=C2=A0 =C2=
=A0 new (reinterpret_cast&lt;T*&gt;(to)) T(*reinterpret_cast&lt;const T*&gt=
;(from));</div><div>=C2=A0 }</div><div><br></div><div><span style=3D"font-f=
amily: Arial, Helvetica, sans-serif;">};</span><br></div><div><br></div><di=
v>template &lt;class T&gt;</div><div>inline constexpr manager_t MANAGER{std=
::in_place_type&lt;T&gt;}<wbr>;</div><div><br></div><div><span style=3D"fon=
t-family: Arial, Helvetica, sans-serif;">template &lt;class MR&gt;</span><b=
r></div><div>struct memory_resource_user {</div><div>=C2=A0 MR mr_;</div><d=
iv>};</div><div><br></div><div><span style=3D"font-family: Arial, Helvetica=
, sans-serif;">template &lt;class MR&gt;</span><br></div><div>class my_any =
: public memory_resource_user&lt;MR&gt; {</div><div>=C2=A0 template &lt;cla=
ss&gt;</div><div>=C2=A0 friend class my_any;</div><div><br></div><div>=C2=
=A0public:</div><div><span style=3D"font-family: Arial, Helvetica, sans-ser=
if;">=C2=A0 =C2=A0 my_any(const my_any&amp; rhs) { copy_init(rhs); }</span>=
<br></div><div><br></div><div>=C2=A0 template &lt;class _MR&gt;</div><div>=
=C2=A0 my_any(const my_any&lt;_MR&gt;&amp; rhs) { copy_init(rhs); }</div><d=
iv><br></div><div>=C2=A0<span style=3D"font-family: Arial, Helvetica, sans-=
serif;">=C2=A0 ~my_any() { deinit(); }</span></div><div><br></div><div>=C2=
=A0private:</div><div>=C2=A0 void init() { manager_ =3D &amp;NULL_MANAGER; =
}</div><div><br></div><div><span style=3D"font-family: Arial, Helvetica, sa=
ns-serif;">=C2=A0 =C2=A0 template &lt;class _MR&gt;</span><br></div><div>=
=C2=A0 void copy_init(const my_any&lt;_MR&gt;&amp; rhs) {</div><div>=C2=A0 =
=C2=A0 manager_ =3D rhs.manager_;</div><div>=C2=A0 =C2=A0 manager_-&gt;copy=
(&amp;rhs.data_, &amp;data_, this-&gt;mr_);</div><div>=C2=A0 }</div><div><b=
r></div><div>=C2=A0 void deinit() {</div><div>=C2=A0 =C2=A0 manager_-&gt;de=
stroy(&amp;data_, this-&gt;mr_);</div><div>=C2=A0 }</div><div><br></div><di=
v>=C2=A0 const manager_t* manager_;</div><div>=C2=A0 mutable void* data_;</=
div><div>};<br></div></font></code></div><br>Mingxin Wang</div><div><br></d=
iv></div></blockquote><div><br></div><div>In other words, by hand-made RTTI=
, and only for fixed allocation starategies (for example, data_ can not be =
a shared_ptr&lt;T&gt; or cow_ptr&lt;T&gt;)</div><div>=C2=A0</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/68690e5c-f466-4fbe-ab41-80be58257259%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/68690e5c-f466-4fbe-ab41-80be58257259=
%40isocpp.org</a>.<br />

------=_Part_17985_2069008231.1508175573386--

------=_Part_17984_1292694928.1508175573386--

.
