Re: [boost] type_traits: add_pointer behavior?
by David Abrahams other posts by this author
Aug 18 2002 3:08PM messages near this date
[boost] Sockets
|
Re: [boost] type_traits: add_pointer behavior?
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@[...].com * http://www.boost-consulting.com
From: "David Abrahams" <david.abrahams@[...].com>
> 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@[...].com>
> To: <boost@[...].com>
> 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
> >
> >
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
David Abrahams
John Maddock
|