220 19152 <CAOfiQqm_ejkoWUXjZObU_4YXEXS1DwVARryUTrBbVDwKejz1vQ@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Richard Smith <richard@metafoo.co.uk>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: New type of "new"/"delete" override
Date: Tue, 21 Jul 2015 14:24:06 -0700
Lines: 390
Approved: news@gmane.org
Message-ID: <CAOfiQqm_ejkoWUXjZObU_4YXEXS1DwVARryUTrBbVDwKejz1vQ@mail.gmail.com>
References: <2328a5fd-924c-4d02-ac18-6a225f786dec@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=bcaec52d52dd2feea4051b69467a
X-Trace: ger.gmane.org 1437513868 26069 80.91.229.3 (21 Jul 2015 21:24:28 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 21 Jul 2015 21:24:28 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDVNBJG4YAIBB57QXKWQKGQEY6IYUYA@isocpp.org Tue Jul 21 23:24:12 2015
Return-path: <std-proposals+bncBDVNBJG4YAIBB57QXKWQKGQEY6IYUYA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f200.google.com ([209.85.220.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDVNBJG4YAIBB57QXKWQKGQEY6IYUYA@isocpp.org>)
	id 1ZHf1E-0004M1-LD
	for gclcip-std-proposals@m.gmane.org; Tue, 21 Jul 2015 23:24:08 +0200
Original-Received: by qkez4 with SMTP id z4sf295496250qke.2
        for <gclcip-std-proposals@m.gmane.org>; Tue, 21 Jul 2015 14:24:07 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:date
         :message-id:subject:from:to:content-type: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=3x/zEk3sLVd8KwtWOmDuMYd6g/KoUCqapYEyqmlyNnI=;
        b=MqT0m4aVTrSHYH+NPpf3s0GEPOmBgV36IjOigib+yGVGBuLHSnI3TgOGOqcFeJDLIw
         WqGfRW0W07oL9Fpmy6zlcD0VxhGAR6tdKo+p+weIY5DeASpshahRUb/HZlX625O/eF0d
         rUenPeOFFlAxTUhBzinUL5U/C/EPFyhs/4h26FbGKGJ0gXW9r2X/qMILQDtAL5FLyQ40
         eWclLuWraZ1Ck5w68N3pNsRq3BXRdmeMI6kQbRjaGHv88iSxr3MG50JQNVN1BdDbwnW5
         hRD3VtJqQtR3uThHNUWFh7rvOLbEqNP7uaCojVw0CgdJWGp6d1dxOJDKAe6wmty5qgbO
         JsJQ==
X-Gm-Message-State: ALoCoQlrdkP0LevbAWfiUUYXUKH6bSAGGmg0XAhXTInmyzHtgJTsW+f7C0wDFq3Vt1hUSVMVKRff
X-Received: by 10.140.151.65 with SMTP id 62mr36660565qhx.1.1437513847876;
        Tue, 21 Jul 2015 14:24:07 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.92.10 with SMTP id a10ls4180367qge.94.gmail; Tue, 21 Jul
 2015 14:24:06 -0700 (PDT)
X-Received: by 10.52.244.40 with SMTP id xd8mr45464540vdc.2.1437513846762;
        Tue, 21 Jul 2015 14:24:06 -0700 (PDT)
Original-Received: from mail-vn0-x236.google.com (mail-vn0-x236.google.com. [2607:f8b0:400c:c0f::236])
        by mx.google.com with ESMTPS id xw1si25331894vdb.28.2015.07.21.14.24.06
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 21 Jul 2015 14:24:06 -0700 (PDT)
Received-SPF: pass (google.com: domain of metafoo@gmail.com designates 2607:f8b0:400c:c0f::236 as permitted sender) client-ip=2607:f8b0:400c:c0f::236;
Original-Received: by vnav141 with SMTP id v141so41026169vna.0
        for <std-proposals@isocpp.org>; Tue, 21 Jul 2015 14:24:06 -0700 (PDT)
X-Received: by 10.52.135.4 with SMTP id po4mr45355034vdb.78.1437513846613;
 Tue, 21 Jul 2015 14:24:06 -0700 (PDT)
Original-Sender: metafoo@gmail.com
Original-Received: by 10.31.75.2 with HTTP; Tue, 21 Jul 2015 14:24:06 -0700 (PDT)
In-Reply-To: <2328a5fd-924c-4d02-ac18-6a225f786dec@isocpp.org>
X-Original-Sender: richard@metafoo.co.uk
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of metafoo@gmail.com designates 2607:f8b0:400c:c0f::236 as permitted
 sender) smtp.mail=metafoo@gmail.com;       dkim=pass header.i=@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:19152
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19152>

--bcaec52d52dd2feea4051b69467a
Content-Type: text/plain; charset=UTF-8

On Tue, Jul 21, 2015 at 12:37 PM, Myriachan <myriachan@gmail.com> wrote:

> In trying to implement a custom memory allocator, there are many
> annoyances that come up that make C++ difficult to work with.
> Particularly, the syntax of the new and delete operators means that using
> a custom memory allocator often involves macros that are semantically
> different from new and delete.
>

Can you explain a bit more about the problem? It's really not clear to me
what the motivation for this change is. Why can't you / don't you want to
use a custom placement operator new for this?


> When private and protected constructors and destructors get involved,
> things get especially annoying, because the allocator code can't call the
> constructor or destructor itself.
>
> I thought of an idea that would help with this issue, though it is
> admittedly rather crazy.
>
> I would add a new type of operator new overload:
>
> template <typename Type, typename Constructor>
> Type *operator new valloc_new(const Constructor &constructor)
>     noexcept(noexcept(constructor(static_cast<Type *>(nullptr))))
> {
>     static_assert(alignof(Type) <= PAGE_SIZE, "only allocations of
> alignment PAGE_SIZE or less are supported") ;
>
>     std::size_t headerSize = 0;
>
>     // Custom implementations aren't required to use new_handlers
>     void *memory = VirtualAlloc(nullptr, headerSize + sizeof(Type),
> MEM_COMMIT, PAGE_READWRITE);
>     if (!memory)
>     {
>         throw std::bad_alloc("out of memory");
>     }
>
>     try
>     {
>         return constructor(memory);
>     }
>     catch (...)
>     {
>         VirtualFree(memory, 0, MEM_RELEASE);
>         throw;
>     }
> }
>
> template <typename Type, typename Destructor>
> void operator delete valloc_delete(Type *object, const Destructor &
> destructor)
> {
>     if (object == nullptr)
>     {
>         return;
>     }
>
>     // Get the base address of the most-derived object
>     void *memory = const_cast<std::remove_cv_t<Type> *>(object);
>     if (std::is_polymorphic<Type>::value)
>     {
>         memory = dynamic_cast<void *>(const_cast<std::remove_cv_t<Type>
> *>(object));
>     }
>
>     destructor(object);
>
>     VirtualFree(memory, 0, MEM_RELEASE);
> }
>
>
>
> Now valloc_new and valloc_delete in the proper scope will syntactically
> function the same way as the new and delete keywords, in a way becoming
> keywords themselves.  I think that it would be worthwhile to allow these to
> be scoped to namespaces or classes.
>
> The private constructor/destructor problem is solved, because they are
> passed in as lambdas (or function pointers, at implementation discretion).
>
> We can redefine the basic implementation of the "new" keyword to be an
> implementation-defined template function that calls ::operator new(size_t)
> and does other things, like dynamic_cast<void *> if the type is
> polymorphic.  Overriding the global new would work by replacing this
> template or its overloads.
>
> template <typename Type, typename Constructor, typename... Args>
> Type *operator new new(const Constructor &constructor, Args &&...args)
>     noexcept(
>         noexcept(constructor(static_cast<Type *>(nullptr))) &&
>         noexcept(::operator new(std::size_t(), std::forward<Args>(args
> )...)));
>
>
> Melissa
>
> --
>
> ---
> 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.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--bcaec52d52dd2feea4051b69467a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Jul 21, 2015 at 12:37 PM, Myriachan <span dir=3D"ltr">&lt;<a href=3D"ma=
ilto:myriachan@gmail.com" target=3D"_blank">myriachan@gmail.com</a>&gt;</sp=
an> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">In trying to =
implement a custom memory allocator, there are many annoyances that come up=
 that make C++ difficult to work with.=C2=A0 Particularly, the syntax of th=
e <span style=3D"font-family:courier new,monospace">new</span> and <span st=
yle=3D"font-family:courier new,monospace">delete</span> operators means tha=
t using a custom memory allocator often involves macros that are semantical=
ly different from <span style=3D"font-family:courier new,monospace">new</sp=
an> and <span style=3D"font-family:courier new,monospace">delete</span>.</d=
iv></blockquote><div><br></div><div>Can you explain a bit more about the pr=
oblem? It&#39;s really not clear to me what the motivation for this change =
is. Why can&#39;t you / don&#39;t you want to use a custom placement operat=
or new for this?</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"ltr">When private and protected constructors and destructors get inv=
olved, things get especially annoying, because the allocator code can&#39;t=
 call the constructor or destructor itself.<br><br>I thought of an idea tha=
t would help with this issue, though it is admittedly rather crazy.<br><br>=
I would add a new type of <span style=3D"font-family:courier new,monospace"=
>operator new</span> overload:<br><br><div style=3D"background-color:rgb(25=
0,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1p=
x;word-wrap:break-word"><code><div><span style=3D"color:#008">template</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span>=
<span style=3D"color:#008">typename</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">Type</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#008">typename</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">Constructor=
</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br=
></span><span style=3D"color:#606">Type</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">*</span><span style=3D"color:#008">operato=
r</span><span style=3D"color:#000"> </span><span style=3D"color:#008">new</=
span><span style=3D"color:#000"> valloc_new</span><span style=3D"color:#660=
">(</span><span style=3D"color:#008">const</span><span style=3D"color:#000"=
> </span><span style=3D"color:#606">Constructor</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">&amp;</span><span style=3D"color:#=
000">constructor</span><span style=3D"color:#660">)</span><span style=3D"co=
lor:#000"><br>=C2=A0 =C2=A0 noexcept</span><span style=3D"color:#660">(</sp=
an><span style=3D"color:#000">noexcept</span><span style=3D"color:#660">(</=
span><span style=3D"color:#000">constructor</span><span style=3D"color:#660=
">(</span><span style=3D"color:#008">static_cast</span><span style=3D"color=
:#660">&lt;</span><span style=3D"color:#606">Type</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">*&gt;(</span><span style=3D"colo=
r:#008">nullptr</span><span style=3D"color:#660">))))</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"co=
lor:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">static_assert=
</span><span style=3D"color:#660">(</span><span style=3D"color:#008">aligno=
f</span><span style=3D"color:#660">(</span><span style=3D"color:#606">Type<=
/span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">&lt;=3D</span><span style=3D"color:#000"> PAGE_=
SIZE</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#080">&quot;only allocations of alignment PAGE_S=
IZE or less are supported&quot;</span><span style=3D"color:#660">)</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br><br>=C2=A0 =C2=A0 std</span><span style=3D"color:#6=
60">::</span><span style=3D"color:#000">size_t headerSize </span><span styl=
e=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">0</span><span style=3D"color:#660">;</span><span style=3D"c=
olor:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">// Custo=
m implementations aren&#39;t required to use new_handlers</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">void</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">*</span><=
span style=3D"color:#000">memory </span><span style=3D"color:#660">=3D</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">VirtualAllo=
c</span><span style=3D"color:#660">(</span><span style=3D"color:#008">nullp=
tr</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> hea=
derSize </span><span style=3D"color:#660">+</span><span style=3D"color:#000=
"> </span><span style=3D"color:#008">sizeof</span><span style=3D"color:#660=
">(</span><span style=3D"color:#606">Type</span><span style=3D"color:#660">=
),</span><span style=3D"color:#000"> MEM_COMMIT</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> PAGE_READWRITE</span><span style=
=3D"color:#660">);</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#008">if</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#660">(!</span><span style=3D"color:#000">memory</span><=
span style=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><b=
r>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">throw</span=
><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</span>=
<span style=3D"color:#000">bad_alloc</span><span style=3D"color:#660">(</sp=
an><span style=3D"color:#080">&quot;out of memory&quot;</span><span style=
=3D"color:#660">);</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><span style=3D"color:#660">}</span><span style=3D"color:#000"><br><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008">try</span><span style=3D"color=
:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span st=
yle=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"co=
lor:#008">return</span><span style=3D"color:#000"> constructor</span><span =
style=3D"color:#660">(</span><span style=3D"color:#000">memory</span><span =
style=3D"color:#660">);</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =
</span><span style=3D"color:#660">}</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#008">catch</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">(...)</span><span style=3D"c=
olor:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><spa=
n style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=
=3D"color:#606">VirtualFree</span><span style=3D"color:#660">(</span><span =
style=3D"color:#000">memory</span><span style=3D"color:#660">,</span><span =
style=3D"color:#000"> </span><span style=3D"color:#066">0</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> MEM_RELEASE</span><span=
 style=3D"color:#660">);</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 </span><span style=3D"color:#008">throw</span><span style=3D=
"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><s=
pan style=3D"color:#660">}</span><span style=3D"color:#000"><br></span><spa=
n style=3D"color:#660">}</span><span style=3D"color:#000"><br><br></span><s=
pan style=3D"color:#008">template</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</=
span><span style=3D"color:#000"> </span><span style=3D"color:#606">Type</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">typename</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#606">Destructor</span><span style=3D"color:#660">&gt;=
</span><span style=3D"color:#000"><br></span><span style=3D"color:#008">voi=
d</span><span style=3D"color:#000"> </span><span style=3D"color:#008">opera=
tor</span><span style=3D"color:#000"> </span><span style=3D"color:#008">del=
ete</span><span style=3D"color:#000"> valloc_delete</span><span style=3D"co=
lor:#660">(</span><span style=3D"color:#606">Type</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">*</span><span style=3D"color:#00=
8">object</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">const</span><span style=3D"color:#000=
"> </span><span style=3D"color:#606">Destructor</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">&amp;</span><span style=3D"color:#=
000">destructor</span><span style=3D"color:#660">)</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#660">{</span><span style=3D"color=
:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">if</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">(</span><span style=
=3D"color:#008">object</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">nullptr</span><span style=3D"color:#660">)</span><span styl=
e=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</spa=
n><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span s=
tyle=3D"color:#008">return</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</=
span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D=
"color:#800">// Get the base address of the most-derived object</span><span=
 style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">v=
oid</span><span style=3D"color:#000"> </span><span style=3D"color:#660">*</=
span><span style=3D"color:#000">memory </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#008">con=
st_cast</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#0=
00">std</span><span style=3D"color:#660">::</span><span style=3D"color:#000=
">remove_cv_t</span><span style=3D"color:#660">&lt;</span><span style=3D"co=
lor:#606">Type</span><span style=3D"color:#660">&gt;</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">*&gt;(</span><span style=3D"c=
olor:#008">object</span><span style=3D"color:#660">);</span><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">if</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span s=
tyle=3D"color:#000">std</span><span style=3D"color:#660">::</span><span sty=
le=3D"color:#000">is_polymorphic</span><span style=3D"color:#660">&lt;</spa=
n><span style=3D"color:#606">Type</span><span style=3D"color:#660">&gt;::</=
span><span style=3D"color:#000">value</span><span style=3D"color:#660">)</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
memory </span><span style=3D"color:#660">=3D</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">dynamic_cast</span><span style=3D"col=
or:#660">&lt;</span><span style=3D"color:#008">void</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#660">*&gt;(</span><span style=3D"co=
lor:#008">const_cast</span><span style=3D"color:#660">&lt;</span><span styl=
e=3D"color:#000">std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">remove_cv_t</span><span style=3D"color:#660">&lt;</span><sp=
an style=3D"color:#606">Type</span><span style=3D"color:#660">&gt;</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">*&gt;(</span><s=
pan style=3D"color:#008">object</span><span style=3D"color:#660">));</span>=
<span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0 destructor</sp=
an><span style=3D"color:#660">(</span><span style=3D"color:#008">object</sp=
an><span style=3D"color:#660">);</span><span style=3D"color:#000"><br><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#606">VirtualFree</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#000">memory</span><span sty=
le=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D=
"color:#066">0</span><span style=3D"color:#660">,</span><span style=3D"colo=
r:#000"> MEM_RELEASE</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div></code>=
</div><br><br><br>Now <span style=3D"font-family:courier new,monospace">val=
loc_new</span> and <span style=3D"font-family:courier new,monospace">valloc=
_delete</span> in the proper scope will syntactically function the same way=
 as the <span style=3D"font-family:courier new,monospace">new</span> and <s=
