Boost logo

Boost :

From: Hamish Mackenzie (boost_at_[hidden])
Date: 2002-02-05 15:18:06


On Tue, 2002-02-05 at 19:52, Hamish Mackenzie wrote:
> template< class T >
> move_to_here
> {
> unsigned char buffer_[ sizeof( T ) ];
> T *get() { return reinterperet_cast< T * >( &buffer_ ); }
> const T *get() const { return reinterperet_cast< T * >( &buffer_ ); }
>
> public:
> move_to_here() { construct( get() ); }
> // not sure if it should have default constructor
>
> explicit move_to_here( T &source )
> {
> move_construct( get(), source );
> }
> ~move_to_here() { destroy( get ); }
>
> operator T &() { return *get(); }
> operator const T &() const { return *get(); }

  T * operator -> () { return get(); }
  const T * operator -> () const { return get(); }

> };
>
> Then you could do this
>
> move_to_here< T > temp( x );
>
> This might even help on compilers that do not do return value
> optomization
>
> move_to_here< T > f()
> {
> T x;
> return move_to_here< T >( x );
> }
>
> Hamish Mackenzie


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk