SUNphi  1.0
Add.hpp
Go to the documentation of this file.
1 #ifndef _ADD_HPP
2 #define _ADD_HPP
3 
4 /// \file Add.hpp
5 ///
6 /// \brief Defines a class which take the sum of two SmETs
7 
8 #include <smet/Reference.hpp>
9 #include <smet/NnarySmET.hpp>
10 #include <tens/TensKind.hpp>
11 #include <tens/TensClass.hpp>
12 
13 namespace SUNphi
14 {
15  // Base type to qualify as \c Adder
17 
18  /// Class to add two \c SmET
19  template <typename..._Refs> // Addendum types
20  class Adder :
21  public BaseAdder, // Inherit from \c BaseAdder to detect in expression
22  public NnarySmET<Adder<_Refs...>>, // Inherit from \c NnarySmET
23  public ConstrainAreSmETs<_Refs...> // Constrain all \c Refs to be \c SmET
24  {
25 
27 
28  public:
29 
30  /// Position of the references
31  enum Pos_t{ADDEND1,
32  ADDEND2};
33 
34  /// Representative function of the sum operation
35  template <typename Addend1, // Type of the first addend
36  typename Addend2> // Type of the second addend
37  static DECLAUTO representativeFunction(Addend1&& addend1, ///< First addend
38  Addend2&& addend2) ///< Second addend
39  {
40  return addend1+addend2;
41  }
42 
44 
45  // Attributes
48 
49  /// \c TensKind of the result
50  ///
51  /// \todo Improve, the return type could be decided studying what
52  /// suits best the computational
54 
56 
58 
60  };
61 
62  // Check that a test Adder is a \c NnarySmET
63  namespace CheckAdderIsNnarySmet
64  {
65  /// Tensor comp for test
66  using MyTc=
67  TensComp<double,1>;
68 
69  /// Tensor kind to be tested
70  using MyTk=
71  TensKind<MyTc>;
72 
73  /// Tensor to be tested
74  using MyT=
75  Tens<MyTk,double>;
76 
77  STATIC_ASSERT_IS_NNARY_SMET(Adder<MyT,MyT>);
78  }
79 
80  // Build Adder from add
82 
83  /// Implement smet1+smet2
84  template <typename T1, // Type of the first expression
85  typename T2, // Type of the second expression
87  DECLAUTO operator+(T1&& smet1, ///< First addend
88  T2&& smet2) ///< Second addend
89  {
90  return add(forw<T1>(smet1),forw<T2>(smet2));
91  }
92 }
93 
94 #endif
#define PROVIDE_TK(...)
Provides the Tk member.
Definition: BaseSmET.hpp:94
#define NO_EXTRA_MERGE_DELIMS
Add an empty ExtraDelims.
Definition: NnarySmET.hpp:319
#define PROVIDE_SIMPLE_NNARY_COMP_SIZE
Definition: NnarySmET.hpp:151
#define REPRESENTATIVE_FUNCTION_WINS_ALL
Provides Fund, eval and mergedComps according to representativeFunction.
Definition: NnarySmET.hpp:432
Pos_t
Position of the references.
Definition: Add.hpp:31
Adder(SMETS &&...smets)
Definition: Add.hpp:59
Adder< Ts... > add(Ts &&...smets)
Definition: Add.hpp:81
#define FORWARD_IS_ALIASING_TO_REFS
Definition: NnarySmET.hpp:420
#define PROVIDE_NNARY_SMET_SIMPLE_CREATOR(NNARY_SMET)
Defines a simple creator taking n references.
Definition: NnarySmET.hpp:383
#define STATIC_ASSERT_IS_NNARY_SMET(...)
Defines the check for a Nnary SmET.
Definition: NnarySmET.hpp:394
#define SFINAE_ON_TEMPLATE_ARG(...)
Definition: SFINAE.hpp:24
#define NOT_STORING
Set the SmET to not-storing.
Definition: BaseSmET.hpp:86
decltype(auto) operator+(T1 &&smet1, T2 &&smet2)
Implement smet1+smet2.
Definition: Add.hpp:87
#define DECLAUTO
Short name for decltype(auto)
#define SIMPLE_NNARY_SMET_BUILDER(BUILDER,NNARY_SMET)
Definition: NnarySmET.hpp:406
#define PROVIDE_NNARY_SMET_REFS_AND_CHECK_ARE_N(N)
Definition: NnarySmET.hpp:126
decltype(auto) evalThroughRepresentativeFunctionPassingCompsByName(Ts &&...ts)
Definition: NnarySmET.hpp:101
#define DEFINE_BASE_TYPE(TYPE,...)
Definition: TypeTraits.hpp:526