Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to stick with boost::any i am not sure but you can write your own "boost::any". I'm using this code for proxy methods to pass the parameters.</p> <pre><code>#include &lt;iostream&gt; #include &lt;boost\smart_ptr\scoped_ptr.hpp&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/serialization/access.hpp&gt; #include &lt;boost/serialization/shared_ptr.hpp&gt; #include &lt;boost/archive/text_oarchive.hpp&gt; #include &lt;boost/archive/text_iarchive.hpp&gt; #include &lt;boost/serialization/export.hpp&gt; #include &lt;sstream&gt; class my_placeholder { public: virtual ~my_placeholder(){} my_placeholder(){} private: friend class boost::serialization::access; template&lt;class Archive&gt; void serialize(Archive &amp; ar, const unsigned int version) { // serialize base class information //ar &amp; boost::serialization::base_object&lt;bus_stop&gt;(*this); //ar &amp; m_placeholder; } }; template&lt;typename T&gt; class my_derivedplaceholder: public my_placeholder { public: my_derivedplaceholder() { } my_derivedplaceholder(T &amp;value) { m_value=value; } T m_value; private: friend class boost::serialization::access; template&lt;class Archive&gt; void serialize(Archive &amp; ar, const unsigned int version) { // serialize base class information ar &amp; boost::serialization::base_object&lt;my_placeholder&gt;(*this); ar &amp; m_value; } }; BOOST_CLASS_EXPORT_GUID(my_derivedplaceholder&lt;int&gt;, "p&lt;int&gt;"); class my_any { public: my_any() { } template&lt;typename T&gt; my_any(const T &amp;value) { m_placeholder.reset(new my_derivedplaceholder&lt;T&gt;(const_cast&lt;T&amp;&gt;(value))); } template&lt;typename T&gt; void operator=(const T &amp;value) { m_placeholder.reset(new my_derivedplaceholder&lt;T&gt;(const_cast&lt;T&amp;&gt;(value))); } protected: friend class boost::serialization::access; template&lt;class Archive&gt; void serialize(Archive &amp; ar, const unsigned int version) { // serialize base class information //ar &amp; boost::serialization::base_object&lt;bus_stop&gt;(*this); ar &amp; m_placeholder; } template&lt;typename T&gt; friend T my_anycast(my_any &amp;val); boost::shared_ptr&lt;my_placeholder&gt; m_placeholder; }; template&lt;typename T&gt; T my_anycast(my_any &amp;val) { boost::shared_ptr&lt;my_derivedplaceholder&lt;T&gt;&gt; concrete=boost::dynamic_pointer_cast&lt;my_derivedplaceholder&lt;T&gt;&gt;(val.m_placeholder); if (concrete.get()==NULL) throw std::invalid_argument("Not convertible"); return concrete-&gt;m_value; } void main() { my_any m=10; int a=my_anycast&lt;int&gt;(m); std::cout &lt;&lt; a &lt;&lt; std::endl; std::stringstream ss,ss2; boost::archive::text_oarchive oa(ss); oa &lt;&lt; m; boost::archive::text_iarchive ia(ss); my_any m2; ia &gt;&gt; m2; std::cout &lt;&lt; my_anycast&lt;int&gt;(m2) &lt;&lt; std::endl; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload