Topic: std::any: Add a way to obtain a void* to the


Author: stackmachine@hotmail.com
Date: Sat, 19 Oct 2013 05:11:05 -0700 (PDT)
Raw View
------=_Part_91_6080867.1382184665060
Content-Type: text/plain; charset=ISO-8859-1

Neither boost::any, nor the proposed version of std::any allow me to obtain
a pointer to the stored value without knowing the stored type. This makes
std::any unusable for any kind of type erasure.
Is there a specific reason why this rather basic functionality is missing?

--

---
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/.

------=_Part_91_6080867.1382184665060
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Neither boost::any, nor the proposed version of std::any a=
llow me to obtain a pointer to the stored value without knowing the stored =
type. This makes std::any unusable for any kind of type erasure.<br>Is ther=
e a specific reason why this rather basic functionality is missing?<br></di=
v>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

------=_Part_91_6080867.1382184665060--

.


Author: Christopher Jefferson <chris@bubblescope.net>
Date: Sat, 19 Oct 2013 13:13:42 +0100
Raw View
On 19 October 2013 13:11,  <stackmachine@hotmail.com> wrote:
> Neither boost::any, nor the proposed version of std::any allow me to obtain
> a pointer to the stored value without knowing the stored type. This makes
> std::any unusable for any kind of type erasure.
> Is there a specific reason why this rather basic functionality is missing?

What use would such a pointer be, if you don't know the type? (that
isn't sarcasm, I am interested to know your use case).

Chris

>
> --
>
> ---
> 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/.

.


Author: stackmachine@hotmail.com
Date: Sat, 19 Oct 2013 05:46:28 -0700 (PDT)
Raw View
------=_Part_107_2569037.1382186788643
Content-Type: text/plain; charset=ISO-8859-1

Here is simple example of code that should work with std::any:
#include <iostream>

struct TypeErased
{
    template <typename T>
    TypeErased(T&& value)
        : value_(std::forward<T>(t)), doPrint_(&TypeErased::doPrint<T>)
    {}

    void print()
    {
        doPrint_(value_.ptr());
    }

private:
    template <typename T>
    static void doPrint(void* ptr)
    {
        std::cout << *static_cast<T*>(ptr);
    }

    std::any value_;
    void (* doPrint_) (void*);
};

int main()
{
    TypeErased x(42);
    x.print();
}
This piece of code stores a value into the any and a function pointer to an
instantiation of doPrint for the correct type. Thus the stored type is
implicitly known, but not within print(). Using .ptr(), a void* to the
value is obtained and passed to the print function which does a cast to the
correct type.

This is a common type erasure pattern, std::any should support it.

--

---
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/.

------=_Part_107_2569037.1382186788643
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Here is simple example of code that should work with std::=
any:<br><div class=3D"prettyprint" 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 class=3D"prettyprint"><div class=3D"sub=
prettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettify">#inc=
lude</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;iostream&gt=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">TypeErased</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">TypeErased</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&amp;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> value</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&=
nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> value_</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">forward</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">t</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)),</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> doPrint_</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(&amp;</span><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">TypeErased</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">doPrint</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;)</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">{}</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <=
br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">print</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbs=
p; &nbsp; doPrint_</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">v=
alue_</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">ptr</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">());</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">private</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">static</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> doPrint</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">void</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> ptr</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nb=
sp; std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">cout </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">static_cast</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">*&gt;(</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">ptr</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br><br>&nbsp; &nbsp; std</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">any value_</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(*</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> doPrint_</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">*);</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> main</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">TypeErased</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #066;" class=3D"styled-by-prettify">42</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; x</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">.</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">print</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">}</span></div></code></div>This piece of code stores a value into the=
 any and a function pointer to an instantiation of doPrint for the correct =
type. Thus the stored type is implicitly known, but not within print(). Usi=
ng .ptr(), a void* to the value is obtained and passed to the print functio=
n which does a cast to the correct type.<br><br>This is a common type erasu=
re pattern, std::any should support it.<br></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

