[Rcpp-devel] fun(Times) with STL
SILKWODJ at airproducts.com
Sat Jun 4 19:52:15 CEST 2011
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 <- '
int min_el_ind = *std::min_element(TimeQ.begin(), TimeQ.end()) - TimeQ.begin();
show_position = min_el_ind;
fun <- cxxfunction(signature(arg1="numeric"),src,plugin="Rcpp")
More information about the Rcpp-devel