Blaze  3.6
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 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // CLASS DEFINITION
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
62 template< 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****************************************************************************
98  T value_;
99 
100  //**********************************************************************************************
101 
102  //**Compile time checks*************************************************************************
106  //**********************************************************************************************
107 };
108 //*************************************************************************************************
109 
110 
111 
112 
113 //=================================================================================================
114 //
115 // CONSTRUCTORS
116 //
117 //=================================================================================================
118 
119 //*************************************************************************************************
124 template< 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 //*************************************************************************************************
145 template< 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 //*************************************************************************************************
167 template< 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 //*************************************************************************************************
188 template< typename T > // Type of the unsigned value
189 inline T UnsignedValue<T>::get() const
190 {
191  return value_;
192 }
193 //*************************************************************************************************
194 
195 
196 
197 
198 //=================================================================================================
199 //
200 // GLOBAL OPERATORS
201 //
202 //=================================================================================================
203 
204 //*************************************************************************************************
207 template< typename T1, typename T2 >
208 inline bool operator==( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
209 
210 template< typename T1, typename T2 >
211 inline bool operator!=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
212 
213 template< typename T1, typename T2 >
214 inline bool operator< ( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
215 
216 template< typename T1, typename T2 >
217 inline bool operator> ( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
218 
219 template< typename T1, typename T2 >
220 inline bool operator<=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
221 
222 template< typename T1, typename T2 >
223 inline bool operator>=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs );
224 
225 template< typename T >
226 inline std::ostream& operator<<( std::ostream& os, const UnsignedValue<T>& uv );
227 
228 template< typename T >
229 std::istream& operator>>( std::istream& is, UnsignedValue<T>& uv );
231 //*************************************************************************************************
232 
233 
234 //*************************************************************************************************
241 template< typename T1 // Type of the left-hand side unsigned value
242  , typename T2 > // Type of the right-hand side unsigned value
243 inline bool operator==( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
244 {
245  return lhs.get() == rhs.get();
246 }
247 //*************************************************************************************************
248 
249 
250 //*************************************************************************************************
257 template< typename T1 // Type of the left-hand side unsigned value
258  , typename T2 > // Type of the right-hand side unsigned value
259 inline bool operator!=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
260 {
261  return lhs.get() != rhs.get();
262 }
263 //*************************************************************************************************
264 
265 
266 //*************************************************************************************************
273 template< typename T1 // Type of the left-hand side unsigned value
274  , typename T2 > // Type of the right-hand side unsigned value
275 inline bool operator<( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
276 {
277  return lhs.get() < rhs.get();
278 }
279 //*************************************************************************************************
280 
281 
282 //*************************************************************************************************
289 template< typename T1 // Type of the left-hand side unsigned value
290  , typename T2 > // Type of the right-hand side unsigned value
291 inline bool operator>( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
292 {
293  return lhs.get() > rhs.get();
294 }
295 //*************************************************************************************************
296 
297 
298 //*************************************************************************************************
305 template< typename T1 // Type of the left-hand side unsigned value
306  , typename T2 > // Type of the right-hand side unsigned value
307 inline bool operator<=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
308 {
309  return lhs.get() <= rhs.get();
310 }
311 //*************************************************************************************************
312 
313 
314 //*************************************************************************************************
321 template< typename T1 // Type of the left-hand side unsigned value
322  , typename T2 > // Type of the right-hand side unsigned value
323 inline bool operator>=( const UnsignedValue<T1>& lhs, const UnsignedValue<T2>& rhs )
324 {
325  return lhs.get() >= rhs.get();
326 }
327 //*************************************************************************************************
328 
329 
330 //*************************************************************************************************
337 template< typename T > // Type of the unsigned value
338 inline std::ostream& operator<<( std::ostream& os, const UnsignedValue<T>& uv )
339 {
340  return os << uv.get();
341 }
342 //*************************************************************************************************
343 
344 
345 //*************************************************************************************************
357 template< typename T > // Type of the unsigned value
358 std::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
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
UnsignedValue(T value=0)
The default constructor for UnsignedInt.
Definition: UnsignedValue.h:125
#define BLAZE_CONSTRAINT_MUST_BE_UNSIGNED_TYPE(T)
Constraint on the data type.In case the given data type T is not an unsigned integral data type,...
Definition: Unsigned.h:61
T value_
The wrapped built-in unsigned integral value.
Definition: UnsignedValue.h:98
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
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 > &, 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)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
UnsignedValue & operator=(T value)
Assignment of a built-in unsigned integral value.
Definition: UnsignedValue.h:146
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
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:1349
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
T get() const
Access to the wrapped built-in unsigned integral value.
Definition: UnsignedValue.h:189
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:1383
Implementation of a wrapper for built-in unsigned integral values.This class wraps a value of built-i...
Definition: UnsignedValue.h:63