Blaze 3.9
UnsignedValue.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_UTIL_UNSIGNEDVALUE_H_
36#define _BLAZE_UTIL_UNSIGNEDVALUE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <iosfwd>
45
46
47namespace blaze {
48
49//=================================================================================================
50//
51// CLASS DEFINITION
52//
53//=================================================================================================
54
55//*************************************************************************************************
62template< typename T > // Type of the unsigned value
64{
65 public:
66 //**Constructors********************************************************************************
69 explicit inline UnsignedValue( T value=0 );
71 //**********************************************************************************************
72
73 //**Assignment operators************************************************************************
76 inline UnsignedValue& operator=( T value );
78 //**********************************************************************************************
79
80 //**Conversion operators************************************************************************
83 inline operator T() const;
85 //**********************************************************************************************
86
87 //**Access function*****************************************************************************
90 inline T get() const;
92 //**********************************************************************************************
93
94 private:
95 //**Member variables****************************************************************************
100 //**********************************************************************************************
101
102 //**Compile time checks*************************************************************************
106 //**********************************************************************************************
107};
108//*************************************************************************************************
109
110
111
112
113//=================================================================================================
114//
115// CONSTRUCTORS
116//
117//=================================================================================================
118
119//*************************************************************************************************
124template< typename T > // Type of the unsigned value
126 : value_( value ) // The wrapped built-in unsigned integral value
127{}
128//*************************************************************************************************
129
130
131
132
133//=================================================================================================
134//
135// ASSIGNMENT OPERATOR
136//
137//=================================================================================================
138
139//*************************************************************************************************
145template< typename T > // Type of the unsigned value
147{
148 value_ = value;
149 return *this;
150}
151//*************************************************************************************************
152
153
154
155
156//=================================================================================================
157//
158// CONVERSION OPERATOR
159//
160//=================================================================================================
161
162//*************************************************************************************************
167template< typename T > // Type of the unsigned value
169{
170 return value_;
171}
172//*************************************************************************************************
173
174
175
176
177//=================================================================================================
178//
179// ACCESS FUNCTIONS
180//
181//=================================================================================================
182
183//*************************************************************************************************
188template< typename T > // Type of the unsigned value
189inline T UnsignedValue<T>::get() const
190{
191 return value_;
192}
193//*************************************************************************************************
194
195
196
197
198//=================================================================================================
199//
200// GLOBAL OPERATORS
201//
202//=================================================================================================
203
204//*************************************************************************************************
207template< typename T1, typename T2 >
208inline bool operator==( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
209
210template< typename T1, typename T2 >
211inline bool operator!=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
212
213template< typename T1, typename T2 >
214inline bool operator< ( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
215
216template< typename T1, typename T2 >
217inline bool operator> ( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
218
219template< typename T1, typename T2 >
220inline bool operator<=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
221
222template< typename T1, typename T2 >
223inline bool operator>=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
224
225template< typename T >
226inline std::ostream& operator<<( std::ostream& os, const UnsignedValue<T>& uv );
227
228template< typename T >
229std::istream& operator>>( std::istream& is, UnsignedValue<T>& uv );
231//*************************************************************************************************
232
233
234//*************************************************************************************************
241template< typename T1 // Type of the left-hand side unsigned value
242 , typename T2 > // Type of the right-hand side unsigned value
243inline bool operator==( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
244{
245 return lhs.get() == rhs.get();
246}
247//*************************************************************************************************
248
249
250//*************************************************************************************************
257template< typename T1 // Type of the left-hand side unsigned value
258 , typename T2 > // Type of the right-hand side unsigned value
259inline bool operator!=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
260{
261 return lhs.get() != rhs.get();
262}
263//*************************************************************************************************
264
265
266//*************************************************************************************************
273template< typename T1 // Type of the left-hand side unsigned value
274 , typename T2 > // Type of the right-hand side unsigned value
275inline bool operator<( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
276{
277 return lhs.get() < rhs.get();
278}
279//*************************************************************************************************
280
281
282//*************************************************************************************************
289template< typename T1 // Type of the left-hand side unsigned value
290 , typename T2 > // Type of the right-hand side unsigned value
291inline bool operator>( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
292{
293 return lhs.get() > rhs.get();
294}
295//*************************************************************************************************
296
297
298//*************************************************************************************************
305template< typename T1 // Type of the left-hand side unsigned value
306 , typename T2 > // Type of the right-hand side unsigned value
307inline bool operator<=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
308{
309 return lhs.get() <= rhs.get();
310}
311//*************************************************************************************************
312
313
314//*************************************************************************************************
321template< typename T1 // Type of the left-hand side unsigned value
322 , typename T2 > // Type of the right-hand side unsigned value
323inline bool operator>=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
324{
325 return lhs.get() >= rhs.get();
326}
327//*************************************************************************************************
328
329
330//*************************************************************************************************
337template< typename T > // Type of the unsigned value
338inline std::ostream& operator<<( std::ostream& os, const UnsignedValue<T>& uv )
339{
340 return os << uv.get();
341}
342//*************************************************************************************************
343
344
345//*************************************************************************************************
357template< typename T > // Type of the unsigned value
358std::istream& operator>>( std::istream& is, UnsignedValue<T>& uv )
359{
360 T tmp;
361 const std::istream::pos_type pos( is.tellg() );
362
363 // Skipping any leading whitespaces
364 is >> std::ws;
365
366 // Extracting the value
367 if( is.peek() == '-' || !(is >> tmp) )
368 {
369 is.clear();
370 is.seekg( pos );
371 is.setstate( std::istream::failbit );
372 return is;
373 }
374
375 // Transfering the input to the unsigned integer value
376 uv = tmp;
377
378 return is;
379}
380//*************************************************************************************************
381
382} // namespace blaze
383
384#endif
Constraint on the data type.
Implementation of a wrapper for built-in unsigned integral values.
Definition: UnsignedValue.h:64
T get() const
Access to the wrapped built-in unsigned integral value.
Definition: UnsignedValue.h:189
UnsignedValue(T value=0)
The default constructor for UnsignedInt.
Definition: UnsignedValue.h:125
T value_
The wrapped built-in unsigned integral value.
Definition: UnsignedValue.h:98
UnsignedValue & operator=(T value)
Assignment of a built-in unsigned integral value.
Definition: UnsignedValue.h:146
#define BLAZE_CONSTRAINT_MUST_BE_UNSIGNED_TYPE(T)
Constraint on the data type.
Definition: Unsigned.h:61
decltype(auto) operator<<(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Left-shift operator for the elementwise left-shift of a dense matrix.
Definition: DMatDMatMapExpr.h:1570
decltype(auto) operator>>(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Right-shift operator for the elementwise right-shift of a dense matrix.
Definition: DMatDMatMapExpr.h:1604
constexpr bool operator>(const NegativeAccuracy< A > &lhs, const T &rhs)
Greater-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:370
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
constexpr bool operator<(const NegativeAccuracy< A > &lhs, const T &rhs)
Less-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:332
constexpr bool operator>=(const NegativeAccuracy< A > &, const T &rhs)
Greater-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:446
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
constexpr bool operator<=(const NegativeAccuracy< A > &, const T &rhs)
Less-or-equal-than comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:408