Boost logo

Boost Users :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2005-10-04 22:36:10


David Abrahams writes:
> "Noel Belcourt" <kbelco_at_[hidden]> writes:
>
>> On Oct 1, 2005, at 6:57 PM, David Abrahams wrote:
>>
>>> "Noel Belcourt" <kbelco_at_[hidden]> writes:
>>>> So if I want to perform an element-wise mpl::or operation of two
>>>> sequences (r, p1) and then test the resulting sequence for equivalence
>>>> to the input sequence, something like this should work since as you
>>>> observe below, mpl::equal will compare two sequences and yield a
>>>> scalar
>>>> boolean.
>>>
>>> BOOST_MPL_ASSERT((equal<r, transform<r, p1, or_<_,_> >::type>));
>>
>> One more observation about this, this code doesn't compile if r and p1
>> are a vector_c<bool,..> or a vector_c<int,..> with CW 9.5 on Tiger
>> 10.4.2. The compiler output is attached.
>>
>> For example, if r and p1 are declared as follows, the code will not
>> compile.
>>
>> typedef vector_c<bool,1,0> r,p1;
>> BOOST_MPL_ASSERT(( equal<r, transform<r, p1, or_<_,_> >::type>));
>>
>> The problem seems to be that the sequence produced by invoking
>> transform using a boolean binary function is a different type than
>> vector_c<bool,..>.
>
> I think that's not really the issue. I think the problem is that the
> _element_ types of those two sequuences are not identical.

Yep. The default predicate for 'equal' is 'is_same', which means that
the algorithm compares elements' type identity instead of their values
(and for the numeric operations, the former is seldom guaranteed). Try

    typedef vector_c<bool,1,0> r,p1;
    BOOST_MPL_ASSERT(( equal<
          r
        , transform<r, p1, or_<_,_> >::type
        , equal_to<_1,_2>
> ));

>> Just want to be sure that this is known and expected behavior?
>
> I'm actually unsure. Aleksey?

Yes, it is.

-- 
Aleksey Gurtovoy
MetaCommunications Engineering

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