NumberAsExpression.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
11 #include "Utilities/TMPL.hpp"
12 
13 namespace TensorExpressions {
14 /// \ingroup TensorExpressionsGroup
15 /// \brief Defines an expression representing a `double`
17  : public TensorExpression<NumberAsExpression, double, tmpl::list<>,
18  tmpl::list<>, tmpl::list<>> {
19  using type = double;
20  using symmetry = tmpl::list<>;
21  using index_list = tmpl::list<>;
22  using args_list = tmpl::list<>;
23  using structure = Tensor_detail::Structure<symmetry>;
24  static constexpr auto num_tensor_indices = 0;
25 
26  NumberAsExpression(const double number) : number_(number) {}
27  ~NumberAsExpression() override = default;
28 
29  /// \brief Returns the number represented by the expression
30  ///
31  /// \details
32  /// While a NumberAsExpression does not store a rank 0 Tensor, it does
33  /// represent one. This is why, unlike other derived TensorExpression types,
34  /// there is no second variadic template parameter for the generic indices.
35  /// In addition, this is why this template is only instantiated for the case
36  /// where `Structure` is equal to the Structure of a rank 0 Tensor.
37  ///
38  /// \tparam Structure the Structure of the rank 0 Tensor represented by this
39  /// expression
40  /// \return the number represented by this expression
41  template <typename Structure>
43  const size_t /*storage_index*/) const noexcept {
44  static_assert(std::is_same_v<Structure, structure>,
45  "In retrieving the number stored by a NumberAsExpression, "
46  "the provided Structure should be that of a rank 0 Tensor.");
47  return number_;
48  }
49 
50  private:
51  double number_;
52 };
53 } // namespace TensorExpressions
TensorExpressions::NumberAsExpression::get
double get(const size_t) const noexcept
Returns the number represented by the expression.
Definition: NumberAsExpression.hpp:42
TensorExpression.hpp
TensorExpressions::NumberAsExpression
Defines an expression representing a double
Definition: NumberAsExpression.hpp:16
Structure.hpp
TensorExpressions
Definition: AddSubtract.hpp:30
SPECTRE_ALWAYS_INLINE
#define SPECTRE_ALWAYS_INLINE
Definition: ForceInline.hpp:16
cstddef
ForceInline.hpp
TMPL.hpp