Boost logo

Boost :

From: Mat Marcus (mmarcus_at_[hidden])
Date: 2000-10-02 18:11:44


At 7:39 PM +0000 10/2/00, William Kempf wrote:
>
>> Monday morning, back at my Windows box. The above code seems to
>work
>> for me on VC6.3 after correcting some typos:
>>
> > template <class T>
>> struct ISCONST {
>> enum {RET = (1 != sizeof(&((Holder<T>*)0)->x))};
> > };
>
>I don't follow this at all. It appears that your ISCONST will always
>return 'true' because you're basically doing a sizeof(T*) != 1 in the
>above code. Trying to implement this in VC6 bears this out for me.
>So, either you made some more typos here or I'm severely misreading
>the posted code.
>
>> Cool. One aspect of this version of ISREF is that there are no
>> compiler warnings from VC6.3.
>
>As opposed to which other version of ISREF?
>
>I really want to find work arounds here, as I'd really, REALLY,
>*REALLY* like a version of the Lambda Library that works for VC++.
>So, I'm following this thread carefully and trying to get things to
>work with VC6. Unfortunately, I'm still stumbling on a few things
>here that others claim to have figured out.
>
>Bill Kempf

Sorry. What I meant to type was

> >
> >
>
template <class T>
struct ISREF { // doesn't work :-(
     enum {RET = (1 != sizeof(IsNonConstPointer(&(( (Holder<T>*) 0)->x) ))};
  };

Unfortunately I misreported the results. VC6.3 doesn't behave
correctly here. Typos + Monday morning = brain damage. But all is not
lost. If you are willing to put up with an ISREF that gets confused
over const volatile references then you could make use of the
following technique. Here is an explanation. References seem to be
the only type for which T const is equal to T. This implies that T
const is not const if and only if T is a reference type. Simalarly
for volatile. So you might try this.

template <class T>
struct ISREF { // Apparently works except for const volatile references
        typedef T const volatile;
        enum { RET = !ISCONST<T>::RET || !ISVOLATILE<T>::RET };
};

Thanks to John Maddock for this excellent idea.

- Mat


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk