|
Boost : |
From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2001-03-19 12:46:31
Peter Dimov wrote:
> > If you have an alternative which doesn't require partial
> > specialization that runs on MSVC, it will be very much
> > appreciated by those of us stuck with this dang compiler.
> > I've had it, and have stopped trying. Although I know
> > that is a bad attitude. And judging from the comments by
> > the folks in Redmond reading this list I am hopeful that they
> > are working on it.
>
> Very difficult. I can't do the general case without typeof,
> or remove_cv and remove_reference
> (I've tried several times.)
FYI, all 'boost::type_traits' library's type transformation templates
(including 'remove_cv' and 'remove_reference') can be made to work even on
compilers without partial class template specialization support; by default
they do work for all fundamental types, and all their 1st and 2nd rank
cv-[un]qualified derivative pointer types, e.g.
BOOST_STATIC_ASSERT((is_same<remove_cv<int const volatile>::type,
int>::value));
BOOST_STATIC_ASSERT((is_same<remove_cv<int* const volatile>::type,
int*>::value));
BOOST_STATIC_ASSERT((is_same<remove_cv<int** const volatile>::type,
int**>::value));
BOOST_STATIC_ASSERT((is_same<remove_reference<int&>::type, int>::value));
and by writing something like:
struct my;
BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(my);
you can also make the above code compile with any user-defined type in place
of 'int'. Obviously, this approach places some burden on the library users,
but AFAIK it's the only way to compensate the lack of partial specialization
here, and, speaking of its applicability to an expression template library,
personally I would rather prefer to write:
// once, somewhere in the header
BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(point);
// a lot of code like this
list<point> l;
find_if(l.begin(), l.end(), var1 < point(5, 5));
than:
// a lot of code like this
list< point<long> > l;
find_if(l.begin(), l.end(), bind2nd(less<point>(), point(5, 5));
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk