HerdSoftware  0.4.0
CooArray.h
Go to the documentation of this file.
1 /*
2  * CooArray.h
3  *
4  * Created on: 9 Jan 2019
5  * Author: Nicola Mori
6  */
7 
8 #ifndef HERD_COOARRAY_H_
9 #define HERD_COOARRAY_H_
10 
11 // HerdSoftware headers
14 
15 namespace Herd {
22 template <typename ContainedClass> class CooArray : public ArrayForwarder<ContainedClass, 3> {
23 public:
25 
28  constexpr CooArray() = default;
29 
34  constexpr CooArray(const CooArray<ContainedClass> &c) : BaseType(c) {}
35 
41  // Note by VF: This one used to have a variadic template and was tricky to write. See
42  // https://stackoverflow.com/questions/6893700/how-to-construct-stdarray-object-with-initializer-list
43  // Note by NM: the implementation making use of variadic templates blocked the possibility to implement a copy
44  // constructor
45  template <typename U, typename V, typename Z>
46  constexpr CooArray(U &&v1, V &&v2, Z &&v3)
47  : BaseType({static_cast<ContainedClass>(v1), static_cast<ContainedClass>(v2), static_cast<ContainedClass>(v3)}) {}
48 
54  constexpr CooArray(const std::array<ContainedClass, 3> &values) : BaseType(values) {}
55  constexpr CooArray(std::array<ContainedClass, 3> &&values) : BaseType(std::move(values)) {}
56 
63  BaseType::operator=(lhs);
64  return *this;
65  }
66 
75  constexpr ContainedClass &operator[](const RefFrame::Coo &coo) { return BaseType::operator[](static_cast<int>(coo)); }
76 
85  constexpr const ContainedClass &operator[](const RefFrame::Coo &coo) const {
86  return BaseType::operator[](static_cast<int>(coo));
87  }
88 
98  constexpr ContainedClass &at(const RefFrame::Coo &coo) { return BaseType::at(static_cast<int>(coo)); }
99 
109  constexpr const ContainedClass &at(const RefFrame::Coo &coo) const { return BaseType::at(static_cast<int>(coo)); }
110 };
111 
112 } // namespace Herd
113 
114 #endif /* HERD_COOARRAY_H_ */
Herd::CooArray::operator[]
constexpr const ContainedClass & operator[](const RefFrame::Coo &coo) const
Accesses an element without validity check on the element index.
Definition: CooArray.h:85
Herd::CooArray
An array that accepts coordinates as subscripts.
Definition: CooArray.h:22
Herd::CooArray::CooArray
constexpr CooArray(const std::array< ContainedClass, 3 > &values)
Array constructors.
Definition: CooArray.h:54
Herd::CooArray::CooArray
constexpr CooArray(std::array< ContainedClass, 3 > &&values)
Definition: CooArray.h:55
Herd
CssGeoParams.h CssGeoParams class declaration.
Definition: CaloPDCalibrationAlgo.h:22
Herd::ArrayForwarder< ContainedClass, 3 >::at
_GLIBCXX17_CONSTEXPR reference at(size_type __n)
Definition: ArrayForwarder.h:152
RefFrame.h
Herd::CooArray::at
constexpr ContainedClass & at(const RefFrame::Coo &coo)
Accesses an element with validity check on the element index.
Definition: CooArray.h:98
Herd::CooArray::operator=
constexpr CooArray< ContainedClass > & operator=(const CooArray< ContainedClass > &lhs)
Assignment operator.
Definition: CooArray.h:62
ArrayForwarder.h
Herd::CooArray::CooArray
constexpr CooArray(const CooArray< ContainedClass > &c)
Copy constructor.
Definition: CooArray.h:34
Herd::RefFrame::Coo
Coo
Aliases for the three space coordinates.
Definition: RefFrame.h:24
Herd::ArrayForwarder
A forwarder class for std::array.
Definition: ArrayForwarder.h:48
Herd::CooArray::CooArray
constexpr CooArray()=default
Default constructor.
Herd::CooArray::operator[]
constexpr ContainedClass & operator[](const RefFrame::Coo &coo)
Accesses an element without validity check on the element index.
Definition: CooArray.h:75
Herd::ArrayForwarder< ContainedClass, 3 >::operator[]
_GLIBCXX17_CONSTEXPR reference operator[](size_type __n) noexcept
Definition: ArrayForwarder.h:148
Herd::CooArray::at
constexpr const ContainedClass & at(const RefFrame::Coo &coo) const
Accesses an element with validity check on the element index.
Definition: CooArray.h:109
Herd::CooArray::CooArray
constexpr CooArray(U &&v1, V &&v2, Z &&v3)
Initializer list constructor.
Definition: CooArray.h:46