Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-08-18 10:08:19


I realize it's been ages since I started this conversation, but...

I find the idea that add_pointer does something so different from add_const
and add_reference disturbing, and hard-to-remember.

Could we call the current add_pointer<> template addressof_type or
something, and supply an add_pointer which straightforwardly adds a '*' if
it's legal to do so?

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com

From: "David Abrahams" <david.abrahams_at_[hidden]>

> I can understand why the behavior would be useful for references, but I
> still can't understand it for arrays. A pointer-to-an-array is a
> well-defined concept, but maybe there's something I'm missing here:
>
> template <class T>
> struct holder
> {
> typedef T type;
> T held;
> };
>
> template <class T>
> std::type_info const& f(T const& x)
> {
> typename add_pointer<typename T::type>::type held_ptr p = &x.held;
> return typeid(*p);
> }
>
> std::type_info id = f(holder<int[10]>());
>
> So, does this program compile? If so, what does id contain? typeid(int)?
> typeid(int[10])? Something else?
>
> -Dave
>
> ----- Original Message -----
> From: "John Maddock" <John_Maddock_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Sunday, March 17, 2002 7:32 AM
> Subject: Re: [boost] type_traits: add_pointer behavior?
>
>
> > > On conforming compilers, add_pointer<int&> is int*.
> > >
> > > I'm not sure that's desirable (perhaps int& would be better).
> > >
> > > 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.
> > > It seems to me that any type_traits metafunction called "add_xxx"
> > > shouldn't strip any features of its argument.
> > >
> > > Thoughts?
> >
> > The aim is that add_pointer<T>::type is the same as the type of &t, if
> t is
> > an instance of T.
> >
> > John Maddock
> > http://ourworld.compuserve.com/homepages/john_maddock/index.htm
> >
> >


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