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/DisableIf.h>
50 #include <blaze/util/EnableIf.h>
51 #include <blaze/util/Types.h>
52 
53 
54 namespace blaze {
55 
56 //=================================================================================================
57 //
58 // CLASS DEFINITION
59 //
60 //=================================================================================================
61 
62 //*************************************************************************************************
69 template< typename Type > // Type of the value element
71 {
72  public:
73  //**Type definitions****************************************************************************
74  typedef Type ValueType;
75  typedef size_t IndexType;
76  typedef Type& Reference;
77  typedef const Type& ConstReference;
78  //**********************************************************************************************
79 
80  //**Constructors********************************************************************************
81  inline ValueIndexPair();
82  inline ValueIndexPair( const Type& v, size_t i );
83  // No explicitly declared copy constructor.
84  //**********************************************************************************************
85 
86  //**Destructor**********************************************************************************
87  // No explicitly declared destructor.
88  //**********************************************************************************************
89 
90  //**Operators***********************************************************************************
93  // No explicitly declared copy assignment operator.
94 
95  template< typename Other >
96  inline EnableIf_< IsSparseElement<Other>, ValueIndexPair& > operator=( const Other& rhs );
97 
98  template< typename Other >
99  inline DisableIf_< IsSparseElement<Other>, ValueIndexPair& > operator=( const Other& v );
100 
101  template< typename Other > inline ValueIndexPair& operator+=( const Other& v );
102  template< typename Other > inline ValueIndexPair& operator-=( const Other& v );
103  template< typename Other > inline ValueIndexPair& operator*=( const Other& v );
104  template< typename Other > inline ValueIndexPair& operator/=( const Other& v );
106  //**********************************************************************************************
107 
108  //**Acess functions*****************************************************************************
111  inline Reference value();
112  inline ConstReference value() const;
113  inline IndexType index() const;
115  //**********************************************************************************************
116 
117  protected:
118  //**Member variables****************************************************************************
121  Type value_;
122  size_t index_;
123 
124  //**********************************************************************************************
125 
126  private:
127  //**Friend declarations*************************************************************************
129  template< typename Other > friend class ValueIndexPair;
131  //**********************************************************************************************
132 
133  //**Compile time checks*************************************************************************
140  //**********************************************************************************************
141 };
142 //*************************************************************************************************
143 
144 
145 
146 
147 //=================================================================================================
148 //
149 // CONSTRUCTORS
150 //
151 //=================================================================================================
152 
153 //*************************************************************************************************
156 template< typename Type > // Type of the value element
158  : value_() // Value of the value-index-pair
159  , index_() // Index of the value-index-pair
160 {}
161 //*************************************************************************************************
162 
163 
164 //*************************************************************************************************
170 template< typename Type > // Type of the value element
171 inline ValueIndexPair<Type>::ValueIndexPair( const Type& v, size_t i )
172  : value_( v ) // Value of the value-index-pair
173  , index_( i ) // Index of the value-index-pair
174 {}
175 //*************************************************************************************************
176 
177 
178 
179 
180 //=================================================================================================
181 //
182 // OPERATORS
183 //
184 //=================================================================================================
185 
186 //*************************************************************************************************
196 template< typename Type > // Type of the value element
197 template< typename Other > // Data type of the right-hand side value-index-pair
200 {
201  value_ = rhs.value();
202  index_ = rhs.index();
203  return *this;
204 }
205 //*************************************************************************************************
206 
207 
208 //*************************************************************************************************
214 template< typename Type > // Type of the value element
215 template< typename Other > // Data type of the right-hand side value
218 {
219  value_ = v;
220  return *this;
221 }
222 //*************************************************************************************************
223 
224 
225 //*************************************************************************************************
231 template< typename Type > // Type of the value element
232 template< typename Other > // Data type of the right-hand side value
234 {
235  value_ += v;
236  return *this;
237 }
238 //*************************************************************************************************
239 
240 
241 //*************************************************************************************************
247 template< typename Type > // Type of the value element
248 template< typename Other > // Data type of the right-hand side value
250 {
251  value_ -= v;
252  return *this;
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
263 template< typename Type > // Type of the value element
264 template< typename Other > // Data type of the right-hand side value
266 {
267  value_ *= v;
268  return *this;
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
279 template< typename Type > // Type of the value element
280 template< typename Other > // Data type of the right-hand side value
282 {
283  value_ /= v;
284  return *this;
285 }
286 //*************************************************************************************************
287 
288 
289 
290 
291 //=================================================================================================
292 //
293 // ACCESS FUNCTIONS
294 //
295 //=================================================================================================
296 
297 //*************************************************************************************************
302 template< typename Type > // Type of the value element
304 {
305  return value_;
306 }
307 //*************************************************************************************************
308 
309 
310 //*************************************************************************************************
315 template< typename Type > // Type of the value element
317 {
318  return value_;
319 }
320 //*************************************************************************************************
321 
322 
323 //*************************************************************************************************
328 template< typename Type > // Type of the value element
330 {
331  return index_;
332 }
333 //*************************************************************************************************
334 
335 } // namespace blaze
336 
337 #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
size_t IndexType
The index type of the value-index-pair.
Definition: ValueIndexPair.h:75
Header file for basic type definitions.
BLAZE_ALWAYS_INLINE T1 & operator/=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Division assignment operator for the division of two SIMD packs.
Definition: BasicTypes.h:1339
typename DisableIf< Condition, T >::Type DisableIf_
Auxiliary type for the DisableIf class template.The DisableIf_ alias declaration provides a convenien...
Definition: DisableIf.h:223
#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
BLAZE_ALWAYS_INLINE T1 & operator*=(SIMDPack< T1 > &lhs, const SIMDPack< T2 > &rhs)
Multiplication assignment operator for the multiplication of two SIMD packs.
Definition: BasicTypes.h:1321
const Type & ConstReference
Reference-to-const return type.
Definition: ValueIndexPair.h:77
Constraint on the data type.
Header file for the DisableIf class template.
Type ValueType
The value type of the value-index-pair.
Definition: ValueIndexPair.h:74
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#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
Type & Reference
Reference return type.
Definition: ValueIndexPair.h:76
Constraint on the data type.
Header file for the SparseElement base class.
size_t index_
Index of the value-index-pair.
Definition: ValueIndexPair.h:122
Header file for the EnableIf class template.
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:1285
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
IndexType index() const
Access to the current index of the value-index-pair.
Definition: ValueIndexPair.h:329
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
typename EnableIf< Condition, T >::Type EnableIf_
Auxiliary alias declaration for the EnableIf class template.The EnableIf_ alias declaration provides ...
Definition: EnableIf.h:223
Header file for the IsSparseElement type trait class.
Index-value-pair for sparse vectors and matrices.The ValueIndexPair class represents a single index-v...
Definition: ValueIndexPair.h:70
Type value_
Value of the value-index-pair.
Definition: ValueIndexPair.h:121
ValueIndexPair()
Default constructor for value-index-pairs.
Definition: ValueIndexPair.h:157
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:1303
Size type of the Blaze library.
Reference value()
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:303