Blaze 3.9
ColumnsData.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_VIEWS_COLUMNS_COLUMNSDATA_H_
36#define _BLAZE_MATH_VIEWS_COLUMNS_COLUMNSDATA_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... CCAs > // Compile time column arguments
72class ColumnsData
73{};
75//*************************************************************************************************
76
77
78
79
80//=================================================================================================
81//
82// CLASS TEMPLATE SPECIALIZATION FOR INDEX SEQUENCES
83//
84//=================================================================================================
85
86//*************************************************************************************************
94template< size_t I // First column index
95 , size_t... Is > // Remaining column indices
96class ColumnsData< 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... RCAs >
117 explicit inline ColumnsData( RCAs... args ) noexcept;
118
119 ColumnsData( const ColumnsData& ) = default;
121 //**********************************************************************************************
122
123 //**Destructor**********************************************************************************
126 ~ColumnsData() = default;
128 //**********************************************************************************************
129
130 //**Assignment operators************************************************************************
133 ColumnsData& operator=( const ColumnsData& ) = 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 columns() 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 column index
167 , size_t... Is > // Remaining column indices
168constexpr typename ColumnsData< index_sequence<I,Is...> >::Indices
169 ColumnsData< index_sequence<I,Is...> >::indices_;
170#endif
172//*************************************************************************************************
173
174
175//*************************************************************************************************
181template< size_t I // First column index
182 , size_t... Is > // Remaining column indices
183template< typename... RCAs > // Optional column arguments
184inline ColumnsData< index_sequence<I,Is...> >::ColumnsData( RCAs... args ) noexcept
185{
186 MAYBE_UNUSED( args... );
187}
189//*************************************************************************************************
190
191
192//*************************************************************************************************
198template< size_t I // First column index
199 , size_t... Is > // Remaining column indices
200constexpr decltype(auto) ColumnsData< index_sequence<I,Is...> >::idces() noexcept
201{
202 return index_sequence<I,Is...>();
203}
205//*************************************************************************************************
206
207
208//*************************************************************************************************
215template< size_t I // First column index
216 , size_t... Is > // Remaining column indices
217constexpr size_t ColumnsData< index_sequence<I,Is...> >::idx( size_t i ) noexcept
218{
219 BLAZE_USER_ASSERT( i < columns(), "Invalid column access index" );
220 return indices_[i];
221}
223//*************************************************************************************************
224
225
226//*************************************************************************************************
232template< size_t I // First column index
233 , size_t... Is > // Remaining column indices
234constexpr size_t ColumnsData< index_sequence<I,Is...> >::columns() 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 ColumnsData<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... RCAs >
280 inline ColumnsData( P p, size_t n, RCAs... args ) noexcept;
281
282 ColumnsData( const ColumnsData& ) = default;
283 ColumnsData( ColumnsData&& ) = default;
285 //**********************************************************************************************
286
287 //**Destructor**********************************************************************************
290 ~ColumnsData() = default;
292 //**********************************************************************************************
293
294 //**Assignment operators************************************************************************
297 ColumnsData& operator=( const ColumnsData& ) = delete;
298 ColumnsData& operator=( ColumnsData&& ) = 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 columns() 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... RCAs > // Optional column arguments
334inline ColumnsData<P>::ColumnsData( P p, size_t n, RCAs... 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) ColumnsData<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 ColumnsData<P>::idx( size_t i ) const noexcept
368{
369 BLAZE_USER_ASSERT( i < columns(), "Invalid column access index" );
370 return p_(i);
371}
373//*************************************************************************************************
374
375
376//*************************************************************************************************
382template< typename P > // Type of the index producer
383inline size_t ColumnsData<P>::columns() const noexcept
384{
385 return n_;
386}
388//*************************************************************************************************
389
390
391
392
393//=================================================================================================
394//
395// CLASS TEMPLATE SPECIALIZATION FOR ZERO COMPILE TIME COLUMN ARGUMENTS
396//
397//=================================================================================================
398
399//*************************************************************************************************
407template<>
408class ColumnsData<>
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... RCAs >
429 inline ColumnsData( T* indices, size_t n, RCAs... args );
430
431 ColumnsData( const ColumnsData& ) = default;
432 ColumnsData( ColumnsData&& ) = default;
434 //**********************************************************************************************
435
436 //**Destructor**********************************************************************************
439 ~ColumnsData() = default;
441 //**********************************************************************************************
442
443 //**Assignment operators************************************************************************
446 ColumnsData& operator=( const ColumnsData& ) = 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 columns() 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 column indices
484 , typename... RCAs > // Optional column arguments
485inline ColumnsData<>::ColumnsData( T* indices, size_t n, RCAs... args )
486 : indices_( indices, indices+n ) // The indices of the columns in the matrix
487{
488 MAYBE_UNUSED( args... );
489}
491//*************************************************************************************************
492
493
494//*************************************************************************************************
500inline decltype(auto) ColumnsData<>::idces() const noexcept
501{
502 return blaze::as_const( indices_ );
503}
505//*************************************************************************************************
506
507
508//*************************************************************************************************
517inline size_t ColumnsData<>::idx( size_t i ) const noexcept
518{
519 BLAZE_USER_ASSERT( i < columns(), "Invalid column access index" );
520 return indices_[i];
521}
523//*************************************************************************************************
524
525
526//*************************************************************************************************
532inline size_t ColumnsData<>::columns() const noexcept
533{
534 return indices_.size();
535}
537//*************************************************************************************************
538
539
540
541
542//=================================================================================================
543//
544// GLOBAL FUNCTIONS
545//
546//=================================================================================================
547
548//*************************************************************************************************
557template< typename... CRAs1, typename... CRAs2 >
558constexpr bool
559 compareIndices( const ColumnsData<CRAs1...>& lhs, const ColumnsData<CRAs2...>& rhs ) noexcept
560{
561 if( lhs.columns() != rhs.columns() )
562 return false;
563
564 for( size_t i=0UL; i<lhs.columns(); ++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 columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:660
#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.