|
Boost : |
From: Sofus Mortensen (sofus_at_[hidden])
Date: 2000-10-02 14:30:29
Hi,
I don't know if you already have a ISPTR, but this works fine for me on
MSVC6SP3.
Best regards,
Sofus Mortensen
tlb2h - A COM/C++ interoperability tool
http://www.lambdasoft.dk/tlb2h
template <class T> struct Holder { T x; Holder(); };
template<typename T>
char IsPointer(T*);
int IsPointer(...);
template<class T>
struct ISPTR {
enum { RET = sizeof(IsPointer(((Holder<T>*)0)->x)) == 1};
};
char a[ISPTR<int*>::RET];
char b[!ISPTR<int>::RET];
char c[ISPTR<int* const>::RET];
char d[ISPTR<const int*>::RET];
char e[!ISPTR<const int>::RET];
char f[!ISPTR<int&>::RET];
char g[ISPTR<const volatile int* const>::RET];
> -----Original Message-----
> From: Mat Marcus [mailto:mmarcus_at_[hidden]]
> Sent: Monday, October 02, 2000 7:59 PM
> To: boost_at_[hidden]
> Subject: [boost] Re: Simulating Partial Specialization
>
>
> >Looks like ISPTR used as a discriminator for full class
> >specialization
> >will work if ISCONST used as a secondary discriminator and member
> >template classes work :
> >
> >template <bool is_ptr, bool is_const>
> >struct iterator_traits_helper
> >{
> > template <class Iterator> class iterator_traits_base {
> > typedef typename Iterator::value_type value_type;
> > ...
> > }
> >};
> >
> >template<>
> >struct iterator_traits_helper<true, true>
> >{
> > // we know for sure this guy is const T*
> > // remove_const template is supposed to remove const -- do we have
> >that ???
> > template <class Iterator> class iterator_traits_base {
> > typedef typename remove_const<Iterator>::value_type value_type;
> > ...
> > }
> >};
> >
> >template <class T>
> >struct iterator_traits : public
> >iterator_traits_helper::iterator_traits_base<IS_PTR<T>::Ret,
> >IS_CONST<T> > {
> >};
> >
> >The problem might be that VC6 might not work very well with typedefs
> >inside member template classes...
>
> It looks like you have rediscovered the metactrl::IF technique.
> However the problem of determining the underlying type from a pointer
> template parameter at compile time remains unsolved AFAIK.
>
> - Mat
>
>
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk