Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2002-03-13 19:21:04

David Abrahams wrote:
> Right now, add_pointer<T> doesn't compile on MSVC6 when T is
> a reference type.
> I can make it be int& on MSVC, if it's agreed that's desirable.
> On conforming compilers, add_pointer<int&> is int*.
> I'm not sure that's desirable (perhaps int& would be better).

The docs say:

If "t" is an instance of T, then add_pointer<T>::type is the type returned
by "&t". For example "int", "int&", "int[2]" and "int (&)[2]" all become

In other words, (as I see it, anyway) 'add_pointer' is a replacement for T*
for situations like this:

template<typename T> void foo(T t)
    // T* p = &t; // doesn't work for some T
    typename boost::add_pointer<T>::type p = &t; // always works

> Also, add_pointer<int[5]> is int* rather than int(*)[5] on conforming
> compilers.
> I /really/ can't understand why you'd want to throw out the
> array part.

The above explains the motivation; can't say anything about how useful that
semantics is for arrays, though - never used it.


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