Skip to content

Unable to construct RMatrix from a non-const buffer #139

Description

@galexv

The following code does not compile:

// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::depends(RcppParallel,BH)]]
#include <Rcpp.h>
#include <RcppParallel.h>
#include <cassert>

using RcppParallel::RMatrix;

//[[Rcpp::export]]
void Test() {
  double buffer[10] = {1,2,3,4,5,6,7,8,9,10};
  RMatrix<double> mtx(&buffer[0], 2,5);  // compilation error: invalid cast `const double*` to `double*` in ctor
  assert (mtx(0,0) == 1);
  mtx(0,0)=77;
  assert (mtx(0,0) == 77);
}

I believe there is nothing wrong for the RMatrix constructor to accept a non-const pointer to the data buffer; i prepared and submitted a PR (#138).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions