I've put together a bleeding edge setup with G++ 4.7 (though for the moment I'm still using the boost 1.48 that came with sudo apt-get boost-all-dev
on Debian Wheezy).
My code is set up where the logical data structure to use would be multidimensional arrays of unique_ptr. But multi_array
doesn't seem to be able to construct even an empty single-element array if there's a unique_ptr in it. Thus this works:
boost::multi_array<int, 1> arrWorks (boost::extents[1]);
But this does not:
boost::multi_array< unique_ptr<int>, 1> arrFails (boost::extents[1]);
I imagine the relevant complaint from the compiler is:
/usr/include/c++/4.7/bits/stl_uninitialized.h:225: required from ‘void std::uninitialized_fill_n(_ForwardIterator, _Size, const _Tp&) [with _ForwardIterator = std::unique_ptr*; _Size = unsigned int; _Tp = std::unique_ptr]’
I'm having some problems with optional< unique_ptr<...> >
as well, even though I applied the patch offered here:
https://svn.boost.org/trac/boost/ticket/1841
( Note: Found via Is it possible to move a boost::optional? )
So for instance:
boost::optional< unique_ptr<int> > optWorks (new int);
// Fails
boost::optional< unique_ptr<int> > optFails (std::move(optWorks));
I feel like what I'm doing is legitimate. In fact I've already found a few bugs in terms of transfer-of-ownership semantics by incorporating unique_ptr into this project. So I'd hate to say "oh, this is too complicated, just use raw pointers".
Is this something on boost's agenda to support? Is there a timeline for it? Are there any simple workarounds I can use in the meantime?