Skip to content
Prev 2420 / 10988 Next

[Rcpp-devel] fun(Times) with STL

On Sat, Jun 4, 2011 at 11:26 AM, Douglas Bates <bates at stat.wisc.edu> wrote:
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
structure.

Dirk and Romain recommended the freely-available book "C++ Annotaions"
to me (just google the title to find out where to download it) and
that contains several chapters explaining iterators, STL storage
classes (on which much of the Rcpp class structures are patterned) and
the STL algorithms.  Definitely worth reading if you have the time.