Blaze 3.9
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
57namespace blaze {
58
59//=================================================================================================
60//
61// CLASS DEFINITION
62//
63//=================================================================================================
64
65//*************************************************************************************************
72template< 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********************************************************************************
87 constexpr ValueIndexPair();
88 constexpr ValueIndexPair( const Type& v, size_t i );
89
90 ValueIndexPair( const ValueIndexPair& ) = default;
91 ValueIndexPair( ValueIndexPair&& ) = default;
93 //**********************************************************************************************
94
95 //**Destructor**********************************************************************************
98 ~ValueIndexPair() = default;
100 //**********************************************************************************************
101
102 //**Assignment operators************************************************************************
105 ValueIndexPair& operator=( const ValueIndexPair& ) = default;
106 ValueIndexPair& operator=( ValueIndexPair&& ) = default;
107
108 template< typename Other >
109 constexpr auto operator=( const Other& rhs )
111
112 template< typename Other >
113 constexpr auto operator=( Other&& rhs )
115 IsRValueReference_v<Other&&>, ValueIndexPair& >;
116
117 template< typename Other >
118 constexpr auto operator=( const Other& v )
120
121 template< typename Other >
122 constexpr auto operator=( Other&& v )
124 IsRValueReference_v<Other&&>, ValueIndexPair& >;
125
126 template< typename Other > constexpr ValueIndexPair& operator+=( const Other& v );
127 template< typename Other > constexpr ValueIndexPair& operator-=( const Other& v );
128 template< typename Other > constexpr ValueIndexPair& operator*=( const Other& v );
129 template< typename Other > constexpr ValueIndexPair& operator/=( const Other& v );
131 //**********************************************************************************************
132
133 //**Acess functions*****************************************************************************
136 constexpr Reference value() noexcept;
137 constexpr ConstReference value() const noexcept;
138 constexpr IndexType index() const noexcept;
140 //**********************************************************************************************
141
142 protected:
143 //**Member variables****************************************************************************
146 Type value_;
147 size_t index_;
149 //**********************************************************************************************
150
151 private:
152 //**Friend declarations*************************************************************************
154 template< typename Other > friend class ValueIndexPair;
156 //**********************************************************************************************
157
158 //**Compile time checks*************************************************************************
165 //**********************************************************************************************
166};
167//*************************************************************************************************
168
169
170
171
172//=================================================================================================
173//
174// CONSTRUCTORS
175//
176//=================================================================================================
177
178//*************************************************************************************************
181template< typename Type > // Type of the value element
183 : value_() // Value of the value-index-pair
184 , index_() // Index of the value-index-pair
185{}
186//*************************************************************************************************
187
188
189//*************************************************************************************************
195template< typename Type > // Type of the value element
196constexpr ValueIndexPair<Type>::ValueIndexPair( const Type& v, size_t i )
197 : value_( v ) // Value of the value-index-pair
198 , index_( i ) // Index of the value-index-pair
199{}
200//*************************************************************************************************
201
202
203
204
205//=================================================================================================
206//
207// OPERATORS
208//
209//=================================================================================================
210
211//*************************************************************************************************
221template< typename Type > // Type of the value element
222template< typename Other > // Data type of the right-hand side value-index-pair
223constexpr auto ValueIndexPair<Type>::operator=( const Other& rhs )
225{
226 value_ = rhs.value();
227 index_ = rhs.index();
228 return *this;
229}
230//*************************************************************************************************
231
232
233//*************************************************************************************************
243template< typename Type > // Type of the value element
244template< typename Other > // Data type of the right-hand side value-index-pair
245constexpr auto ValueIndexPair<Type>::operator=( Other&& rhs )
247 IsRValueReference_v<Other&&>, ValueIndexPair& >
248{
249 value_ = std::move( rhs.value() );
250 index_ = rhs.index();
251 return *this;
252}
253//*************************************************************************************************
254
255
256//*************************************************************************************************
262template< typename Type > // Type of the value element
263template< typename Other > // Data type of the right-hand side value
264constexpr auto ValueIndexPair<Type>::operator=( const Other& v )
266{
267 value_ = v;
268 return *this;
269}
270//*************************************************************************************************
271
272
273//*************************************************************************************************
279template< typename Type > // Type of the value element
280template< typename Other > // Data type of the right-hand side value
281constexpr auto ValueIndexPair<Type>::operator=( Other&& v )
282 -> EnableIf_t< !IsSparseElement_v< RemoveReference_t<Other> > &&
283 IsRValueReference_v<Other&&>, ValueIndexPair& >
284{
285 value_ = std::move( v );
286 return *this;
287}
288//*************************************************************************************************
289
290
291//*************************************************************************************************
297template< typename Type > // Type of the value element
298template< typename Other > // Data type of the right-hand side value
300{
301 value_ += v;
302 return *this;
303}
304//*************************************************************************************************
305
306
307//*************************************************************************************************
313template< typename Type > // Type of the value element
314template< typename Other > // Data type of the right-hand side value
316{
317 value_ -= v;
318 return *this;
319}
320//*************************************************************************************************
321
322
323//*************************************************************************************************
329template< typename Type > // Type of the value element
330template< typename Other > // Data type of the right-hand side value
332{
333 value_ *= v;
334 return *this;
335}
336//*************************************************************************************************
337
338
339//*************************************************************************************************
345template< typename Type > // Type of the value element
346template< typename Other > // Data type of the right-hand side value
348{
349 value_ /= v;
350 return *this;
351}
352//*************************************************************************************************
353
354
355
356
357//=================================================================================================
358//
359// ACCESS FUNCTIONS
360//
361//=================================================================================================
362
363//*************************************************************************************************
368template< typename Type > // Type of the value element
369constexpr typename ValueIndexPair<Type>::Reference
371{
372 return value_;
373}
374//*************************************************************************************************
375
376
377//*************************************************************************************************
382template< typename Type > // Type of the value element
385{
386 return value_;
387}
388//*************************************************************************************************
389
390
391//*************************************************************************************************
396template< typename Type > // Type of the value element
397constexpr typename ValueIndexPair<Type>::IndexType
399{
400 return index_;
401}
402//*************************************************************************************************
403
404} // namespace blaze
405
406#endif
Constraint on the data type.
Header file for the EnableIf class template.
Header file for the IsRValueReference type trait.
Header file for the IsSparseElement type trait class.
Constraint on the data type.
Constraint on the data type.
Header file for the RemoveReference type trait.
Constraint on the data type.
Index-value-pair for sparse vectors and matrices.
Definition: ValueIndexPair.h:75
size_t index_
Index of the value-index-pair.
Definition: ValueIndexPair.h:147
constexpr IndexType index() const noexcept
Access to the current index of the value-index-pair.
Definition: ValueIndexPair.h:398
const Type & ConstReference
Reference-to-const return type.
Definition: ValueIndexPair.h:81
Type & Reference
Reference return type.
Definition: ValueIndexPair.h:80
constexpr ValueIndexPair()
Default constructor for value-index-pairs.
Definition: ValueIndexPair.h:182
Type ValueType
The value type of the value-index-pair.
Definition: ValueIndexPair.h:78
constexpr Reference value() noexcept
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:370
Type value_
Value of the value-index-pair.
Definition: ValueIndexPair.h:146
size_t IndexType
The index type of the value-index-pair.
Definition: ValueIndexPair.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.
Definition: EnableIf.h:138
Header file for the SparseElement base class.
Base class for all sparse element types.
Definition: SparseElement.h:58
Header file for basic type definitions.
Header file for the And_t alias template.
Header file for the Not_t alias template.