|
Boost Users : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-10-04 00:36:48
Leo Landa wrote:
> I am trying to find a portable enough implementation of remove_pointer
> (MSVC 6, MSVC 7.1, G++ 2.95.3, G++ 2.96). The "usual" template
> technique relies on partial template specialization, which MSVC 6.0
> does not support. As far as I can tell, Boost's version of
> remove_pointer is a little bit of a "cheat" - i.e. it becomes
> predefined only for primitive types. Am I right about that?
Yes, _out of box_ 'remove_pointer' works for all fundametal types and their
first- and second- rank derivations (e.g. 'int', 'int const', 'int
volatile', 'int const volatile', 'int*', 'int const*', .., 'int const
volatile* const volatile* const volatile').
You can make it work for any other user-defined type 'A' by simply saying
BOOST_TT_BROKEN_COMPILER_SPEC(A)
somewhere in the global scope, before the first 'remove_pointer' usage:
struct A {};
BOOST_TT_BROKEN_COMPILER_SPEC(A)
BOOST_STATIC_ASSERT((is_same<A, remove_pointer<A*>::type>::value));
See the paragraph in the docs at the end of the "Transformation ..." section
(http://www.boost.org/libs/type_traits/index.htm#transformations).
> I'm a bit of a newb in these parts of London ;-)
>
> If this is true, then I'm screwed - and I can't convert a generic
> pointer type to the pointee type. If it is not true, then what is the
> technique?
The only way to implement any of the 'remove_*' traits is template
specialization, either full or partial [1]. Since MSVC 6.0 doesn't support
the latter, the type_traits way is the only way.
Aleksey
[1] At least it's the only way in absence of 'typeof'.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net