On Jun 14, 2006, at 4:56 AM, John Maddock wrote:
Gottlob Frege wrote:
if unknown_struct is an incomplete type (which is what I meant, and should have said), alignment_of doesn't compile.
If the type is incomplete then you can't use aligned_storage anyway, since you don't know how much storage you'll need! Sorry but you've lost me now.
There are applications such as boost::function where aligned storage for an unknown type is useful. In boost::function's case, aligned storage could be used to implement the "short string optimization". The general pattern is: class Container { private: const unsigned buf_size = ...; aligned_storage<buf_size>::type buffer; public: template <class T> Container(const T& t) {/* might stick t into buffer instead of on heap, based on sizeof(T) */} }; On Jun 14, 2006, at 6:55 AM, David Abrahams wrote:
I think what the OP is looking for is called boost::shared_ptr ;-)
shared_ptr can't compete with this application performance-wise. -Howard