<div dir="ltr"><div><div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px">Hi everyone (and Dirk),</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
Second attempt on corrected email list.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">I have been trying to extend Rcpp with my own wrap and as templates.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Two issues:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
1) I need to explicitly call wrap. Is that expected?</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">So for example I wrote this specialization:</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"><div>template<> SEXP Rcpp::wrap(std::vector<TimedOptDouble> const& entries) {</div>
<div><span style="white-space:pre-wrap">  </span>std::vector<double> sec_times;</div><div><span style="white-space:pre-wrap">     </span>std::vector<double> doubles;</div><div><span style="white-space:pre-wrap">       </span>for(auto const& entry : entries)</div>
<div><span style="white-space:pre-wrap">  </span>{</div><div><span style="white-space:pre-wrap">                </span>sec_times.push_back(entry.GetTime().Seconds());</div><div><span style="white-space:pre-wrap">          </span>TimedOptDouble::OptDouble opt_double(entry.GetOptDouble());</div>
<div><span style="white-space:pre-wrap">          </span>if(opt_double)</div><div><span style="white-space:pre-wrap">                   </span>doubles.push_back(*opt_double);</div><div><span style="white-space:pre-wrap">          </span>else</div><div><span style="white-space:pre-wrap">                     </span>doubles.push_back(R_NaReal);</div>
<div><span style="white-space:pre-wrap">  </span>}</div><div><span style="white-space:pre-wrap">        </span>return List::create(</div><div><span style="white-space:pre-wrap">             </span>Named( "Time" ) = sec_times,</div>
<div><span style="white-space:pre-wrap">          </span>Named( "Value" ) = doubles);</div><div>}</div></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
First of all, this returns what I believe to be a Rcpp::List object, which seems to be converted implicitly to a SEXP. This is the typical behaviour I know.</div><div style="font-family:arial,sans-serif;font-size:13px"><br>
</div><div style="font-family:arial,sans-serif;font-size:13px">Unfortunately, when making use of this template, it doesn't work implicitly, but I need to explicitly call it.</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">So for example</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">SEXP GetSunPositions(SEXP a) {<br>
</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap">        </span>std::vector<TimedOptDouble> sun_positions;<br></div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="white-space:pre-wrap">     </span>...</div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap">        </span>return wrap(sun_positions);<br></div><div style="font-family:arial,sans-serif;font-size:13px">
}</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">works, where as</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
return sun_positions;<br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">as last line doesn't. Am I doing something wrong here? I did do the declaration before including <Rcpp.h>.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">2) How to make as work for own types in containers</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">The other way around, one can return a std::vector<double> implicitly, but how do I return std::vector<MyType>? I tried to define</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap">      </span>template<> MyType as(SEXP);</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
But that didn't help, e.g. I had to write my own</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="white-space:pre-wrap">     </span>template<> std::vector<MyType> as(SEXP);</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Thanks for help</div><div class="" style="font-family:arial,sans-serif;font-size:13px"><div id=":10y" class="" tabindex="0">
<img class="" src="https://mail.google.com/mail/u/0/images/cleardot.gif"></div></div>Florian<br></div></div>
</div>