Allow constructing RMatrix from a non-const buffer - #138
Conversation
|
Thanks! |
|
I had the same issue, however my fix was to implement a similar pattern as the more common constructor: RcppParallel/inst/include/RcppParallel/RMatrix.h Lines 199 to 205 in cb514e8 Thus, I implemented the following: inline RMatrix(const T* data, std::size_t nrow, std::size_t ncol)
: data_(const_cast<T*>(data)), nrow_(nrow), ncol_(ncol)
{
}I had experimented with the current fix (removing the I'm not sure which is better, but my gut feeling is that keeping |
|
This is a possibility, but my gut feeling is just the opposite: i do not like Case in point: a simplified code at https://godbolt.org/z/WP5qes uses A side note: When the program is compiled with "-O1", the compiler deduces the result without actually running any memory access code, ignoring the incorrect assignment, so we get different results at different optimization levels, as is common when a UB is invoked. [Sorry for double posting, accidentally posted it from a temporary account 😔 ] |
No description provided.