ElementsData.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_VIEWS_ELEMENTS_ELEMENTSDATA_H_
36 #define _BLAZE_MATH_VIEWS_ELEMENTS_ELEMENTSDATA_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/util/Assert.h>
44 #include <blaze/util/SmallVector.h>
45 #include <blaze/util/Types.h>
46 #include <blaze/util/Unused.h>
47 
48 
49 namespace blaze {
50 
51 //=================================================================================================
52 //
53 // CLASS DEFINITION
54 //
55 //=================================================================================================
56 
57 //=================================================================================================
58 //
59 // CLASS TEMPLATE SPECIALIZATION FOR TWO COMPILE TIME ARGUMENTS
60 //
61 //=================================================================================================
62 
63 //*************************************************************************************************
73 template< size_t... CEAs > // Compile time element arguments
74 struct ElementsData
75 {
76  public:
77  //**Type definitions****************************************************************************
78  using Indices = std::array<size_t,sizeof...(CEAs)>;
79  //**********************************************************************************************
80 
81  //**Constructors********************************************************************************
84  template< typename... REAs >
85  explicit inline ElementsData( REAs... args ) noexcept;
86  // No explicitly declared copy constructor.
88  //**********************************************************************************************
89 
90  //**Destructor**********************************************************************************
91  // No explicitly declared destructor.
92  //**********************************************************************************************
93 
94  //**Assignment operators************************************************************************
95  ElementsData& operator=( const ElementsData& ) = delete;
96  //**********************************************************************************************
97 
98  //**Utility functions***************************************************************************
101  static inline constexpr const Indices& idces() noexcept;
102  static inline constexpr size_t idx ( size_t i ) noexcept;
103  static inline constexpr size_t size () noexcept;
105  //**********************************************************************************************
106 
107  private:
108  //**Member variables****************************************************************************
111  static constexpr Indices indices_{ { CEAs... } };
112 
113  //**********************************************************************************************
114 };
116 //*************************************************************************************************
117 
118 
119 //*************************************************************************************************
121 // Definition and initialization of the static member variables
122 template< size_t... CEAs > // Compile time element arguments
123 constexpr typename ElementsData<CEAs...>::Indices ElementsData<CEAs...>::indices_;
125 //*************************************************************************************************
126 
127 
128 //*************************************************************************************************
134 template< size_t... CEAs > // Compile time element arguments
135 template< typename... REAs > // Optional element arguments
136 inline ElementsData<CEAs...>::ElementsData( REAs... args ) noexcept
137 {
138  UNUSED_PARAMETER( args... );
139 }
141 //*************************************************************************************************
142 
143 
144 //*************************************************************************************************
150 template< size_t... CEAs > // Compile time element arguments
151 inline constexpr const typename ElementsData<CEAs...>::Indices& ElementsData<CEAs...>::idces() noexcept
152 {
153  return indices_;
154 }
156 //*************************************************************************************************
157 
158 
159 //*************************************************************************************************
166 template< size_t... CEAs > // Compile time element arguments
167 inline constexpr size_t ElementsData<CEAs...>::idx( size_t i ) noexcept
168 {
169  BLAZE_USER_ASSERT( i < size(), "Invalid element access index" );
170  return indices_[i];
171 }
173 //*************************************************************************************************
174 
175 
176 //*************************************************************************************************
182 template< size_t... CEAs > // Compile time element arguments
183 inline constexpr size_t ElementsData<CEAs...>::size() noexcept
184 {
185  return sizeof...( CEAs );
186 }
188 //*************************************************************************************************
189 
190 
191 
192 
193 //=================================================================================================
194 //
195 // CLASS TEMPLATE SPECIALIZATION FOR ZERO COMPILE TIME ELEMENT ARGUMENTS
196 //
197 //=================================================================================================
198 
199 //*************************************************************************************************
207 template<>
208 struct ElementsData<>
209 {
210  public:
211  //**Type definitions****************************************************************************
212  using Indices = SmallVector<size_t,8UL>;
213  //**********************************************************************************************
214 
215  //**Constructors********************************************************************************
218  template< typename T, typename... REAs >
219  explicit inline ElementsData( const T* indices, size_t n, REAs... args );
220 
221  inline ElementsData( const ElementsData& ) = default;
222  inline ElementsData( ElementsData&& ) = default;
224  //**********************************************************************************************
225 
226  //**Destructor**********************************************************************************
227  // No explicitly declared destructor.
228  //**********************************************************************************************
229 
230  //**Assignment operators************************************************************************
231  ElementsData& operator=( const ElementsData& ) = delete;
232  //**********************************************************************************************
233 
234  //**Utility functions***************************************************************************
237  inline const Indices& idces() const noexcept;
238  inline size_t idx ( size_t i ) const noexcept;
239  inline size_t size () const noexcept;
241  //**********************************************************************************************
242 
243  private:
244  //**Member variables****************************************************************************
247  Indices indices_;
248 
249  //**********************************************************************************************
250 };
252 //*************************************************************************************************
253 
254 
255 //*************************************************************************************************
263 template< typename T // Type of the element indices
264  , typename... REAs > // Optional element arguments
265 inline ElementsData<>::ElementsData( const T* indices, size_t n, REAs... args )
266  : indices_( indices, indices+n ) // The indices of the elements in the vector
267 {
268  UNUSED_PARAMETER( args... );
269 }
271 //*************************************************************************************************
272 
273 
274 //*************************************************************************************************
280 inline const ElementsData<>::Indices& ElementsData<>::idces() const noexcept
281 {
282  return indices_;
283 }
285 //*************************************************************************************************
286 
287 
288 //*************************************************************************************************
297 inline size_t ElementsData<>::idx( size_t i ) const noexcept
298 {
299  BLAZE_USER_ASSERT( i < size(), "Invalid element access index" );
300  return indices_[i];
301 }
303 //*************************************************************************************************
304 
305 
306 //*************************************************************************************************
312 inline size_t ElementsData<>::size() const noexcept
313 {
314  return indices_.size();
315 }
317 //*************************************************************************************************
318 
319 } // namespace blaze
320 
321 #endif
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Header file for the UNUSED_PARAMETER function template.
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE size_t size(const Vector< VT, TF > &vector) noexcept
Returns the current size/dimension of the vector.
Definition: Vector.h:265
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for run time assertion macros.
Header file for the SmallVector implementation.
void UNUSED_PARAMETER(const Args &...)
Suppression of unused parameter warnings.
Definition: Unused.h:81