Note that there are some explanatory texts on larger screens.

plurals
  1. POStrip boost::shared_ptr from a template parameter
    text
    copied!<p>I am developing a C++ template library that uses both primitive types and pointer types stored in boost::shared_ptr. I am having a problem with a helper class that is used to pack primitive types into a container class if necessary before being passed into a lower layer of the library. The following shows the basic type that just passes the pointer on, and the implementation for std::string which is one of the primitives.</p> <pre><code>template &lt;class T&gt; class RRPrimUtil { public: static rr_DataType GetTypeID() {return rr_void_t;} static boost::shared_ptr&lt;RRObject&gt; PrePack(T val) {return rr_cast&lt;RRObject&gt;(val);} static T PreUnpack(boost::shared_ptr&lt;RRObject&gt; val) {return rr_cast&lt;T&gt;(val);} }; template&lt;&gt; class RRPrimUtil&lt;std::string&gt; { public: static rr_DataType GetTypeID() {return rr_string_t;} static boost::shared_ptr&lt;RRObject&gt; PrePack(std::string val) {return rr_cast&lt;RRObject&gt;(stringToRRArray(val));} static std::string PreUnpack(boost::shared_ptr&lt;RRObject&gt; val) {return RRArrayToString(rr_cast&lt;RRArray&lt;char&gt;&gt;(val));} }; </code></pre> <p>The rr_cast&lt;>() function is an alias to dynamic_pointer_cast. The problem I am having is that for the general case, the template "T" includes the "boost::shared_ptr" prefix because this type may or may not interact with a shared_ptr. The prefix messes up the dynamic_pointer_cast, because it expects just the pointer type. Is there a clean way to work around this?</p>
 

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