dune-common  2.3.0
dotproduct.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_DOTPRODUCT_HH
4 #define DUNE_DOTPRODUCT_HH
5 
6 #include "ftraits.hh"
7 #include "typetraits.hh"
8 #include "promotiontraits.hh"
9 
10 namespace Dune {
25  template<class T>
26  struct AlwaysVoid { typedef void type; };
27 
28  template<class T, class = void>
29  struct IsVector : false_type {};
30 
31  template<class T>
32  struct IsVector<T, typename AlwaysVoid<typename T::field_type>::type>
33  : true_type {};
34 
42  template<class A, class B>
43  inline typename enable_if<!IsVector<A>::value && !is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type> ::value, typename PromotionTraits<A,B>::PromotedType>::type
44  dot(const A & a, const B & b) {
45  return conj(a)*b;
46  }
47 
57  // fundamental type with A being a real type
58  template<class A, class B>
59  inline typename enable_if<!IsVector<A>::value && is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type>::value, typename PromotionTraits<A,B>::PromotedType>::type
60  dot(const A & a, const B & b) {
61  return a*b;
62  }
63 
73  // vectors
74  template<typename A, typename B>
75  // inline typename enable_if<IsVector<A>::value, typename PromotionTraits<typename FieldTraits<A>::field_type, typename FieldTraits<B>::field_type >::PromotedType>::type
76  inline typename enable_if<IsVector<A>::value, typename PromotionTraits<typename A::field_type, typename B::field_type >::PromotedType>::type
77  dot(const A & a, const B & b) {
78  return a.dot(b);
79  }
89  template<class A, class B>
90  inline typename enable_if<!IsVector<A>::value && !is_same<typename FieldTraits<A>::field_type,typename FieldTraits<A>::real_type> ::value, typename PromotionTraits<A,B>::PromotedType>::type
91  dotT(const A & a, const B & b) {
92  return a*b;
93  }
94 
102  template<class A, class B>
103  inline typename enable_if<IsVector<A>::value, typename PromotionTraits<typename A::field_type, typename B::field_type >::PromotedType>::type
104  dotT(const A & a, const B & b) {
105  return a*b;
106  }
107 
109 } // end namespace DUNE
110 
111 #endif // DUNE_DOTPRODUCT_HH