------=_Part_107_2569037.1382186788643--

.


Author: Xavi <gratal@gmail.com>
Date: Sat, 19 Oct 2013 09:14:41 -0400
Raw View
--Apple-Mail-60F7AD01-1505-4B4F-890B-1986AE414F19
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Why not have doPrint take a reference to std::any? I fail to see any case w=
here you really need the void*, since std::any is just a safer form of it, =
with its functionality of being castable to the right type.

     xavi

> On 19 okt 2013, at 08:46, stackmachine@hotmail.com wrote:
>=20
> Here is simple example of code that should work with std::any:
> #include <iostream>
>=20
> struct TypeErased
> {
>     template <typename T>
>     TypeErased(T&& value)
>         : value_(std::forward<T>(t)), doPrint_(&TypeErased::doPrint<T>)
>     {}
>    =20
>     void print()
>     {
>         doPrint_(value_.ptr());
>     }
>    =20
> private:
>     template <typename T>
>     static void doPrint(void* ptr)
>     {
>         std::cout << *static_cast<T*>(ptr);
>     }
>=20
>     std::any value_;
>     void (* doPrint_) (void*);
> };
>=20
> int main()
> {
>     TypeErased x(42);
>     x.print();
> }
> This piece of code stores a value into the any and a function pointer to =
an instantiation of doPrint for the correct type. Thus the stored type is i=
mplicitly known, but not within print(). Using .ptr(), a void* to the value=
 is obtained and passed to the print function which does a cast to the corr=
ect type.
>=20
> This is a common type erasure pattern, std::any should support it.
> --=20
> =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=
 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-propo=
sals/.

--=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/.

