Boost logo

Boost Users :

Subject: Re: [Boost-users] can't take const ref to tribool's indeterminate
From: Phil Nash (phil.nash.lists_at_[hidden])
Date: 2011-04-19 13:41:31


Thanks for you reply, Steven:

On Tue, Apr 19, 2011 at 4:36 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> AMDG
>
> On 04/19/2011 12:27 AM, Phil Nash wrote:
>> The following does not compile (GCC 4.2):
>>
>>     #include <boost/logic/tribool.hpp>
>>
>>     template<typename T>
>>     void byRef( const T& v )
>>     {
>>     }
>>
>>     // ...
>>
>>       byRef( boost::indeterminate );
>>
>> I realise that indeterminate is actually a function. If I write my
>> own, equivalent, function I can substitute it here and it compiles,
>> however. I can't see what is stopping it from working in
>> indeterminate's case - but I suspect it is to do with some of the
>> operator overloading going on. I couldn't pin it down, though.
>>
>
> A function type cannot be const qualified
> under C++03.

I suspected there might be something like this involved.
What puzzles me still is that if I write my own function, I can pass it. e.g:

    inline bool myIndeterminate(boost::tribool x,
boost::logic::detail::indeterminate_t)
    {
        return x.value == boost::tribool::indeterminate_value;
    }

    //...

    byRef( myIndeterminate );

And this compiles fine. Whether it should or not is another, not
unimportant, matter - and what you've said suggests it shouldn't.
Nonetheless why does my function compile when boost::indeterminate doesn't?

> Probably the easiest solution is to have the
> call site use boost::tribool(boost::indeterminate).

It's a shame as it means that I can't treat indeterminate as a value
because of the implementation choice. My actual function taking a
const ref is an operator overload. It means that:

   myObject == boost::indeterminate

doesn't compile even though:

  triboolValue == boost::indeterminate doesn't.

It seems the forwarding problem is not the only obstacle to this sort of thing.

Thanks and regards,

[)o
IhIL..


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