|
Boost : |
From: Larry Evans (cppljevans_at_[hidden])
Date: 2006-03-26 16:11:22
On 03/26/2006 01:19 PM, Vaclav Vesely wrote:
[snip]
> IMHO const reference forwarding and explicit wrapping of non-const
> reference parameters with boost::ref is comfortable enough and feasible
> with current compilers. See the attachment.
>
> If there will be there a will to add my implementation into Boost, I
> will write an appendix to the Best Practices.
>
> Regards,
> Vaclav
[snip]
> namespace boost
> {
>
> #if !defined(BOOST_MAX_NEW_ARITY)
> #define BOOST_MAX_NEW_ARITY 10
> #endif
>
> #define BOOST_NEW_TEMPLATE(z, n, d) \
> template<typename T BOOST_PP_ENUM_TRAILING_PARAMS(n, typename A)> \
> T new_(BOOST_PP_ENUM_BINARY_PARAMS(n, A, const& a)) \
> { \
> return T(new T::element_type(BOOST_PP_ENUM_PARAMS(n, a))); \
> } \
> /**/
>
> BOOST_PP_REPEAT(BOOST_PP_INC(BOOST_MAX_NEW_ARITY), BOOST_NEW_TEMPLATE,
> BOOST_PP_EMPTY())
>
> #undef BOOST_NEW_TEMPLATE
>
> } // namespace boost
>
This would not be useful for a smart pointer:
template<class Referent>
struct only_heap_ptrs
;
which didn't have a CTOR taking a Referent* argument.
IOW, there would be no:
template<class Referent>
only_heap_ptrs<Referent>::only_heap_ptrs(Referent* a_heap_ptr);
Such a smart pointer would avoid a mistake like:
int i;
only_heap_ptrs<int> pi(&i);
OTOH, this was one of the purposes of the auto_overhead template
class of http://tinyurl.com/f2r7h. OTOH, it's very easy to reuse
auto_overhead to write new_ AFAICT.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk