Blaze  3.6
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********************************************************************************
87  inline constexpr ValueIndexPair();
88  inline 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  inline constexpr auto operator=( const Other& rhs )
111 
112  template< typename Other >
113  inline constexpr auto operator=( Other&& rhs )
115  IsRValueReference_v<Other&&>, ValueIndexPair& >;
116 
117  template< typename Other >
118  inline constexpr auto operator=( const Other& v )
120 
121  template< typename Other >
122  inline constexpr auto operator=( Other&& v )
124  IsRValueReference_v<Other&&>, ValueIndexPair& >;
125 
126  template< typename Other > inline constexpr ValueIndexPair& operator+=( const Other& v );
127  template< typename Other > inline constexpr ValueIndexPair& operator-=( const Other& v );
128  template< typename Other > inline constexpr ValueIndexPair& operator*=( const Other& v );
129  template< typename Other > inline constexpr ValueIndexPair& operator/=( const Other& v );
131  //**********************************************************************************************
132 
133  //**Acess functions*****************************************************************************
136  inline constexpr Reference value() noexcept;
137  inline constexpr ConstReference value() const noexcept;
138  inline constexpr IndexType index() const noexcept;
140  //**********************************************************************************************
141 
142  protected:
143  //**Member variables****************************************************************************
146  Type value_;
147  size_t index_;
148 
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 //*************************************************************************************************
181 template< typename Type > // Type of the value element
182 inline constexpr ValueIndexPair<Type>::ValueIndexPair()
183  : value_() // Value of the value-index-pair
184  , index_() // Index of the value-index-pair
185 {}
186 //*************************************************************************************************
187 
188 
189 //*************************************************************************************************
195 template< typename Type > // Type of the value element
196 inline constexpr 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 //*************************************************************************************************
221 template< typename Type > // Type of the value element
222 template< typename Other > // Data type of the right-hand side value-index-pair
223 inline constexpr auto ValueIndexPair<Type>::operator=( const Other& rhs )
225 {
226  value_ = rhs.value();
227  index_ = rhs.index();
228  return *this;
229 }
230 //*************************************************************************************************
231 
232 
233 //*************************************************************************************************
243 template< typename Type > // Type of the value element
244 template< typename Other > // Data type of the right-hand side value-index-pair
245 inline constexpr 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 //*************************************************************************************************
262 template< typename Type > // Type of the value element
263 template< typename Other > // Data type of the right-hand side value
264 inline constexpr auto ValueIndexPair<Type>::operator=( const Other& v )
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
281 inline constexpr 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 //*************************************************************************************************
297 template< typename Type > // Type of the value element
298 template< typename Other > // Data type of the right-hand side value
299 inline constexpr ValueIndexPair<Type>& ValueIndexPair<Type>::operator+=( const Other& v )
300 {
301  value_ += v;
302  return *this;
303 }
304 //*************************************************************************************************
305 
306 
307 //*************************************************************************************************
313 template< typename Type > // Type of the value element
314 template< typename Other > // Data type of the right-hand side value
315 inline constexpr ValueIndexPair<Type>& ValueIndexPair<Type>::operator-=( const Other& v )
316 {
317  value_ -= v;
318  return *this;
319 }
320 //*************************************************************************************************
321 
322 
323 //*************************************************************************************************
329 template< typename Type > // Type of the value element
330 template< typename Other > // Data type of the right-hand side value
331 inline constexpr ValueIndexPair<Type>& ValueIndexPair<Type>::operator*=( const Other& v )
332 {
333  value_ *= v;
334  return *this;
335 }
336 //*************************************************************************************************
337 
338 
339 //*************************************************************************************************
345 template< typename Type > // Type of the value element
346 template< typename Other > // Data type of the right-hand side value
347 inline constexpr ValueIndexPair<Type>& ValueIndexPair<Type>::operator/=( const Other& v )
348 {
349  value_ /= v;
350  return *this;
351 }
352 //*************************************************************************************************
353 
354 
355 
356 
357 //=================================================================================================
358 //
359 // ACCESS FUNCTIONS
360 //
361 //=================================================================================================
362 
363 //*************************************************************************************************
368 template< typename Type > // Type of the value element
369 inline constexpr typename ValueIndexPair<Type>::Reference
371 {
372  return value_;
373 }
374 //*************************************************************************************************
375 
376 
377 //*************************************************************************************************
382 template< typename Type > // Type of the value element
383 inline constexpr typename ValueIndexPair<Type>::ConstReference
385 {
386  return value_;
387 }
388 //*************************************************************************************************
389 
390 
391 //*************************************************************************************************
396 template< typename Type > // Type of the value element
397 inline constexpr typename ValueIndexPair<Type>::IndexType
399 {
400  return index_;
401 }
402 //*************************************************************************************************
403 
404 } // namespace blaze
405 
406 #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,...
Definition: Const.h:79
Header file for basic type definitions.
Header file for the And_t alias 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,...
Definition: Volatile.h:79
Constraint on the data type.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
const Type & ConstReference
Reference-to-const return type.
Definition: ValueIndexPair.h:81
constexpr IndexType index() const noexcept
Access to the current index of the value-index-pair.
Definition: ValueIndexPair.h:398
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
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:147
Header file for the EnableIf class template.
Header file for the Not_t alias template.
Type & Reference
Reference return type.
Definition: ValueIndexPair.h:80
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,...
Definition: Reference.h:79
constexpr ValueIndexPair()
Default constructor for value-index-pairs.
Definition: ValueIndexPair.h:182
constexpr Reference value() noexcept
Access to the current value of the value-index-pair.
Definition: ValueIndexPair.h:370
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.
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:73
Type value_
Value of the value-index-pair.
Definition: ValueIndexPair.h:146
Size type of the Blaze library.