Z
zr
Hi,
Is there a way to initialize a std::tr1::array with a pre-allocated
built-in array in a copy-less assignment, such that both will point to
the same memory?
Vice-versa is easy to do, simply use std::t1::array::data() and assign
the returned value to the c-style pointer;
if STL does not support this, is there any other library that has such
a container (maybe BOOST)?
Here is an example of what i have in mind:
#include <array>
using namespace std::tr1;
int main()
{
int cArray[] = { 1 , 2, 3, 4};
array<int,4> tr1Array(cArray); // Using some imaginary c-tor. Don't
want to copy. Want to use preallocated memory
tr1Array[0] = 42;
assert(tr1Array[0] == cArray[0] == 42); // Both point to same memory
tr1Array[100] = 42; //In debug builds, this should raise an exception
cArray[100] = 42; //Much harder to catch
return 0;
}
Is there a way to initialize a std::tr1::array with a pre-allocated
built-in array in a copy-less assignment, such that both will point to
the same memory?
Vice-versa is easy to do, simply use std::t1::array::data() and assign
the returned value to the c-style pointer;
if STL does not support this, is there any other library that has such
a container (maybe BOOST)?
Here is an example of what i have in mind:
#include <array>
using namespace std::tr1;
int main()
{
int cArray[] = { 1 , 2, 3, 4};
array<int,4> tr1Array(cArray); // Using some imaginary c-tor. Don't
want to copy. Want to use preallocated memory
tr1Array[0] = 42;
assert(tr1Array[0] == cArray[0] == 42); // Both point to same memory
tr1Array[100] = 42; //In debug builds, this should raise an exception
cArray[100] = 42; //Much harder to catch
return 0;
}