Eric, I'm trying this option, but I can't get it to work correctly (the compiler does not find the operator overloads when I require boost::is_array to be "true"). If you uncomment the appropriate 3 lines in the grammar definition in the attached source file, you'll see what I mean. Thanks again, Hal On Tue, 2009-10-06 at 12:32 -0400, Eric Niebler wrote:
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,