ValueIndexPair.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SPARSE_VALUEINDEXPAIR_H_
36 #define _BLAZE_MATH_SPARSE_VALUEINDEXPAIR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
49 #include <blaze/util/EnableIf.h>
50 #include <blaze/util/mpl/And.h>
51 #include <blaze/util/mpl/Not.h>
52 #include <blaze/util/Types.h>
55 
56 
57 namespace blaze {
58 
59 //=================================================================================================
60 //
61 // CLASS DEFINITION
62 //
63 //=================================================================================================
64 
65 //*************************************************************************************************
72 template< typename Type > // Type of the value element
74  : private SparseElement
75 {
76  public:
77  //**Type definitions****************************************************************************
78  using ValueType = Type;
79  using IndexType = size_t;
80  using Reference = Type&;
81  using ConstReference = const Type&;
82  //**********************************************************************************************
83 
84  //**Constructors********************************************************************************
85  inline ValueIndexPair();
86  inline ValueIndexPair( const Type& v, size_t i );
87  // No explicitly declared copy constructor.
88  // No explicitly declared move constructor.
89  //**********************************************************************************************
90 
91  //**Destructor**********************************************************************************
92  // No explicitly declared destructor.
93  //**********************************************************************************************
94 
95  //**Operators***********************************************************************************
98  // No explicitly declared copy assignment operator.
99  // No explicitly declared move assignment operator.
100 
101  template< typename Other >
103  operator=( const Other& rhs );
104 
105  template< typename Other >
108  operator=( Other&& rhs );
109 
110  template< typename Other >
112  operator=( const Other& v );
113 
114  template< typename Other >
116  , IsRValueReference<Other&&> >, ValueIndexPair& >
117  operator=( Other&& v );
118 
119  template< typename Other > inline ValueIndexPair& operator+=( const Other& v );
120  template< typename Other > inline ValueIndexPair& operator-=( const Other& v );
121  template< typename Other > inline ValueIndexPair& operator*=( const Other& v );
122  template< typename Other > inline ValueIndexPair& operator/=( const Other& v );
124  //**********************************************************************************************
125 
126  //**Acess functions*****************************************************************************
129  inline Reference value();
130  inline ConstReference value() const;
131  inline IndexType index() const;
133  //**********************************************************************************************
134 
135  protected:
136  //**Member variables****************************************************************************
139  Type value_;
140  size_t index_;
141 
142  //**********************************************************************************************
143 
144  private:
145  //**Friend declarations*************************************************************************
147  template< typename Other > friend class ValueIndexPair;
149  //**********************************************************************************************
150 
151  //**Compile time checks*************************************************************************
158  //**********************************************************************************************
159 };
160 //*************************************************************************************************
161 
162 
163 
164 
165 //=================================================================================================
166 //
167 // CONSTRUCTORS
168 //
169 //=================================================================================================
170 
171 //*************************************************************************************************
174 template< typename Type > // Type of the value element
176  : value_() // Value of the value-index-pair
177  , index_() // Index of the value-index-pair
178 {}
179 //*************************************************************************************************
180 
181 
182 //*************************************************************************************************
188 template< typename Type > // Type of the value element
189 inline ValueIndexPair<Type>::ValueIndexPair( const Type& v, size_t i )
190  : value_( v ) // Value of the value-index-pair
191  , index_( i ) // Index of the value-index-pair
192 {}
193 //*************************************************************************************************
194 
195 
196 
197 
198 //=================================================================================================
199 //
200 // OPERATORS
201 //
202 //=================================================================================================
203 
204 //*************************************************************************************************
214 template< typename Type > // Type of the value element
215 template< typename Other > // Data type of the right-hand side value-index-pair
218 {
219  value_ = rhs.value();
220  index_ = rhs.index();
221  return *this;
222 }
223 //*************************************************************************************************
224 
225 
226 //*************************************************************************************************
236 template< typename Type > // Type of the value element
237 template< typename Other > // Data type of the right-hand side value-index-pair
241 {
242  value_ = std::move( rhs.value() );
243  index_ = rhs.index();
244  return *this;
245 }
246 //*************************************************************************************************
247 
248 
249 //*************************************************************************************************
255 template< typename Type > // Type of the value element
256 template< typename Other > // Data type of the right-hand side value
259 {
260  value_ = v;
261  return *this;
262 }
263 //*************************************************************************************************
264 
265 
266 //*************************************************************************************************
272 template< typename Type > // Type of the value element
273 template< typename Other > // Data type of the right-hand side value
275  , IsRValueReference<Other&&> >, ValueIndexPair<Type>& >
277 {
278  value_ = std::move( v );
279  return *this;
280 }
281 //*************************************************************************************************
282 
283 
284 //*************************************************************************************************
290 template< typename Type > // Type of the value element
291 template< typename Other > // Data type of the right-hand side value
293 {
294  value_ += v;
295  return *this;
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
306 template< typename Type > // Type of the value element
307 template< typename Other > // Data type of the right-hand side value
309 {
310  value_ -= v;
311  return *this;
312 }
313 //*************************************************************************************************
314 
315 
316 //*************************************************************************************************
322 template< typename Type > // Type of the value element
323 template< typename Other > // Data type of the right-hand side value
325 {
326  value_ *= v;
327  return *this;
328 }
329 //*************************************************************************************************
330 
331 
332 //*************************************************************************************************
338 template< typename Type > // Type of the value element
339 template< typename Other > // Data type of the right-hand side value
341 {
342  value_ /= v;
343  return *this;
344 }
345 //*************************************************************************************************
346 
347 
348 
349 
350 //=================================================================================================
351 //
352 // ACCESS FUNCTIONS
353 //
354 //=================================================================================================
355 
356 //*************************************************************************************************
361 template< typename Type > // Type of the value element
363 {
364  return value_;
365 }
366 //*************************************************************************************************
367 
368 
369 //*************************************************************************************************
374 template< typename Type > // Type of the value element
376 {
377  return value_;
378 }
379 //*************************************************************************************************
380 
381 
382 //*************************************************************************************************
387 template< typename Type > // Type of the value element
389 {
390  return index_;
391 }
392 //*************************************************************************************************
393 
394 } // namespace blaze
395 
396 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:79
Header file for basic type definitions.
Header file for the And class template.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:79
Constraint on the data type.
const Type & ConstReference
Reference-to-const return type.
Definition: ValueIndexPair.h:81
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:79
Header file for the Not class template.
Type ValueType
The value type of the value-index-pair.
Definition: ValueIndexPair.h:78
Constraint on the data type.
Header file for the SparseElement base class.
size_t index_
Index of the value-index-pair.
Definition: ValueIndexPair.h:140
Header file for the EnableIf class template.
Type & Reference
Reference return type.
Definition: ValueIndexPair.h:80
BLAZE_ALWAYS_INLINE T1 & operator+=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Addition assignment operator for the addition of two SIMD packs.
Definition: BasicTypes.h:1357
Header file for the IsRValueReference type trait.
Constraint on the data type.
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:79
Constraint on the data type.
Base class for all sparse element types.The SparseElement class is the base class for all sparse elem...
Definition: SparseElement.h:57
Header file for the RemoveReference type trait.
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:224
EnableIf_< IsNumeric< ST >, MT &> operator/=(DenseMatrix< MT, SO > &mat, ST scalar)
Division assignment operator for the division of a dense matrix by a scalar value ( )...
Definition: DenseMatrix.h:655
Header file for the IsSparseElement type trait class.
IndexType index() const
Access to the current index of the value-index-pair.
Definition: ValueIndexPair.h:388
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:73
Type value_
Value of the value-index-pair.
Definition: ValueIndexPair.h:139
Compile time type check.This class tests whether the given template parameter T is an rvalue referenc...
Definition: IsRValueReference.h:77
ValueIndexPair()
Default constructor for value-index-pairs.
Definition: ValueIndexPair.h:175
BLAZE_ALWAYS_INLINE T1 & operator-=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Subtraction assignment operator for the subtraction of two SIMD packs.
Definition: BasicTypes.h:1375
EnableIf_< IsNumeric< ST >, MT &> operator*=(DenseMatrix< MT, SO > &mat, ST scalar)
Multiplication assignment operator for the multiplication of a dense matrix and a scalar value ( )...
Definition: DenseMatrix.h:593
Size type of the Blaze library.
Reference value()
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:362