Boost logo

Boost Users :

From: Jaakko Jarvi (jarvi_at_[hidden])
Date: 2006-11-08 11:47:06


On Nov 8, 2006, at 1:42 AM, Sebastian Weber wrote:

> Hi Stuart!
>
>> Try this -
>>
>> boost::function< double (std::size_t) > wf = (sIndex < m_maxIndex
>> +1) ?
>> boost::function< double (std::size_t) >(
>> boost::lambda::bind(boost::ref(m_cf), sDeg,
>> boost::lambda::_1) ) ) : (
>> boost::ref(*m_wf) );
>>
>> i.e. make sure the first expression is explicitly a boost::function<
>> double (std::size_t) >, as the second is convertible to that.
>
> Cool, this works! But why is this explicit cast necessary in this
> case?
>
It follows from the language rules of the ? : operator.
Roughly, the branches have to have same types, or one convertible to
another.

The types of the expressions in the branches in your example look
something like this:

lambda_functor< some long template mess here >

lambda_functor< some long template mess here, but different than the
one in the other branch>

These types are not convertible.

   Best, Jaakko Järvi


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