NumberAsExpression.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cstddef>
8 
11 #include "Utilities/Requires.hpp"
12 #include "Utilities/TMPL.hpp"
13 
14 namespace TensorExpressions {
15 /// \ingroup TensorExpressionsGroup
16 /// \brief Defines an expression representing a `double`
18  : public TensorExpression<NumberAsExpression, double, tmpl::list<>,
19  tmpl::list<>, tmpl::list<>> {
20  using type = double;
21  using symmetry = tmpl::list<>;
22  using index_list = tmpl::list<>;
23  using args_list = tmpl::list<>;
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 this template is only defined for the case
34  /// where `TensorIndices` is empty.
35  ///
36  /// \tparam TensorIndices the TensorIndexs of the LHS tensor and RHS tensor
37  /// expression
38  /// \return the number represented by this expression
39  template <typename... TensorIndices,
40  Requires<sizeof...(TensorIndices) == 0> = nullptr>
42  const std::array<size_t, 0>& /*multi_index*/) const noexcept {
43  return number_;
44  }
45 
46  private:
47  double number_;
48 };
49 } // namespace TensorExpressions
TensorExpressions::NumberAsExpression::get
double get(const std::array< size_t, 0 > &) const noexcept
Returns the number represented by the expression.
Definition: NumberAsExpression.hpp:41
TensorExpression.hpp
TensorExpressions::NumberAsExpression
Defines an expression representing a double
Definition: NumberAsExpression.hpp:17
TensorExpressions
Definition: AddSubtract.hpp:36
SPECTRE_ALWAYS_INLINE
#define SPECTRE_ALWAYS_INLINE
Definition: ForceInline.hpp:16
cstddef
array
ForceInline.hpp
Requires.hpp
Requires
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t
Definition: Requires.hpp:67
TMPL.hpp