Boost logo

Boost :

Subject: Re: [boost] [mpl] has_function
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-03-28 09:01:34


On Sat, Mar 27, 2010 at 11:56 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
>> <snip>
>>    template<typename T>
>>    struct has_contract_f_ {
>>    private:
>>        typedef char true_t;
>>        struct false_t { true_t dummy[2]; };
>>        static T* make();
>>
>>        static false_t check(...);
>>        template<typename C> static true_t check(C*,
>>                typename C::template contract_f_<0>* = 0);
>>    public:
>>        static const bool value =
>>                sizeof(check(make())) == sizeof(true_t); // line 31
>>    };
>>
>> <snip>
>
> Does it work if you pass 0 explicitly instead of using a default argument.

Unfortunately, it does not work (that is the first thing I tried...).
If I change the `value` evaluation to:

    sizeof(check(make(), 0)) == sizeof(true_t); // line 31

Then `check(...)` is always called and `value` is always false. I
_think_ because in this context 0 is always interpreted as a `int`
instead of a pointer to `C::contract_f_<0>`.

On Sat, Mar 27, 2010 at 10:55 PM, Jeffrey Hellrung <jhellrung_at_[hidden]> wrote:
> Compiles fine for me (MSVC9, Vista).

I have not tried the code on MSVC yet -- it's good it works on MSVC. I
get the error with GCC/Ubuntu (what should the C++ ISO standard
behavior be? error or not?).


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