Index: testsuite/Makefile.am =================================================================== RCS file: /cvsroot/blitz/blitz/testsuite/Makefile.am,v retrieving revision 1.12 diff -u -d -b -w -r1.12 Makefile.am --- testsuite/Makefile.am 5 May 2004 21:29:00 -0000 1.12 +++ testsuite/Makefile.am 11 Sep 2004 05:45:53 -0000 @@ -18,7 +18,7 @@ module newet Olaf-Ronneberger-1 peter-bienstman-1 peter-bienstman-2 \ peter-bienstman-3 peter-bienstman-4 peter-bienstman-5 peter-nordlund-1 \ peter-nordlund-2 peter-nordlund-3 promote qcd reduce reindex reverse \ -shapecheck shape storage stub theodore-papadopoulo-1 tinymat tinyvec \ +shapecheck shape storage stub ternary theodore-papadopoulo-1 tinymat tinyvec \ transpose troyer-genilloud Ulisses-Mello-1 wei-ku-1 where Adnene_Ben_Abdallah_1_SOURCES = Adnene-Ben-Abdallah-1.cpp @@ -68,6 +68,7 @@ shape_SOURCES = shape.cpp storage_SOURCES = storage.cpp stub_SOURCES = stub.cpp +ternary_SOURCES = ternary.cpp theodore_papadopoulo_1_SOURCES = theodore-papadopoulo-1.cpp tinymat_SOURCES = tinymat.cpp tinyvec_SOURCES = tinyvec.cpp Index: blitz/array/asexpr.h =================================================================== RCS file: /cvsroot/blitz/blitz/blitz/array/asexpr.h,v retrieving revision 1.7 diff -u -d -b -w -r1.7 asexpr.h --- blitz/array/asexpr.h 31 Dec 2003 01:50:04 -0000 1.7 +++ blitz/array/asexpr.h 11 Sep 2004 05:45:53 -0000 @@ -37,6 +37,7 @@ template struct asExpr { + enum { isBlitz = false }; typedef _bz_ArrayExprConstant T_expr; static T_expr getExpr(const T& x) { return T_expr(x); } }; @@ -45,6 +46,7 @@ template struct asExpr<_bz_ArrayExpr > { + enum { isBlitz = true }; typedef _bz_ArrayExpr T_expr; static const T_expr& getExpr(const T_expr& x) { return x; } }; @@ -53,6 +55,7 @@ template struct asExpr > { + enum { isBlitz = true }; typedef FastArrayIterator T_expr; static T_expr getExpr(const Array& x) { return x.beginFast(); } }; @@ -61,6 +64,7 @@ template struct asExpr > { + enum { isBlitz = true }; typedef IndexPlaceholder T_expr; static T_expr getExpr(T_expr x) { return x; } }; Index: blitz/array/newet-macros.h =================================================================== RCS file: /cvsroot/blitz/blitz/blitz/array/newet-macros.h,v retrieving revision 1.14 diff -u -d -b -w -r1.14 newet-macros.h --- blitz/array/newet-macros.h 9 Mar 2004 21:51:33 -0000 1.14 +++ blitz/array/newet-macros.h 11 Sep 2004 05:45:53 -0000 @@ -31,6 +31,41 @@ #ifdef BZ_TEMPLATES_AS_TEMPLATE_ARGUMENTS /* + * Helpers + */ +// Inspired by Boost enable_if library +template +struct enable_if_c { + typedef T type; +}; + +template +struct enable_if_c {}; + +template +struct enable_if : public enable_if_c {}; + +template +struct IsAtLeastOneOperandBlitz2 { + enum { value = asExpr::isBlitz || asExpr::isBlitz }; +}; + +template +struct IsAtLeastOneOperandBlitz3 { + enum { value = IsAtLeastOneOperandBlitz2::value || asExpr::isBlitz }; +}; + +template +const T& unwrap(const T& t) { return t; } + +template +const T& unwrap(const ETBase& t) { + return t.unwrap(); +} + +// etc + +/* * Unary functions and operators */ @@ -98,12 +133,13 @@ template \ _bz_inline_et \ typename BzTernaryExprResult::T_result \ -name(const ETBase& d1, const ETBase& d2, const ETBase& d3) \ +name(const T1& d1, const T2& d2, const T3& d3, \ + typename enable_if< IsAtLeastOneOperandBlitz3 >::type* dummy = 0)\ { \ typedef typename BzTernaryExprResult::T_result result; \ - return result(asExpr::getExpr(d1.unwrap()), \ - asExpr::getExpr(d2.unwrap()), \ - asExpr::getExpr(d3.unwrap())); \ + return result(asExpr::getExpr(unwrap(d1)), \ + asExpr::getExpr(unwrap(d2)), \ + asExpr::getExpr(unwrap(d3))); \ } #else @@ -206,7 +242,8 @@ applic<_bz_typename asExpr::T_expr::T_numtype, \ _bz_typename asExpr::T_expr::T_numtype, \ _bz_typename asExpr::T_expr::T_numtype> > > \ -name(const ETBase& d1, const ETBase& d2, const ETBase& d3) \ +name(const T1& d1, const T2& d2, const T3& d3, \ + typename enable_if< IsAtLeastOneOperandBlitz3 >::type* dummy = 0)\ { \ return _bz_ArrayExpr<_bz_ArrayExprTernaryOp< \ _bz_typename asExpr::T_expr, \ @@ -215,9 +252,9 @@ applic<_bz_typename asExpr::T_expr::T_numtype, \ _bz_typename asExpr::T_expr::T_numtype, \ _bz_typename asExpr::T_expr::T_numtype> > > \ - (asExpr::getExpr(d1.unwrap()), \ - asExpr::getExpr(d2.unwrap()), \ - asExpr::getExpr(d3.unwrap())); \ + (asExpr::getExpr(unwrap(d1)), \ + asExpr::getExpr(unwrap(d2)), \ + asExpr::getExpr(unwrap(d3))); \ } #endif /* BZ_TEMPLATES_AS_TEMPLATE_ARGUMENTS */