RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
addMissingOperators.hh
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the C++-library RFFGen. */
4 /* Copyright 2015 Lars Lubkoll */
5 /* */
6 /* RFFGen is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* RFFGen is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with RFFGen. If not, see <http://www.gnu.org/licenses/>. */
18 /* */
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 
21 #ifndef RFFGEN_UTIL_ADDMISSINGOPERATORS_HH
22 #define RFFGEN_UTIL_ADDMISSINGOPERATORS_HH
23 
24 #include <type_traits>
25 #include "base.hh"
26 #include "staticChecks.hh"
27 
28 namespace RFFGen
29 {
31  template < class Arg ,
32  class = std::enable_if_t< !std::is_base_of<Base,Arg>() && !std::is_arithmetic<Arg>() > ,
33  class = std::enable_if_t< !Checks::summation<Arg>() &&
34  Checks::inPlaceSummation<Arg>() > >
35  auto operator+(Arg x, const Arg& y)
36  {
37  x += y;
38  return x;
39  }
40 
42  template < class Arg , class ScalarArg ,
43  class = std::enable_if_t< std::is_arithmetic<ScalarArg>::value > ,
44  class = std::enable_if_t< !std::is_base_of<Base,Arg>() && !std::is_arithmetic<Arg>() > ,
45  class = std::enable_if_t< !Checks::multiplicationWithArithmeticFromLeft<Arg,ScalarArg>() &&
46  Checks::inPlaceMultiplicationWithArithmetic<Arg,ScalarArg>() > >
47  auto operator*( ScalarArg a , Arg x )
48  {
49  x *= a;
50  return x;
51  }
52 
54  template < class Arg , class ScalarArg ,
55  class = std::enable_if_t< std::is_arithmetic<ScalarArg>::value > ,
56  class = std::enable_if_t< !std::is_base_of<Base,Arg>() && !std::is_arithmetic<Arg>::value> ,
57  class = std::enable_if_t< !Checks::multiplicationWithArithmeticFromRight<Arg,ScalarArg>() &&
58  Checks::inPlaceMultiplicationWithArithmetic<Arg,ScalarArg>() > >
59  auto operator*( Arg x , ScalarArg a )
60  {
61  x *= a;
62  return x;
63  }
64 
66  template < class Arg1 , class Arg2 ,
67  class = std::enable_if_t< !std::is_base_of<Arg1,Base>() && !std::is_base_of<Arg2,Base>() > ,
68  class = std::enable_if_t< !std::is_arithmetic<Arg1>() && !std::is_arithmetic<Arg2>() > ,
69  class = std::enable_if_t< !Checks::multiplication<Arg1,Arg2>() &&
70  Checks::inPlaceMultiplication<Arg1,Arg2>() > >
71  auto operator*( Arg1 x, const Arg2& y)
72  {
73  x *= y;
74  return x;
75  }
76 
78  template < class Arg1 , class Arg2 ,
79  class = std::enable_if_t< !std::is_base_of<Arg1,Base>() && !std::is_base_of<Arg2,Base>() > ,
80  class = std::enable_if_t< !std::is_arithmetic<Arg1>() && !std::is_arithmetic<Arg2>() > ,
81  class = std::enable_if_t< !Checks::multiplication<Arg1,Arg2>() &&
82  !Checks::inPlaceMultiplication<Arg1,Arg2>() > ,
83  class = std::enable_if_t< Checks::callToRightMultiply<Arg1,Arg2>() > >
84  auto operator*( Arg1 x , const Arg2& y)
85  {
86  return x.rightmultiplyany(y);
87  }
88 }
89 
90 #endif // RFFGEN_UTIL_ADDMISSINGOPERATORS_HH
Static checks for detection of presence of different operators and functions.