pan style=3D"font-family:courier new,monospace">delete</span> keywords, in =
a way becoming keywords themselves.=C2=A0 I think that it would be worthwhi=
le to allow these to be scoped to namespaces or classes.<br><br>The private=
 constructor/destructor problem is solved, because they are passed in as la=
mbdas (or function pointers, at implementation discretion).<br><br>We can r=
edefine the basic implementation of the &quot;new&quot; keyword to be an im=
plementation-defined template function that calls <span style=3D"font-famil=
y:courier new,monospace">::operator new(size_t)</span> and does other thing=
s, like <span style=3D"font-family:courier new,monospace">dynamic_cast&lt;v=
oid *&gt;</span> if the type is polymorphic.=C2=A0 Overriding the global ne=
w would work by replacing this template or its overloads.<br><br><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><span style=
=3D"color:#008">template</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">Type</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#606">Constructor</span><span style=3D"color:#660">,</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#008">typename</span><s=
pan style=3D"color:#660">...</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#606">Args</span><span style=3D"color:#660">&gt;</span><spa=
n style=3D"color:#000"><br></span><span style=3D"color:#606">Type</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">*</span><span st=
yle=3D"color:#008">operator</span><span style=3D"color:#000"> </span><span =
style=3D"color:#008">new</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#008">new</span><span style=3D"color:#660">(</span><span style=
=3D"color:#008">const</span><span style=3D"color:#000"> </span><span style=
=3D"color:#606">Constructor</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">&amp;</span><span style=3D"color:#000">constructor</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#606">Args</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">&amp;&amp;...</span><span style=3D"color:#000">args<=
/span><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 noexcept</span><span style=3D"color:#660">(</span><span style=3D=
"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 noexcept</span><span style=3D"=
color:#660">(</span><span style=3D"color:#000">constructor</span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#008">static_cast</span><span=
 style=3D"color:#660">&lt;</span><span style=3D"color:#606">Type</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">*&gt;(</span><spa=
n style=3D"color:#008">nullptr</span><span style=3D"color:#660">)))</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">&amp;&amp;</sp=
an><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 noexcept</spa=
n><span style=3D"color:#660">(::</span><span style=3D"color:#008">operator<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">new</sp=
an><span style=3D"color:#660">(</span><span style=3D"color:#000">std</span>=
<span style=3D"color:#660">::</span><span style=3D"color:#000">size_t</span=
><span style=3D"color:#660">(),</span><span style=3D"color:#000"> std</span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">forward</sp=
an><span style=3D"color:#660">&lt;</span><span style=3D"color:#606">Args</s=
pan><span style=3D"color:#660">&gt;(</span><span style=3D"color:#000">args<=
/span><span style=3D"color:#660">)...)));</span></div></code></div><br><br>=
Melissa</div><span class=3D"HOEnZb"><font color=3D"#888888">

<p></p>

-- <br>
<br>
--- <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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--bcaec52d52dd2feea4051b69467a--

.