--Apple-Mail-60F7AD01-1505-4B4F-890B-1986AE414F19
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=
=3Dutf-8"></head><body dir=3D"auto"><div>Why not have doPrint take a refere=
nce to std::any? I fail to see any case where you really need the void*, si=
nce std::any is just a safer form of it, with its functionality of being ca=
stable to the right type.<br><br>&nbsp; &nbsp; &nbsp;xavi</div><div><br>On =
19 okt 2013, at 08:46, <a href=3D"mailto:stackmachine@hotmail.com">stackmac=
hine@hotmail.com</a> wrote:<br><br></div><blockquote type=3D"cite"><div><di=
v dir=3D"ltr">Here is simple example of code that should work with std::any=
:<br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 25=
0); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1p=
x; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span style=3D"color: #800;" class=3D"styled-by-prettify">#includ=
e</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;iostream&gt;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">TypeErased</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">TypeErased</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&amp;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 value</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &n=
bsp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 value_</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">forward</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">t</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)),</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> doPrint_</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(&amp;</span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">TypeErased</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">do=
Print</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;)</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">{}</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br>&nb=
sp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>void</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">print</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nb=
sp; doPrint_</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">value_<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">ptr</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">());</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; <br></span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">private</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">static</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> doPrint</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">vo=
id</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> ptr</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; s=
td</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">static_cast</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">*&gt;(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">ptr</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br><br>&nbsp; &nbsp; std</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">any value_</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">void</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(*</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> doPrint_</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">void</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> main<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">TypeErased</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">42</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>&nbsp; &nbsp; x</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">.</span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">print</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span></div></code></div>This piece of code stores a value into the any and=
 a function pointer to an instantiation of doPrint for the correct type. Th=
us the stored type is implicitly known, but not within print(). Using .ptr(=
), a void* to the value is obtained and passed to the print function which =
does a cast to the correct type.<br><br>This is a common type erasure patte=
rn, std::any should support it.<br></div>

<p></p>

-- <br>
&nbsp;<br>
--- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" 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>
</div></blockquote></body></html>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

--Apple-Mail-60F7AD01-1505-4B4F-890B-1986AE414F19--

.


Author: stackmachine@hotmail.com
Date: Sat, 19 Oct 2013 06:47:30 -0700 (PDT)
Raw View
------=_Part_89_858946.1382190450724
Content-Type: text/plain; charset=ISO-8859-1

any_cast uses dynamic_cast, that's unnecessary overhead.

--

---
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/.

------=_Part_89_858946.1382190450724
Content-Type: text/html; charset=ISO-8859-1

<div dir="ltr">any_cast uses dynamic_cast, that's unnecessary overhead.<br></div>

<p></p>

-- <br />
&nbsp;<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 email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

------=_Part_89_858946.1382190450724--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Sat, 19 Oct 2013 15:54:14 +0200
Raw View
2013/10/19  <stackmachine@hotmail.com>:
> any_cast uses dynamic_cast, that's unnecessary overhead.

The effect of any_cast is similar to that of std::function's target()
function: It compares two type_info objects by equality, but there is
no dynamic_cast involved.

- Daniel

--

---
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/.

.


Author: stackmachine@hotmail.com
Date: Sat, 19 Oct 2013 07:53:37 -0700 (PDT)
Raw View
------=_Part_108_33011950.1382194417062
Content-Type: text/plain; charset=ISO-8859-1

That's still some kind of overhead.

--

---
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/.

------=_Part_108_33011950.1382194417062
Content-Type: text/html; charset=ISO-8859-1

<div dir="ltr">That's still some kind of overhead.<br></div>

<p></p>

-- <br />
&nbsp;<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 email to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />

------=_Part_108_33011950.1382194417062--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Sat, 19 Oct 2013 17:11:39 +0200
Raw View
2013/10/19  <stackmachine@hotmail.com>:
> That's still some kind of overhead.

The access to the underlying object should be exactly equal to your
suggested function returning void*, except the additional test of two
type_info objects that were obtained from compile-time known types, so
this is no additional "polymorphic" overhead.

Did you have tested the performance overhead compared to your
envisioned access? Some data would be nice to have.

Given the fact that std::any claims to be a "typesafe void*", such a
function providing direct access to void* makes me a bit nervous at
the moment, especially since I'm not seeing comparable access to the
underlying object by similar types such as std::function::target or
std::shared_ptr's get_deleter template.

If we have the general feeling that such direct access to underlying
objects should be provided, I would like to see a more general
protocol for this (e.g. via a trait-like template that could be
specialized for types that we would consider as good candidates. So, I
think, missing to provide that feature now could be changed in the
future.

- Daniel

--

---
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/.

.


Author: Jeffrey Yasskin <jyasskin@google.com>
Date: Mon, 21 Oct 2013 09:45:44 -0700
Raw View
On Sat, Oct 19, 2013 at 7:53 AM,  <stackmachine@hotmail.com> wrote:
> That's still some kind of overhead.

In general, when you make an assertion like this, you need to include
benchmark results proving it. Performance is not obvious.

--

---
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/.

.


Author: Beman Dawes <bdawes@acm.org>
Date: Mon, 21 Oct 2013 21:45:41 -0400
Raw View
--047d7b6221eaef113004e94a8e18
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Oct 19, 2013 at 8:11 AM, <stackmachine@hotmail.com> wrote:

> Neither boost::any, nor the proposed version of std::any allow me to
> obtain a pointer to the stored value without knowing the stored type. This
> makes std::any unusable for any kind of type erasure.
>

Does boost::unsafe_any_cast meet your need?


> Is there a specific reason why this rather basic functionality is missing?
>

I'm guessing that unsafe_any_cast has been sufficient for Boost users.
IIRC, the Adobe implementation also has unsafe_any_cast, and the Adobe
folks think it should be included in the TS.

One good way to kill a proposal to the committee is to load it up with
every feature anyone could ever conceivably use. A better way is to submit
a proposal with core functionality that meets many users needs, and get it
accepted. Then submit small proposals or issues for added features. If they
get accepted, fine, but if committee members strongly dislike a particular
proposed feature it doesn't put the core parts at risk.

--Beman

--

---
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/.

--047d7b6221eaef113004e94a8e18
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
at, Oct 19, 2013 at 8:11 AM,  <span dir=3D"ltr">&lt;<a href=3D"mailto:stack=
machine@hotmail.com" target=3D"_blank">stackmachine@hotmail.com</a>&gt;</sp=
an> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Neither =
boost::any, nor the proposed version of std::any allow me to obtain a point=
er to the stored value without knowing the stored type. This makes std::any=
 unusable for any kind of type erasure.<br>
</div></blockquote><div><br></div><div>Does boost::unsafe_any_cast meet you=
r need?<br></div><div>=A0</div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left=
:1ex">
<div dir=3D"ltr">Is there a specific reason why this rather basic functiona=
lity is missing?<span class=3D""></span><br></div></blockquote><div><br></d=
iv><div>I&#39;m guessing that unsafe_any_cast has been sufficient for Boost=
 users. IIRC, the Adobe implementation also has=A0unsafe_any_cast, and the =
Adobe folks think it should be included in the TS.<br>
<br></div><div>One good way to kill a proposal to the committee is to load =
it up with every feature anyone could ever conceivably use. A better way is=
 to submit a proposal with core functionality that meets many users needs, =
and get it accepted. Then submit small proposals or issues for added featur=
es. If they get accepted, fine, but if committee members strongly dislike a=
 particular proposed feature it doesn&#39;t put the core parts at risk.<br>
<br></div><div>--Beman<br> </div></div></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

--047d7b6221eaef113004e94a8e18--

.


Author: stackmachine@hotmail.com
Date: Tue, 22 Oct 2013 00:35:31 -0700 (PDT)
Raw View
------=_Part_3061_9635726.1382427331431
Content-Type: text/plain; charset=ISO-8859-1



Am Dienstag, 22. Oktober 2013 03:45:41 UTC+2 schrieb Beman Dawes:
>
> On Sat, Oct 19, 2013 at 8:11 AM, <stackm...@hotmail.com <javascript:>>wrote:
>
>> Neither boost::any, nor the proposed version of std::any allow me to
>> obtain a pointer to the stored value without knowing the stored type. This
>> makes std::any unusable for any kind of type erasure.
>>
>
> Does boost::unsafe_any_cast meet your need?
>
No. unsafe_any_cast is something different. Casting from holder<T> to
holder<void> is different than obtaining a void* to the value. (I'm not
even sure if holder<void> can be instantiated.) It would have to be a
virtual member function of holder.

--

---
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/.

------=_Part_3061_9635726.1382427331431
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>Am Dienstag, 22. Oktober 2013 03:45:41 UTC+2 schri=
eb Beman Dawes:<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=
"><div><div class=3D"gmail_quote">On Sat, Oct 19, 2013 at 8:11 AM,  <span d=
ir=3D"ltr">&lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mai=
lto=3D"Lby-fqBbFfMJ">stackm...@hotmail.com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">Neither =
boost::any, nor the proposed version of std::any allow me to obtain a point=
er to the stored value without knowing the stored type. This makes std::any=
 unusable for any kind of type erasure.<br>
</div></blockquote><div><br></div><div>Does boost::unsafe_any_cast meet you=
r need?</div></div></div></div></blockquote><div>No. unsafe_any_cast is som=
ething different. Casting from holder&lt;T&gt; to holder&lt;void&gt; is dif=
ferent than obtaining a void* to the value. (I'm not even sure if holder&lt=
;void&gt; can be instantiated.) It would have to be a virtual member functi=
on of holder. <br></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

------=_Part_3061_9635726.1382427331431--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Tue, 22 Oct 2013 09:48:16 +0200
Raw View
2013/10/22  <stackmachine@hotmail.com>:
>
>
> Am Dienstag, 22. Oktober 2013 03:45:41 UTC+2 schrieb Beman Dawes:
>>
>> On Sat, Oct 19, 2013 at 8:11 AM, <stackm...@hotmail.com> wrote:
>>>
>>> Neither boost::any, nor the proposed version of std::any allow me to
>>> obtain a pointer to the stored value without knowing the stored type. This
>>> makes std::any unusable for any kind of type erasure.
>>
>>
>> Does boost::unsafe_any_cast meet your need?
>
> No. unsafe_any_cast is something different. Casting from holder<T> to
> holder<void> is different than obtaining a void* to the value. (I'm not even
> sure if holder<void> can be instantiated.) It would have to be a virtual
> member function of holder.

You are misunderstanding Beman's suggestion. The (undocumented) trick
is to perform

boost::unsafe_any_cast<void*>

on a pointer to boost::any, which gives you essentially the void**
address of the underlying object. So, I believe this function
essentially gives you what you want.

- Daniel

--

---
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/.

.


Author: stackmachine@hotmail.com
Date: Tue, 22 Oct 2013 01:01:49 -0700 (PDT)
Raw View
------=_Part_3219_4508053.1382428909827
Content-Type: text/plain; charset=ISO-8859-1

Here's the code of unsafe_any_cast:

template<typename ValueType>
inline ValueType * unsafe_any_cast(any * operand) BOOST_NOEXCEPT
{
        return &static_cast<any::holder<ValueType> *>(operand->content)->held;
}

If I instantiate this template, I get a static_cast<any::holder<void*>*>.
This is UB.

--

---
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/.

------=_Part_3219_4508053.1382428909827
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><code>Here's the code of unsafe_any_cast:</code><br><div c=
lass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-=
color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wra=
p: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><=
pre><span style=3D"color: #008;" class=3D"styled-by-prettify">template</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">ValueType</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">inline</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"sty=
led-by-prettify">ValueType</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> u=
nsafe_any_cast</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">any <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> operand</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> BOOST_NOEXCEPT<br></span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp;=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">static_cast</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">any</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">holder</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">ValueType</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">*&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">op=
erand</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">content</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">)-&gt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">held</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">}</span></pre></div></code></div>If I =
instantiate this template, I get a static_cast&lt;any::holder&lt;void*&gt;*=
&gt;. This is UB.<br></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

