Boost logo

Boost Users :

From: Noel Belcourt (kbelco_at_[hidden])
Date: 2005-10-01 13:33:53


On Sep 29, 2005, at 7:45 PM, David Abrahams wrote:

> "Noel Belcourt" <kbelco_at_[hidden]> writes:
>> r = p1 || p1 && p2
>
> That would be equivalent to r = p1. Why go to all that trouble? Or
> do you mean
>
> r == p1 || p1 && p2

Yes, that's what I meant.

>
> Anyway, what does it mean to use the logical && operator on two
> sequences? Do you want elementwise comparison?

Yes, element-wise comparison.

> Do you want the same
> for r == p1?

Yes.

> The usual meaning is to compare all elements and produce
> a scalar boolean, which would then be incompatible with the vector of
> bools produced by p1 && p2. Maybe you mean something like;
>
> mpl::transform<
> mpl::transform<r,p1,mpl::equal_to<_,_> >::type
> , mpl::transform<p1,p2,mpl::and_<_,_> >::type
> , mpl::or_<_,_>
>> ::type
>

This looks reasonable. Transform returns a new sequence produced by
applying the binary operation to a pair of elements from the input
sequences.

Let me see if I understand this.

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_STATIC_ASSERT((
   equal<
        r
        , transform<r,p1,or_<_,_> >::type
>::type::value
));

> Ugh; do yourself a favor and apply a couple of namespace aliases at
> least; the whole point of those placeholders is that they're supposed
> to increase readability!

Duly noted.

> It seems to me that you also have several conceptual problems here.
> First, you have perfectly good metafunction parameters here that you
> can use; what are the placeholders supposed to be doing? Placeholders
> only have an effect in a context where an MPL placeholder expression
> can be used, e.g. in an argument to mpl::apply<...>. Why not just use
> R, P1, and P2 directly?

In this case I could.

> Second, you seem to be trying to use the equal algorithm, which
> operates on sequences, on the results of some invocation of mpl::or_,
> which does not return a sequence but a scalar bool-valued MPL integral
> constant.

True, I was confused about this point. So I'll use transform to
generate a sequence representing the element-wise binary operation and
then use equal.

Thanks,

-- Noel


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