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 typename EnableIf< IsSparseElement<Other>, ValueIndexPair& >::Type
97  operator=( const Other& rhs );
98 
99  template< typename Other >
100  inline typename DisableIf< IsSparseElement<Other>, ValueIndexPair& >::Type
101  operator=( const Other& v );
102 
103  template< typename Other > inline ValueIndexPair& operator+=( const Other& v );
104  template< typename Other > inline ValueIndexPair& operator-=( const Other& v );
105  template< typename Other > inline ValueIndexPair& operator*=( const Other& v );
106  template< typename Other > inline ValueIndexPair& operator/=( const Other& v );
108  //**********************************************************************************************
109 
110  //**Acess functions*****************************************************************************
113  inline Reference value();
114  inline ConstReference value() const;
115  inline IndexType index() const;
117  //**********************************************************************************************
118 
119  protected:
120  //**Member variables****************************************************************************
123  Type value_;
124  size_t index_;
125 
126  //**********************************************************************************************
127 
128  private:
129  //**Friend declarations*************************************************************************
131  template< typename Other > friend class ValueIndexPair;
133  //**********************************************************************************************
134 
135  //**Compile time checks*************************************************************************
142  //**********************************************************************************************
143 };
144 //*************************************************************************************************
145 
146 
147 
148 
149 //=================================================================================================
150 //
151 // CONSTRUCTORS
152 //
153 //=================================================================================================
154 
155 //*************************************************************************************************
158 template< typename Type > // Type of the value element
160  : value_() // Value of the value-index-pair
161  , index_() // Index of the value-index-pair
162 {}
163 //*************************************************************************************************
164 
165 
166 //*************************************************************************************************
172 template< typename Type > // Type of the value element
173 inline ValueIndexPair<Type>::ValueIndexPair( const Type& v, size_t i )
174  : value_( v ) // Value of the value-index-pair
175  , index_( i ) // Index of the value-index-pair
176 {}
177 //*************************************************************************************************
178 
179 
180 
181 
182 //=================================================================================================
183 //
184 // OPERATORS
185 //
186 //=================================================================================================
187 
188 //*************************************************************************************************
198 template< typename Type > // Type of the value element
199 template< typename Other > // Data type of the right-hand side value-index-pair
202 {
203  value_ = rhs.value();
204  index_ = rhs.index();
205  return *this;
206 }
207 //*************************************************************************************************
208 
209 
210 //*************************************************************************************************
216 template< typename Type > // Type of the value element
217 template< typename Other > // Data type of the right-hand side value
220 {
221  value_ = v;
222  return *this;
223 }
224 //*************************************************************************************************
225 
226 
227 //*************************************************************************************************
233 template< typename Type > // Type of the value element
234 template< typename Other > // Data type of the right-hand side value
236 {
237  value_ += v;
238  return *this;
239 }
240 //*************************************************************************************************
241 
242 
243 //*************************************************************************************************
249 template< typename Type > // Type of the value element
250 template< typename Other > // Data type of the right-hand side value
252 {
253  value_ -= v;
254  return *this;
255 }
256 //*************************************************************************************************
257 
258 
259 //*************************************************************************************************
265 template< typename Type > // Type of the value element
266 template< typename Other > // Data type of the right-hand side value
268 {
269  value_ *= v;
270  return *this;
271 }
272 //*************************************************************************************************
273 
274 
275 //*************************************************************************************************
281 template< typename Type > // Type of the value element
282 template< typename Other > // Data type of the right-hand side value
284 {
285  value_ /= v;
286  return *this;
287 }
288 //*************************************************************************************************
289 
290 
291 
292 
293 //=================================================================================================
294 //
295 // ACCESS FUNCTIONS
296 //
297 //=================================================================================================
298 
299 //*************************************************************************************************
304 template< typename Type > // Type of the value element
306 {
307  return value_;
308 }
309 //*************************************************************************************************
310 
311 
312 //*************************************************************************************************
317 template< typename Type > // Type of the value element
319 {
320  return value_;
321 }
322 //*************************************************************************************************
323 
324 
325 //*************************************************************************************************
330 template< typename Type > // Type of the value element
332 {
333  return index_;
334 }
335 //*************************************************************************************************
336 
337 } // namespace blaze
338 
339 #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:116
size_t IndexType
The index type of the value-index-pair.
Definition: ValueIndexPair.h:75
Header file for basic type definitions.
#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:116
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:116
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:124
Header file for the EnableIf class template.
Constraint on the data type.
Substitution Failure Is Not An Error (SFINAE) class.The EnableIf class template is an auxiliary tool ...
Definition: EnableIf.h:184
#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:116
IndexType index() const
Access to the current index of the value-index-pair.
Definition: ValueIndexPair.h:331
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
Substitution Failure Is Not An Error (SFINAE) class.The DisableIf class template is an auxiliary tool...
Definition: DisableIf.h:184
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:123
ValueIndexPair()
Default constructor for value-index-pairs.
Definition: ValueIndexPair.h:159
Size type of the Blaze library.
Reference value()
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:305