------=_Part_3219_4508053.1382428909827--

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Tue, 22 Oct 2013 10:08:51 +0200
Raw View
2013/10/22  <stackmachine@hotmail.com>:
> Here's the code of unsafe_any_cast:
>
> template<typename ValueType>
> inline ValueType * unsafe_any_cast(any * operand) BOOST_NOEXCEPT
> {
>         return &static_cast<any::holder<ValueType>
> *>(operand->content)->held;
> }
>
> If I instantiate this template, I get a static_cast<any::holder<void*>*>.
> This is UB.

Please look at the suggestion from the view-point of an API
suggestion, not by looking into the code. It all depends what the
specification would be and a library internal can decide how to
realize that. If the specification says that you can query for void*,
it needs to work - regardless of the internal way how to do that.

- Daniel

--

---
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/.

.


Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@gmail.com>
Date: Tue, 22 Oct 2013 10:15:05 +0200
Raw View
2013/10/22 Daniel Kr=FCgler <daniel.kruegler@gmail.com>:
> 2013/10/22  <stackmachine@hotmail.com>:
>> Here's the code of unsafe_any_cast:
>>
>> template<typename ValueType>
>> inline ValueType * unsafe_any_cast(any * operand) BOOST_NOEXCEPT
>> {
>>         return &static_cast<any::holder<ValueType>
>> *>(operand->content)->held;
>> }
>>
>> If I instantiate this template, I get a static_cast<any::holder<void*>*>=
..
>> This is UB.
>
> Please look at the suggestion from the view-point of an API
> suggestion, not by looking into the code. It all depends what the
> specification would be and a library internal can decide how to
> realize that. If the specification says that you can query for void*,
> it needs to work - regardless of the internal way how to do that.

That being said I agree that unsafe_any_cast is not what you have been
asking for.

> - Daniel

--=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/.

.