Boost logo

Boost Users :

From: Perepelitsa Roman (romka_at_[hidden])
Date: 2006-07-14 07:13:28


> Thanks Roman.
>
> so is this how i would use your implementation?
>
> boost::shared_ptr<Test> t = newptr<int, char, std::string>(1, 'a', "hello");
>
> that is getting a lot closer to what i need. and is far better that a
> MACRO. declaring the types may annoying however.
>
> the good thing about this approach it that is will also be exception
> safe: ie i dont need to declare a variable for the shared_ptr. and
> will be cleaned up if g() fails
>
> // exception safe
> fn(newptr<int, char, std::string>(1, 'a', "hello"), g());

You can omit all but the first template parameters because they can
be deduced by compiler.

shared_ptr<Test> t = newptr<Test>(1, 'a', "hello");

which is equivalent to

shared_ptr<Test> t = shared_ptr<Test>(new Test(1, 'a', "hello"));

HTH,
Roman Perepelitsa.


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