Blaze  3.6
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 
44 #include <blaze/system/Standard.h>
45 #include <blaze/util/Assert.h>
46 #include <blaze/util/MaybeUnused.h>
47 #include <blaze/util/SmallArray.h>
48 #include <blaze/util/Types.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // CLASS DEFINITION
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
69 template< typename... CCAs > // Compile time column arguments
70 class ColumnsData
71 {};
73 //*************************************************************************************************
74 
75 
76 
77 
78 //=================================================================================================
79 //
80 // CLASS TEMPLATE SPECIALIZATION FOR INDEX SEQUENCES
81 //
82 //=================================================================================================
83 
84 //*************************************************************************************************
92 template< size_t I // First column index
93  , size_t... Is > // Remaining column indices
94 class ColumnsData< index_sequence<I,Is...> >
95 {
96  protected:
97  //**Compile time flags**************************************************************************
98  static constexpr size_t N = sizeof...( Is ) + 1UL;
99  //**********************************************************************************************
100 
101  public:
102  //**Compile time flags**************************************************************************
104 
108  static constexpr bool compileTimeArgs = true;
109  //**********************************************************************************************
110 
111  //**Constructors********************************************************************************
114  template< typename... RCAs >
115  explicit inline ColumnsData( RCAs... args ) noexcept;
116 
117  ColumnsData( const ColumnsData& ) = default;
119  //**********************************************************************************************
120 
121  //**Destructor**********************************************************************************
124  ~ColumnsData() = default;
126  //**********************************************************************************************
127 
128  //**Assignment operators************************************************************************
131  ColumnsData& operator=( const ColumnsData& ) = delete;
133  //**********************************************************************************************
134 
135  //**Utility functions***************************************************************************
138  static inline constexpr decltype(auto) idces () noexcept;
139  static inline constexpr size_t idx ( size_t i ) noexcept;
140  static inline constexpr size_t columns() noexcept;
142  //**********************************************************************************************
143 
144  private:
145  //**Type definitions****************************************************************************
146  using Indices = std::array<size_t,N>;
147  //**********************************************************************************************
148 
149  //**Member variables****************************************************************************
152  static constexpr Indices indices_{ { I, Is... } };
153 
154  //**********************************************************************************************
155 };
157 //*************************************************************************************************
158 
159 
160 //*************************************************************************************************
162 #if BLAZE_CPP14_MODE
163 // Definition and initialization of the static member variables
164 template< size_t I // First column index
165  , size_t... Is > // Remaining column indices
166 constexpr typename ColumnsData< index_sequence<I,Is...> >::Indices
167  ColumnsData< index_sequence<I,Is...> >::indices_;
168 #endif
169 
170 //*************************************************************************************************
171 
172 
173 //*************************************************************************************************
179 template< size_t I // First column index
180  , size_t... Is > // Remaining column indices
181 template< typename... RCAs > // Optional column arguments
182 inline ColumnsData< index_sequence<I,Is...> >::ColumnsData( RCAs... args ) noexcept
183 {
184  MAYBE_UNUSED( args... );
185 }
187 //*************************************************************************************************
188 
189 
190 //*************************************************************************************************
196 template< size_t I // First column index
197  , size_t... Is > // Remaining column indices
198 inline constexpr decltype(auto) ColumnsData< index_sequence<I,Is...> >::idces() noexcept
199 {
200  return index_sequence<I,Is...>();
201 }
203 //*************************************************************************************************
204 
205 
206 //*************************************************************************************************
213 template< size_t I // First column index
214  , size_t... Is > // Remaining column indices
215 inline constexpr size_t ColumnsData< index_sequence<I,Is...> >::idx( size_t i ) noexcept
216 {
217  BLAZE_USER_ASSERT( i < columns(), "Invalid column access index" );
218  return indices_[i];
219 }
221 //*************************************************************************************************
222 
223 
224 //*************************************************************************************************
230 template< size_t I // First column index
231  , size_t... Is > // Remaining column indices
232 inline constexpr size_t ColumnsData< index_sequence<I,Is...> >::columns() noexcept
233 {
234  return N;
235 }
237 //*************************************************************************************************
238 
239 
240 
241 
242 //=================================================================================================
243 //
244 // CLASS TEMPLATE SPECIALIZATION FOR INDEX PRODUCING CALLABLES
245 //
246 //=================================================================================================
247 
248 //*************************************************************************************************
256 template< typename P > // Type of the index producer
257 class ColumnsData<P>
258 {
259  protected:
260  //**Compile time flags**************************************************************************
261  static constexpr size_t N = 0UL;
262  //**********************************************************************************************
263 
264  public:
265  //**Compile time flags**************************************************************************
267 
271  static constexpr bool compileTimeArgs = false;
272  //**********************************************************************************************
273 
274  //**Constructors********************************************************************************
277  template< typename... RCAs >
278  explicit inline ColumnsData( P p, size_t n, RCAs... args ) noexcept;
279 
280  ColumnsData( const ColumnsData& ) = default;
281  ColumnsData( ColumnsData&& ) = default;
283  //**********************************************************************************************
284 
285  //**Destructor**********************************************************************************
288  ~ColumnsData() = default;
290  //**********************************************************************************************
291 
292  //**Assignment operators************************************************************************
295  ColumnsData& operator=( const ColumnsData& ) = delete;
296  ColumnsData& operator=( ColumnsData&& ) = delete;
298  //**********************************************************************************************
299 
300  //**Utility functions***************************************************************************
303  inline decltype(auto) idces () const noexcept;
304  inline size_t idx ( size_t i ) const noexcept;
305  inline size_t columns() const noexcept;
307  //**********************************************************************************************
308 
309  private:
310  //**Member variables****************************************************************************
313  P p_;
314  size_t n_;
315 
316  //**********************************************************************************************
317 };
319 //*************************************************************************************************
320 
321 
322 //*************************************************************************************************
330 template< typename P > // Type of the index producer
331 template< typename... RCAs > // Optional column arguments
332 inline ColumnsData<P>::ColumnsData( P p, size_t n, RCAs... args ) noexcept
333  : p_( p )
334  , n_( n )
335 {
336  MAYBE_UNUSED( args... );
337 }
339 //*************************************************************************************************
340 
341 
342 //*************************************************************************************************
348 template< typename P > // Type of the index producer
349 inline decltype(auto) ColumnsData<P>::idces() const noexcept
350 {
351  return std::make_pair( p_, n_ );
352 }
354 //*************************************************************************************************
355 
356 
357 //*************************************************************************************************
364 template< typename P > // Type of the index producer
365 inline size_t ColumnsData<P>::idx( size_t i ) const noexcept
366 {
367  BLAZE_USER_ASSERT( i < columns(), "Invalid column access index" );
368  return p_(i);
369 }
371 //*************************************************************************************************
372 
373 
374 //*************************************************************************************************
380 template< typename P > // Type of the index producer
381 inline size_t ColumnsData<P>::columns() const noexcept
382 {
383  return n_;
384 }
386 //*************************************************************************************************
387 
388 
389 
390 
391 //=================================================================================================
392 //
393 // CLASS TEMPLATE SPECIALIZATION FOR ZERO COMPILE TIME COLUMN ARGUMENTS
394 //
395 //=================================================================================================
396 
397 //*************************************************************************************************
405 template<>
406 class ColumnsData<>
407 {
408  protected:
409  //**Compile time flags**************************************************************************
410  static constexpr size_t N = 0UL;
411  //**********************************************************************************************
412 
413  public:
414  //**Compile time flags**************************************************************************
416 
420  static constexpr bool compileTimeArgs = false;
421  //**********************************************************************************************
422 
423  //**Constructors********************************************************************************
426  template< typename T, typename... RCAs >
427  explicit inline ColumnsData( T* indices, size_t n, RCAs... args );
428 
429  ColumnsData( const ColumnsData& ) = default;
430  ColumnsData( ColumnsData&& ) = default;
432  //**********************************************************************************************
433 
434  //**Destructor**********************************************************************************
437  ~ColumnsData() = default;
439  //**********************************************************************************************
440 
441  //**Assignment operators************************************************************************
444  ColumnsData& operator=( const ColumnsData& ) = delete;
446  //**********************************************************************************************
447 
448  //**Utility functions***************************************************************************
451  inline decltype(auto) idces () const noexcept;
452  inline size_t idx ( size_t i ) const noexcept;
453  inline size_t columns() const noexcept;
455  //**********************************************************************************************
456 
457  private:
458  //**Type definitions****************************************************************************
459  using Indices = SmallArray<size_t,8UL>;
460  //**********************************************************************************************
461 
462  //**Member variables****************************************************************************
465  Indices indices_;
466 
467  //**********************************************************************************************
468 };
470 //*************************************************************************************************
471 
472 
473 //*************************************************************************************************
481 template< typename T // Type of the column indices
482  , typename... RCAs > // Optional column arguments
483 inline ColumnsData<>::ColumnsData( T* indices, size_t n, RCAs... args )
484  : indices_( indices, indices+n ) // The indices of the columns in the matrix
485 {
486  MAYBE_UNUSED( args... );
487 }
489 //*************************************************************************************************
490 
491 
492 //*************************************************************************************************
498 inline decltype(auto) ColumnsData<>::idces() const noexcept
499 {
500  return const_cast<const Indices&>( indices_ );
501 }
503 //*************************************************************************************************
504 
505 
506 //*************************************************************************************************
515 inline size_t ColumnsData<>::idx( size_t i ) const noexcept
516 {
517  BLAZE_USER_ASSERT( i < columns(), "Invalid column access index" );
518  return indices_[i];
519 }
521 //*************************************************************************************************
522 
523 
524 //*************************************************************************************************
530 inline size_t ColumnsData<>::columns() const noexcept
531 {
532  return indices_.size();
533 }
535 //*************************************************************************************************
536 
537 
538 
539 
540 //=================================================================================================
541 //
542 // GLOBAL FUNCTIONS
543 //
544 //=================================================================================================
545 
546 //*************************************************************************************************
555 template< typename... CRAs1, typename... CRAs2 >
556 inline constexpr bool
557  compareIndices( const ColumnsData<CRAs1...>& lhs, const ColumnsData<CRAs2...>& rhs ) noexcept
558 {
559  if( lhs.columns() != rhs.columns() )
560  return false;
561 
562  for( size_t i=0UL; i<lhs.columns(); ++i ) {
563  if( lhs.idx(i) != rhs.idx(i) )
564  return false;
565  }
566 
567  return true;
568 }
570 //*************************************************************************************************
571 
572 } // namespace blaze
573 
574 #endif
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
Header file for basic type definitions.
Header file for the MAYBE_UNUSED function template.
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Header file for the SmallArray implementation.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
Header file for run time assertion macros.
Header file for the integer_sequence and index_sequence aliases.
C++-standard-specific system settings.