Blaze 3.9
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 <array>
45#include <blaze/util/AsConst.h>
46#include <blaze/util/Assert.h>
50#include <blaze/util/Types.h>
51
52
53namespace blaze {
54
55//=================================================================================================
56//
57// CLASS DEFINITION
58//
59//=================================================================================================
60
61//*************************************************************************************************
71template< typename... CEAs > // Compile time element arguments
72class ElementsData
73{};
75//*************************************************************************************************
76
77
78
79
80//=================================================================================================
81//
82// CLASS TEMPLATE SPECIALIZATION FOR INDEX SEQUENCES
83//
84//=================================================================================================
85
86//*************************************************************************************************
94template< size_t I // First element index
95 , size_t... Is > // Remaining element indices
96class ElementsData< index_sequence<I,Is...> >
97{
98 protected:
99 //**Compile time flags**************************************************************************
100 static constexpr size_t N = sizeof...( Is ) + 1UL;
101 //**********************************************************************************************
102
103 public:
104 //**Compile time flags**************************************************************************
106
110 static constexpr bool compileTimeArgs = true;
111 //**********************************************************************************************
112
113 //**Constructors********************************************************************************
116 template< typename... REAs >
117 explicit inline ElementsData( REAs... args ) noexcept;
118
119 ElementsData( const ElementsData& ) = default;
121 //**********************************************************************************************
122
123 //**Destructor**********************************************************************************
126 ~ElementsData() = default;
128 //**********************************************************************************************
129
130 //**Assignment operators************************************************************************
133 ElementsData& operator=( const ElementsData& ) = delete;
135 //**********************************************************************************************
136
137 //**Utility functions***************************************************************************
140 static constexpr decltype(auto) idces() noexcept;
141 static constexpr size_t idx ( size_t i ) noexcept;
142 static constexpr size_t size () noexcept;
144 //**********************************************************************************************
145
146 private:
147 //**Type definitions****************************************************************************
148 using Indices = std::array<size_t,N>;
149 //**********************************************************************************************
150
151 //**Member variables****************************************************************************
154 static constexpr Indices indices_{ { I, Is... } };
156 //**********************************************************************************************
157};
159//*************************************************************************************************
160
161
162//*************************************************************************************************
164#if BLAZE_CPP14_MODE
165// Definition and initialization of the static member variables
166template< size_t I // First element index
167 , size_t... Is > // Remaining element indices
168constexpr typename ElementsData< index_sequence<I,Is...> >::Indices
169 ElementsData< index_sequence<I,Is...> >::indices_;
170#endif
172//*************************************************************************************************
173
174
175//*************************************************************************************************
181template< size_t I // First element index
182 , size_t... Is > // Remaining element indices
183template< typename... REAs > // Optional element arguments
184inline ElementsData< index_sequence<I,Is...> >::ElementsData( REAs... args ) noexcept
185{
186 MAYBE_UNUSED( args... );
187}
189//*************************************************************************************************
190
191
192//*************************************************************************************************
198template< size_t I // First element index
199 , size_t... Is > // Remaining element indices
200constexpr decltype(auto) ElementsData< index_sequence<I,Is...> >::idces() noexcept
201{
202 return index_sequence<I,Is...>();
203}
205//*************************************************************************************************
206
207
208//*************************************************************************************************
215template< size_t I // First element index
216 , size_t... Is > // Remaining element indices
217constexpr size_t ElementsData< index_sequence<I,Is...> >::idx( size_t i ) noexcept
218{
219 BLAZE_USER_ASSERT( i < size(), "Invalid element access index" );
220 return indices_[i];
221}
223//*************************************************************************************************
224
225
226//*************************************************************************************************
232template< size_t I // First element index
233 , size_t... Is > // Remaining element indices
234constexpr size_t ElementsData< index_sequence<I,Is...> >::size() noexcept
235{
236 return N;
237}
239//*************************************************************************************************
240
241
242
243
244//=================================================================================================
245//
246// CLASS TEMPLATE SPECIALIZATION FOR INDEX PRODUCING CALLABLES
247//
248//=================================================================================================
249
250//*************************************************************************************************
258template< typename P > // Type of the index producer
259class ElementsData<P>
260{
261 protected:
262 //**Compile time flags**************************************************************************
263 static constexpr size_t N = 0UL;
264 //**********************************************************************************************
265
266 public:
267 //**Compile time flags**************************************************************************
269
273 static constexpr bool compileTimeArgs = false;
274 //**********************************************************************************************
275
276 //**Constructors********************************************************************************
279 template< typename... REAs >
280 inline ElementsData( P p, size_t n, REAs... args ) noexcept;
281
282 ElementsData( const ElementsData& ) = default;
283 ElementsData( ElementsData&& ) = default;
285 //**********************************************************************************************
286
287 //**Destructor**********************************************************************************
290 ~ElementsData() = default;
292 //**********************************************************************************************
293
294 //**Assignment operators************************************************************************
297 ElementsData& operator=( const ElementsData& ) = delete;
298 ElementsData& operator=( ElementsData&& ) = delete;
300 //**********************************************************************************************
301
302 //**Utility functions***************************************************************************
305 inline decltype(auto) idces() const noexcept;
306 inline size_t idx ( size_t i ) const noexcept;
307 inline size_t size () const noexcept;
309 //**********************************************************************************************
310
311 private:
312 //**Member variables****************************************************************************
315 P p_;
316 size_t n_;
318 //**********************************************************************************************
319};
321//*************************************************************************************************
322
323
324//*************************************************************************************************
332template< typename P > // Type of the index producer
333template< typename... REAs > // Optional element arguments
334inline ElementsData<P>::ElementsData( P p, size_t n, REAs... args ) noexcept
335 : p_( p )
336 , n_( n )
337{
338 MAYBE_UNUSED( args... );
339}
341//*************************************************************************************************
342
343
344//*************************************************************************************************
350template< typename P > // Type of the index producer
351inline decltype(auto) ElementsData<P>::idces() const noexcept
352{
353 return std::make_pair( p_, n_ );
354}
356//*************************************************************************************************
357
358
359//*************************************************************************************************
366template< typename P > // Type of the index producer
367inline size_t ElementsData<P>::idx( size_t i ) const noexcept
368{
369 BLAZE_USER_ASSERT( i < size(), "Invalid element access index" );
370 return p_(i);
371}
373//*************************************************************************************************
374
375
376//*************************************************************************************************
382template< typename P > // Type of the index producer
383inline size_t ElementsData<P>::size() const noexcept
384{
385 return n_;
386}
388//*************************************************************************************************
389
390
391
392
393//=================================================================================================
394//
395// CLASS TEMPLATE SPECIALIZATION FOR ZERO COMPILE TIME ELEMENT ARGUMENTS
396//
397//=================================================================================================
398
399//*************************************************************************************************
407template<>
408class ElementsData<>
409{
410 protected:
411 //**Compile time flags**************************************************************************
412 static constexpr size_t N = 0UL;
413 //**********************************************************************************************
414
415 public:
416 //**Compile time flags**************************************************************************
418
422 static constexpr bool compileTimeArgs = false;
423 //**********************************************************************************************
424
425 //**Constructors********************************************************************************
428 template< typename T, typename... REAs >
429 inline ElementsData( T* indices, size_t n, REAs... args );
430
431 ElementsData( const ElementsData& ) = default;
432 ElementsData( ElementsData&& ) = default;
434 //**********************************************************************************************
435
436 //**Destructor**********************************************************************************
439 ~ElementsData() = default;
441 //**********************************************************************************************
442
443 //**Assignment operators************************************************************************
446 ElementsData& operator=( const ElementsData& ) = delete;
448 //**********************************************************************************************
449
450 //**Utility functions***************************************************************************
453 inline decltype(auto) idces() const noexcept;
454 inline size_t idx ( size_t i ) const noexcept;
455 inline size_t size () const noexcept;
457 //**********************************************************************************************
458
459 private:
460 //**Type definitions****************************************************************************
461 using Indices = SmallArray<size_t,8UL>;
462 //**********************************************************************************************
463
464 //**Member variables****************************************************************************
467 Indices indices_;
469 //**********************************************************************************************
470};
472//*************************************************************************************************
473
474
475//*************************************************************************************************
483template< typename T // Type of the element indices
484 , typename... REAs > // Optional element arguments
485inline ElementsData<>::ElementsData( T* indices, size_t n, REAs... args )
486 : indices_( indices, indices+n ) // The indices of the elements in the vector
487{
488 MAYBE_UNUSED( args... );
489}
491//*************************************************************************************************
492
493
494//*************************************************************************************************
500inline decltype(auto) ElementsData<>::idces() const noexcept
501{
502 return blaze::as_const( indices_ );
503}
505//*************************************************************************************************
506
507
508//*************************************************************************************************
517inline size_t ElementsData<>::idx( size_t i ) const noexcept
518{
519 BLAZE_USER_ASSERT( i < size(), "Invalid element access index" );
520 return indices_[i];
521}
523//*************************************************************************************************
524
525
526//*************************************************************************************************
532inline size_t ElementsData<>::size() const noexcept
533{
534 return indices_.size();
535}
537//*************************************************************************************************
538
539
540
541
542//=================================================================================================
543//
544// GLOBAL FUNCTIONS
545//
546//=================================================================================================
547
548//*************************************************************************************************
557template< typename... CEAs1, typename... CEAs2 >
558constexpr bool
559 compareIndices( const ElementsData<CEAs1...>& lhs, const ElementsData<CEAs2...>& rhs ) noexcept
560{
561 if( lhs.size() != rhs.size() )
562 return false;
563
564 for( size_t i=0UL; i<lhs.size(); ++i ) {
565 if( lhs.idx(i) != rhs.idx(i) )
566 return false;
567 }
568
569 return true;
570}
572//*************************************************************************************************
573
574} // namespace blaze
575
576#endif
Header file for the as_const function template.
Header file for run time assertion macros.
Header file for the integer_sequence and index_sequence aliases.
Header file for the MAYBE_UNUSED function template.
Header file for the SmallArray implementation.
C++-standard-specific system settings.
Index sequence type of the Blaze library.
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
constexpr AddConst_t< T > & as_const(T &v) noexcept
Adding 'const' to the given lvalue.
Definition: AsConst.h:64
Header file for basic type definitions.