Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2000-10-23 07:40:30


> In general I'd like to make these functions simpler and more intuitive
> and rely on the compiler to catch errors. For example, I think
is_pointer
> should return true for int* const and rely on a compile time
constraint
> or a compiler error if the code attempts to, say, increment the
pointer.
> In those rare(?) cases where this would lead to erroneous dispatching
> you'd have to test for and/or strip the cv-qualifiers.

FWIW: my thoughts on the matter.

John Maddock stated that instantiating a template on a cv-qualified type
is usually an error. Usually perhaps, but not always:

shared_ptr<int> p1(new int(42)); // pointer to int
shared_ptr<int const> p2(p1); // pointer to const int

template<class T> void f(T &);

int i = 7;
int * const p = &i;

f(p);

(for a real-world example on the latter, see expression.hpp: (arg1 +=
arg2)(i, 4), (arg1 += arg2)(4, 5); also, consider (*arg1)(p)).

Howard Hinnant sees is_pointer as one of several fundamental type
categories that have the property that every type belongs to one and
exactly one of them. I agree; I'd even go further and declare
type_traits<T>::category based on iterator_traits<I>::iterator_category.

Finally, I can't think of an example where is_pointer should return true
for T *, but _not_ return true for T * const; cases where T * const is
illegal anyway don't count.

--
Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk