|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-05-05 13:36:07
"John Maddock" <john_at_[hidden]> writes:
>> The easiest way of course is to add a specialization for
>> boost::type_traits::rank in my project's sources but this is not a
>> very
>> clean solution because this would require that I add stuff to the
>> boost-namespace in my own project. Ideas?
>
> Unfortunately I think you need to define your own trait: the idea behind
> type-traits is that they work with the core C++ type system only, and that
> we don't extend them to classes that are "pretending" to be something else
> (like an array for example). Having just said that, I'm having trouble
> thinking of a reason why extending boost::rank in this way would cause
> problems in a way that extending is_pointer to smart-pointers would for
> example.
Most of the type traits are designed to do something legal and
reasonable even when doing the right thing is impossible, e.g.
remove_pointer<shared_ptr<T> >::type
is designed to be shared_ptr<T>. If rank does somthing similar, like
return zero when not passed a true array, then specializing it could
break libraries. Besides which, it's just conceptually wrong ;-)
> So.... why not create your own traits class, call it rank if you
> want, place it in your projects own namespace, and have the primary
> template inherit from boost::rank. Does that make sense?
That sounds sensible.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk