Skip to content
Prev 4154 / 10988 Next

[Rcpp-devel] Convertion from SEXP to std::vector<unsigned>

On Wed, Aug 22, 2012 at 9:55 AM, Peng Yu <pengyu.ut at gmail.com> wrote:
You should at least specify the size there so that push_back doesn't
need to allocate/reallocate and possibly overallocate.

std::vector<unsigned> v(vec.size());

You may be able to allocate from iterators as in

std::vector<unsigned> v(vec.begin(), vec.end());

but I'm not sure if that will do the automatic conversion from signed
int to unsigned.  Look up the different forms of constructors for
std::vector and the STL algorithms such as std::transform.