Go to the documentation of this file.00001 #ifndef VIENNAMATH_COMPILETIME_CT_UNARY_EXPR_HPP
00002 #define VIENNAMATH_COMPILETIME_CT_UNARY_EXPR_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <ostream>
00021 #include "viennamath/forwards.h"
00022 #include "viennamath/compiletime/unary_op_tags.hpp"
00023
00028 namespace viennamath
00029 {
00030
00031
00037 template <typename LHS,
00038 typename OP>
00039 class ct_unary_expr
00040 {
00041 typedef typename expression_traits<LHS>::const_reference_type internal_lhs_type;
00042 public:
00043 typedef typename OP::numeric_type numeric_type;
00044
00045 typedef LHS lhs_type;
00046 typedef OP op_type;
00047
00048 explicit ct_unary_expr() : lhs_(LHS()) {}
00049
00050 explicit ct_unary_expr(internal_lhs_type lhs) : lhs_(lhs){}
00051
00053 internal_lhs_type lhs() const { return lhs_; }
00054
00055 template <typename VectorType>
00056 numeric_type operator()(VectorType const & v) const
00057 {
00058
00059 return OP::apply(static_cast<numeric_type>(lhs_(v)), static_cast<numeric_type>(rhs_(v)));
00060 }
00061
00062 private:
00063 internal_lhs_type lhs_;
00064 };
00065
00066
00067
00069 template <typename LHS, typename OP>
00070 std::ostream& operator<<(std::ostream & stream, ct_unary_expr<LHS, OP> const & other)
00071 {
00072 stream << "[" << other.lhs() << OP().str() << "]";
00073 return stream;
00074 }
00075
00076
00077 }
00078
00079 #endif