[Rcpp-devel] fun(Times) with STL
bates at stat.wisc.edu
Sat Jun 4 20:11:09 CEST 2011
A thinko on my part. Remove the '*' in front of the std::min_element.
On Sat, Jun 4, 2011 at 12:52 PM, Silkworth,David J.
<SILKWODJ at airproducts.com> wrote:
> Many thanks, Doug, I feel so-o-o close, but the revised example does not compile.
> I have taken the liberty to condense our discussion a little here.
>>>> double* myIterator = std::min_element (TimeQ.begin(), TimeQ.end());
>>> The usual idiom is
>>> double TQmin = *std::min_element(TimeQ.begin(), TimeQ.end());
>>Sorry. I didn't read through to the end of your message. If you want
>>the index of the minimum element you can use
>>int min_el_ind = *std::min_element(TimeQ.begin(), TimeQ.end()) - TimeQ.begin();
>>The beauty of iterators is that they have more flexibility than simple
>>pointers and they also carry more information, so that the difference
>>between two iterators is the index of an element in an array-like
> Here is the revised example as I have distilled it down and edited (does NOT compile):
> src <- '
> Rcpp::NumericVector TimeQ(arg1);
> Rcpp::IntegerVector show_position(1);
> int min_el_ind = *std::min_element(TimeQ.begin(), TimeQ.end()) - TimeQ.begin();
> show_position = min_el_ind;
> return show_position;
> fun <- cxxfunction(signature(arg1="numeric"),src,plugin="Rcpp")
> fun_test<- fun(Times)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1230 bytes
Desc: not available
More information about the Rcpp-devel