// -*- C++ -*- /*************************************************************************** * blitz/array/asexpr.h Declaration of the asExpr helper functions * * $Id$ * * Copyright (C) 1997-2011 Todd Veldhuizen * * This file is a part of Blitz. * * Blitz is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * Blitz is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with Blitz. If not, see . * * Suggestions: blitz-devel@lists.sourceforge.net * Bugs: blitz-support@lists.sourceforge.net * * For more information, please see the Blitz++ Home Page: * https://sourceforge.net/projects/blitz/ * ***************************************************************************/ #ifndef BZ_ASEXPR_H #define BZ_ASEXPR_H #include #include BZ_NAMESPACE(blitz) // The traits class asExpr converts arbitrary things to // expression templatable operands. // Default to scalar. template struct asExpr { typedef _bz_ArrayExpr<_bz_ArrayExprConstant > T_expr; static T_expr getExpr(const T& x); }; // Already an expression template term template struct asExpr<_bz_ArrayExpr > { typedef _bz_ArrayExpr T_expr; static const T_expr& getExpr(const T_expr& x); }; // Specialization of asExpr for array operands // why doesn't it wrap iterators in an ArrayExpr? template struct asExpr > { //typedef FastArrayIterator T_expr; typedef _bz_ArrayExpr > T_expr; static T_expr getExpr(const Array& x); }; // Specialization of asExpr for tinyvector operands template struct asExpr > { typedef _bz_ArrayExpr > T_expr; static T_expr getExpr(const TinyVector& x); }; // Specialization of asExpr for tinymatrix operands template struct asExpr > { typedef _bz_ArrayExpr > T_expr; static T_expr getExpr(const TinyMatrix& x); }; // Index placeholder template struct asExpr > { // typedef _bz_ArrayExpr > T_expr; typedef _bz_ArrayExpr > T_expr; static T_expr getExpr(const T_expr& x); }; // the levi-civita symbol template <> struct asExpr { typedef _bz_ArrayExpr T_expr; static T_expr getExpr(T_expr x); }; // Range template <> struct asExpr { typedef _bz_ArrayExpr T_expr; static T_expr getExpr(T_expr x); }; // traits class that transforms ETBase subclasses into the // ET<>-wrapped superclass and corresponding expression, but unlike // the asExpr class it leaves POD types alone. This is necessary so // operators on multicomponent arrays can resolve properly. template struct asET { typedef T T_wrapped; typedef T T_expr; }; template struct asET > { typedef ETBase::T_expr> T_wrapped; typedef typename asExpr::T_expr T_expr; }; template struct asET > { typedef ETBase >::T_expr> T_wrapped; typedef typename asExpr >::T_expr T_expr; }; template struct asET > { typedef ETBase >::T_expr> T_wrapped; typedef typename asExpr >::T_expr T_expr; }; template struct asET > { typedef ETBase >::T_expr> T_wrapped; typedef typename asExpr >::T_expr T_expr; }; // traits class that unwraps an ETBase type, otherwise leaves it untouched. template struct unwrapET { typedef T T_unwrapped; }; template struct unwrapET > { typedef T T_unwrapped; }; // traits classes that are used to switch between an ET type or an // unknown type. If the supplied type T is an ET type, T_selected will // be T_ifET, otherwise T. template struct selectET { typedef T_ifnotET T_selected; }; template struct selectET, T_ifnotET, T_ifET> { typedef ETBase T_selected; }; // for binary exprs, it is more complicated. if T1 or T2 are an ET, // T_ifET is selected, otherwise T_ifnotET. template struct selectET2 { typedef T_ifnotET T_selected; }; template struct selectET2, T2, T_ifnotET, T_ifET> { typedef ETBase T_selected; }; template struct selectET2, T_ifnotET, T_ifET> { typedef ETBase T_selected; }; template struct selectET2, ETBase, T_ifnotET, T_ifET> { typedef ETBase T_selected; }; // traits class that resolves to the ultimate numeric datatype used // for operations on the container. This is necessary because for // multicomponent containers we need to determine what the ultimate // POD data type is. template struct opType { typedef T T_optype; }; template struct opType > { typedef typename opType::T_optype T_optype; }; template struct opType > { typedef typename opType::T_optype T_optype; }; template struct opType > { typedef typename opType::T_optype T_optype; }; template struct opType > { typedef typename opType::T_optype T_optype; }; #ifdef BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS // traits classes that provide the return type of operations template