Boost logo

Boost :

From: Jeremy Maitin-Shepard (jbms_at_[hidden])
Date: 2004-01-03 22:28:07

"Thorsten Ottosen" <nesotto_at_[hidden]> writes:

> [snip]

> 2) in generic code, const T* and const smart_ptr<T> are not equal and I will
> need traits to deal with different syntax

It seems you are being confused by your placement of the const keyword.

"const shared_ptr<T>" is equivalent to "shared_ptr<T> const",
but "const T *" is not equivalent to "T * const".

"const T *" is equivalent to "T const *".

However, if you have:

typedef T *pointer;

Then, "const pointer" is equivalent to "pointer const" is equivalent to
"T * const".

To get the const behavior of "const T *" (or "T const *"), i.e. const
pointee, use "shared_ptr<T const>".

To get the const behavior of "T * const", i.e. const pointer,
use "shared_ptr<T> const" or "const shared_ptr<T>".

For generic programming purposes, shared_ptr<T> does in fact work
equivalently to boost::add_const<T>::type. With your proposed change,
however, it would not.

> [snip]

Jeremy Maitin-Shepard

Boost list run by bdawes at, gregod at, cpdaniel at, john at