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 <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 //*************************************************************************************************
67 template< size_t... CCAs > // Compile time column arguments
68 struct ColumnsData
69 {
70  public:
71  //**Type definitions****************************************************************************
72  using Indices = std::array<size_t,sizeof...(CCAs)>;
73  //**********************************************************************************************
74 
75  //**Constructors********************************************************************************
78  template< typename... RCAs >
79  explicit inline ColumnsData( RCAs... args ) noexcept;
80  // No explicitly declared copy constructor.
82  //**********************************************************************************************
83 
84  //**Destructor**********************************************************************************
85  // No explicitly declared destructor.
86  //**********************************************************************************************
87 
88  //**Assignment operators************************************************************************
89  ColumnsData& operator=( const ColumnsData& ) = delete;
90  //**********************************************************************************************
91 
92  //**Utility functions***************************************************************************
95  static inline constexpr const Indices& idces () noexcept;
96  static inline constexpr size_t idx ( size_t i ) noexcept;
97  static inline constexpr size_t columns() noexcept;
99  //**********************************************************************************************
100 
101  private:
102  //**Member variables****************************************************************************
105  static constexpr Indices indices_{ { CCAs... } };
106 
107  //**********************************************************************************************
108 };
110 //*************************************************************************************************
111 
112 
113 //*************************************************************************************************
115 // Definition and initialization of the static member variables
116 template< size_t... CCAs > // Compile time column arguments
117 constexpr typename ColumnsData<CCAs...>::Indices ColumnsData<CCAs...>::indices_;
119 //*************************************************************************************************
120 
121 
122 //*************************************************************************************************
128 template< size_t... CCAs > // Compile time column arguments
129 template< typename... RCAs > // Optional column arguments
130 inline ColumnsData<CCAs...>::ColumnsData( RCAs... args ) noexcept
131 {
132  UNUSED_PARAMETER( args... );
133 }
135 //*************************************************************************************************
136 
137 
138 //*************************************************************************************************
144 template< size_t... CCAs > // Compile time column arguments
145 inline constexpr const typename ColumnsData<CCAs...>::Indices& ColumnsData<CCAs...>::idces() noexcept
146 {
147  return indices_;
148 }
150 //*************************************************************************************************
151 
152 
153 //*************************************************************************************************
160 template< size_t... CCAs > // Compile time column arguments
161 inline constexpr size_t ColumnsData<CCAs...>::idx( size_t i ) noexcept
162 {
163  BLAZE_USER_ASSERT( i < columns(), "Invalid column access index" );
164  return indices_[i];
165 }
167 //*************************************************************************************************
168 
169 
170 //*************************************************************************************************
176 template< size_t... CCAs > // Compile time column arguments
177 inline constexpr size_t ColumnsData<CCAs...>::columns() noexcept
178 {
179  return sizeof...( CCAs );
180 }
182 //*************************************************************************************************
183 
184 
185 
186 
187 //=================================================================================================
188 //
189 // CLASS TEMPLATE SPECIALIZATION FOR ZERO COMPILE TIME COLUMN ARGUMENTS
190 //
191 //=================================================================================================
192 
193 //*************************************************************************************************
201 template<>
202 struct ColumnsData<>
203 {
204  public:
205  //**Type definitions****************************************************************************
206  using Indices = SmallVector<size_t,8UL>;
207  //**********************************************************************************************
208 
209  //**Constructors********************************************************************************
212  template< typename T, typename... RCAs >
213  explicit inline ColumnsData( const T* indices, size_t n, RCAs... args );
214 
215  inline ColumnsData( const ColumnsData& ) = default;
216  inline ColumnsData( ColumnsData&& ) = default;
218  //**********************************************************************************************
219 
220  //**Destructor**********************************************************************************
221  // No explicitly declared destructor.
222  //**********************************************************************************************
223 
224  //**Assignment operators************************************************************************
225  ColumnsData& operator=( const ColumnsData& ) = delete;
226  //**********************************************************************************************
227 
228  //**Utility functions***************************************************************************
231  inline const Indices& idces () const noexcept;
232  inline size_t idx ( size_t i ) const noexcept;
233  inline size_t columns() const noexcept;
235  //**********************************************************************************************
236 
237  private:
238  //**Member variables****************************************************************************
241  Indices indices_;
242 
243  //**********************************************************************************************
244 };
246 //*************************************************************************************************
247 
248 
249 //*************************************************************************************************
257 template< typename T // Type of the column indices
258  , typename... RCAs > // Optional column arguments
259 inline ColumnsData<>::ColumnsData( const T* indices, size_t n, RCAs... args )
260  : indices_( indices, indices+n ) // The indices of the columns in the matrix
261 {
262  UNUSED_PARAMETER( args... );
263 }
265 //*************************************************************************************************
266 
267 
268 //*************************************************************************************************
274 inline const ColumnsData<>::Indices& ColumnsData<>::idces() const noexcept
275 {
276  return indices_;
277 }
279 //*************************************************************************************************
280 
281 
282 //*************************************************************************************************
291 inline size_t ColumnsData<>::idx( size_t i ) const noexcept
292 {
293  BLAZE_USER_ASSERT( i < columns(), "Invalid column access index" );
294  return indices_[i];
295 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
306 inline size_t ColumnsData<>::columns() const noexcept
307 {
308  return indices_.size();
309 }
311 //*************************************************************************************************
312 
313 } // namespace blaze
314 
315 #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.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
BLAZE_ALWAYS_INLINE size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:506
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