Boost logo

Boost Users :

From: Marshall Clow (marshall_at_[hidden])
Date: 2005-10-08 13:38:48


At 10:08 PM -0400 10/7/05, Piyush Kapadia wrote:
>Does Boost Library internally does Reference counting for most of
>its internal objects ?
>
>Does it also use it's shared_ptr kind of Smart pointer
>implementation internally ?
>
>Sorry for my ignorance, but isn't there any cleaner Smart Pointer
>implementation where we don't have to use new every time initiating
>object and smart pointer becomes part of the class rather that
>separate implementation like following -
>
>shared_ptr sp(new int(5));

How about (untested code, but I have something pretty similar in my code):

template <class T>
boost::shared_ptr<T> New () { return boost::shared_ptr<T> ( new T ); }

template <class T, typename A1>
boost::shared_ptr<T> New ( A1 a1 ) { return boost::shared_ptr<T> (
new T ( a1 ) ); }

template <class T, typename A1, typename A2>
boost::shared_ptr<T> New ( A1 a1, A2 a2 ) { return
boost::shared_ptr<T> ( new T ( a1, a2 ) ); }

and so on.

Then can you just say:
        shared_ptr<int> sp = New<int> ( 5 );

-- 
-- Marshall
Marshall Clow     Idio Software   <mailto:marshall_at_[hidden]>
It is by caffeine alone I set my mind in motion.
It is by the beans of Java that thoughts acquire speed,
the hands acquire shaking, the shaking becomes a warning.
It is by caffeine alone I set my mind in motion.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net