Boost logo

Boost Users :

Subject: Re: [Boost-users] [proto] Question on grammar and operator overloading
From: Eric Niebler (eric_at_[hidden])
Date: 2009-10-06 12:32:14


Hal Finkel wrote:
> Eric,
>
> Thank you, I'll use the predicate approach for now. I like the idea of
> using an array base because I have a lot of existing C and C++ code
> which treats complex numbers as a 2 element array, and accesses the
> members using the [] operator. I think this is common in
> high-performance scientific codes. I'm afraid doing it another way could
> lead to the generation of a large number of conditionals which the
> optimizer can't figure out how to eliminate (meaning (idx ? imag() :
> real()), I'd have to test this on several platforms), or the
> introduction of a lot of casts.

If you're going that route, you could just drop boost::array and use
native arrays:

   proto::terminal< double[2] >::type

Then your grammar changes to:

   proto::and_<
     proto::terminal<_>,
     proto::if_<boost::is_array<proto::_value>()>
>

HTH,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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