SUNphi  1.0
ScalarWrap.hpp
Go to the documentation of this file.
1 #ifndef _SCALAR_WRAP_HPP
2 #define _SCALAR_WRAP_HPP
3 
4 /// \file ScalarWrap.hpp
5 ///
6 /// \brief Defines a class which wraps a pure scalar into a SmET, to
7 /// be used in expressions
8 ///
9 
10 #include <smet/NnarySmET.hpp>
11 #include <tens/TensKind.hpp>
12 
13 namespace SUNphi
14 {
15  // Base type to qualify as ScalarWrap
17 
18  /// Class to hold a scalar promoting it into a SmET
19  ///
20  /// \todo Check what happens if called with a SmET
21  template <typename _Fund, // Type to be wrapped
22  typename..._Refs> // Extra types, need to be empty
23  class ScalarWrapper :
24  public BaseScalarWrapper, // Inherit from BaseTransposer to detect in expression
25  public NnarySmET<ScalarWrapper<_Fund,_Refs...>> // Inherit from NnarySmET
26  {
27 
28  public:
29 
31 
32  /// Returns the size of a component, which is always 1
33  int compSize() const
34  {
35  return 1;
36  }
37 
38  /// Empty TensorKind
40 
41  /// Fundamental type
42  PROVIDE_FUND(_Fund);
43 
45 
46  /// Type of the scalar ref, reference or not depending on _Fund
47  ///
48  /// \todo explain
49  using ScRef=
51 
52  /// Provides a reference or a value, depending on \c _Fund
54 
55  // Attributes
57  IS_ASSIGNABLE_ATTRIBUTE(/*! The SmET is assignable if ref is */,
58  isLvalue<_Fund> and (not isConst<_Fund>));
59  PROVIDE_IS_ALIASING(/*! Check with storage */,
60  return alias==scRef;);
61 
62  /// Returns a component-merged version
63  PROVIDE_GET_MERGED_COMPS_VIEW(/*! Returns the ScalarWrap itself */,
64  return *this);
65 
66  PROVIDE_MERGEABLE_COMPS(/* There is no component */,
67  IntSeq<0>); // Left and right borders
68 
69  /// Assignement operator
70  template <typename Oth> // Other type
71  ScalarWrapper& operator=(Oth&& oth) ///< Other object
72  {
73  return (*this)=oth;
74  }
75 
76  /// Provides either the const or non-const evaluator
77  template <typename...Args> /// Arguments (need to be empty)
78  auto& eval(Args&&...args)
79  const
80  {
81  std::cout<<" is: "<<isLvalue<_Fund><<", "<<isLvalue<decltype(scRef)><<" "<<scRef<<std::endl;
83 
84  return scRef;
85  }
86 
88 
89  /// Constructor taking universal reference
90  template <typename T,
92  explicit ScalarWrapper(T&& val) : scRef(forw<T>(val))
93  {
94  }
95  };
96 
97  // Check that a test ScalarWrapper is a NnarySmET
99 
100  // Build ScalarWrapper from scalarWrap
101  SIMPLE_NNARY_SMET_BUILDER(scalarWrap,ScalarWrapper);
102 
103  // Simplifies scalarWrap(smet) -> smet
105 }
106 
107 #endif
int compSize() const
Returns the size of a component, which is always 1.
Definition: ScalarWrap.hpp:33
ScalarWrapper< Ts... > scalarWrap(Ts &&...smets)
Definition: ScalarWrap.hpp:101
#define STATIC_ASSERT_ARE_N_TYPES(N, UNEXP_PARPACK)
Static assert if not passing exactly N types.
Definition: TypeTraits.hpp:422
#define PROVIDE_TK(...)
Provides the Tk member.
Definition: BaseSmET.hpp:94
#define PROVIDE_FUND(...)
Provides the Fund member.
Definition: BaseSmET.hpp:108
#define STORING
Set the SmET to storing.
Definition: BaseSmET.hpp:82
#define PROVIDE_GET_MERGED_COMPS_VIEW(DESCRIPTION,...)
Provides a getMergedCompsView method, taking Is as template parameter.
Definition: BaseSmET.hpp:216
#define IDENTITY_REPRESENTATIVE_FUNCTION
Provide an identity representative function.
Definition: NnarySmET.hpp:29
static constexpr const char * name()
Name of the Tk provided with "name()" suffix.
Definition: TensKind.hpp:117
#define PROVIDE_MERGEABLE_COMPS(LONG_DESCRIPTION,...)
Definition: BaseSmET.hpp:179
#define IS_ASSIGNABLE_ATTRIBUTE(LONG_DESCRIPTION,...)
Provides a isAssignable attribute.
Definition: BaseSmET.hpp:155
#define STATIC_ASSERT_IS_NNARY_SMET(...)
Defines the check for a Nnary SmET.
Definition: NnarySmET.hpp:394
static constexpr int element()
Get the I element of the sequence.
Definition: IntSeq.hpp:95
ScalarWrapper(T &&val)
Constructor taking universal reference.
Definition: ScalarWrap.hpp:92
decltype(auto) operator+(T1 &&smet1, T2 &&smet2)
Implement smet1+smet2.
Definition: Add.hpp:87
ScRef scRef
Provides a reference or a value, depending on _Fund.
Definition: ScalarWrap.hpp:53
#define PROVIDE_ALSO_NON_CONST_METHOD(NAME)
Definition: TypeTraits.hpp:376
#define SIMPLE_NNARY_SMET_BUILDER(BUILDER,NNARY_SMET)
Definition: NnarySmET.hpp:406
ScalarWrapper & operator=(Oth &&oth)
Assignement operator.
Definition: ScalarWrap.hpp:71
#define PROVIDE_NNARY_SMET_REFS_AND_CHECK_ARE_N(N)
Definition: NnarySmET.hpp:126
auto & eval(Args &&...args) const
Provides either the const or non-const evaluator.
Definition: ScalarWrap.hpp:78
decltype(auto) evalThroughRepresentativeFunctionPassingCompsByName(Ts &&...ts)
Definition: NnarySmET.hpp:101
#define ABSORB_DUPLICATED_NNARY_SMET_CALL(CALLER,NNARY_SMET)
Definition: NnarySmET.hpp:515
#define DEFINE_BASE_TYPE(TYPE,...)
Definition: TypeTraits.hpp:526
#define PROVIDE_IS_ALIASING(LONG_DESCRIPTION,...)
Provides a isAliasing method, taking alias as argument.
Definition: BaseSmET.hpp:127