![]() |
Blitz Support : |
From: Patrick Guio (Patrick.Guio_at_[hidden])
Date: 2005-04-04 09:33:56
On Mon, 4 Apr 2005, Breeveld, Eddie (Reigate) wrote:
> Hi Derrick and Patrick,
>
> This is brilliant! My C++ is 'improving', and the routine Derrick
> suggested works. I have modified Derrick's suggestion by using a cast
> to remove the temporary array, and I'm also passing the array as a const
> by reference to avoid too much copying:
>
>
> template<class T_expr> inline
> typename _bz_ArrayExpr<T_expr>::T_numtype
> Afun(const blitz::_bz_ArrayExpr<T_expr> &expr)
> {
> typedef blitz::_bz_ArrayExpr<T_expr> exprT;
> return Afun(
> (blitz::Array<typename exprT::T_numtype, exprT::rank>)expr );
> }
>
>
> I am now trying to do something similar for functions that return arrays
> different shapes to the original. What are the other class members of
> _bz_ArrayExpr?
>
> Patrick, a sample program that does not compile in Microsoft VS.NET 7.1
> would be
>
> #include "c:\program files\blitz-0.8\blitz\array.h"
> BZ_USING_NAMESPACE(blitz)
>
> template<typename T, int N> inline
> T RTSumAll(const Array<T,N> A)
> {
> // complex processing in here ...
> return sum(A);
> };
>
> int main(int argc, char* argv[])
> {
> Array<double, 2> fund(2,2);
> fund = 3.0;
> double rate = RTSumAll(fund * 6.0);
> }
>
> It would be interesting to know if it works with other compilers.
>
I would think that you don't need the "const" declaration for A in
RTSumAll since the array is passed by value.
But you still need an explicit cast
The following compiles well for me...
template<typename T, int N>
inline T RTSumAll(const Array<T,N> A)
{
// complex processing in here ...
return sum(A);
};
int main(int argc, char* argv[])
{
Array<double, 2> fund(2,2);
fund = 3.0;
double rate = RTSumAll(Array<double, 2>(fund * 6.0));
}
Cheers, Patrick