By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,504 Members | 1,724 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,504 IT Pros & Developers. It's quick & easy.

Re: Copy-less initialization of a TR1 array

P: n/a
On Nov 10, 4:20*pm, Vidar Hasfjord <>
On Nov 10, 12:30*pm, zr <zvir...@gmail.comwrote:
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?

Yes, you can use 'placement new':

* * typedef array <int, 4A;
* * int init [] = {1, 2, 3, 4};
* * A& a = *new (init) A;
A may overflow init.
Of course, this is equivalent to

* * array <int, 4a = {1, 2, 3, 4};
Only with POD types. If you replace int with a non-trivial type, this
code will end up calling constructors twice and destructors only once.

Nov 10 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.