xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
is.h
Go to the documentation of this file.
1 #pragma once
5 #include <any>
6 #include <limits>
7 #include <memory>
8 #include <stdexcept>
9 #include "parse.h"
10 #include "types.h"
11 #include "unused.h"
12 
14 namespace xtd {
16  template<typename value_t>
17  inline bool is(bool value) {return false;}
18  template<typename value_t>
19  inline bool is(decimal_t value) {return false;}
20  template<typename value_t>
21  inline bool is(double value) {return false;}
22  template<typename value_t>
23  inline bool is(float value) {return false;}
24  template<typename value_t>
25  inline bool is(int8_t value) {return false;}
26  template<typename value_t>
27  inline bool is(int16_t value) {return false;}
28  template<typename value_t>
29  inline bool is(int32_t value) {return false;}
30  template<typename value_t>
31  inline bool is(int64_t value) {return false;}
32  template<typename value_t>
33  inline bool is(llong_t value) {return false;}
34  template<typename value_t>
35  inline bool is(uint8_t value) {return false;}
36  template<typename value_t>
37  inline bool is(uint16_t value) {return false;}
38  template<typename value_t>
39  inline bool is(uint32_t value) {return false;}
40  template<typename value_t>
41  inline bool is(uint64_t value) {return false;}
42  template<typename value_t>
43  inline bool is(ullong_t value) {return false;}
45 
59  template<>
60  inline bool is<bool>(bool value) {
61  return true;
62  }
63 
77  template<>
78  inline bool is<decimal_t>(decimal_t value) {
79  return true;
80  }
81 
95  template<>
96  inline bool is<double>(double value) {
97  return true;
98  }
99 
113  template<>
114  inline bool is<float>(float value) {
115  return true;
116  }
117 
131  template<>
132  inline bool is<int8_t>(int8_t value) {
133  return true;
134  }
135 
149  template<>
150  inline bool is<int16_t>(int16_t value) {
151  return true;
152  }
153 
167  template<>
168  inline bool is<int32_t>(int32_t value) {
169  return true;
170  }
171 
185  template<>
186  inline bool is<int64_t>(int64_t value) {
187  return true;
188  }
189 
203  template<>
204  inline bool is<llong_t>(llong_t value) {
205  return true;
206  }
207 
221  template<>
222  inline bool is<uint8_t>(uint8_t value) {
223  return true;
224  }
225 
239  template<>
240  inline bool is<uint16_t>(uint16_t value) {
241  return true;
242  }
243 
257  template<>
258  inline bool is<uint32_t>(uint32_t value) {
259  return true;
260  }
261 
275  template<>
276  inline bool is<uint64_t>(uint64_t value) {
277  return true;
278  }
279 
293  template<>
294  inline bool is<ullong_t>(ullong_t value) {
295  return true;
296  }
297 
304  template<typename type_t>
305  bool is(std::any value) {
306  try {
307  any_cast<type_t>(value);
308  return true;
309  } catch (const std::bad_cast&) {
310  return false;
311  }
312  }
313 
320  template<>
321  inline bool is<std::any>(std::any value) {
322  return true;
323  }
324 
331  template<typename type_t, typename param_t>
332  bool is(const param_t* value) {
333  try {
334  if (value == nullptr) return false;
335  return dynamic_cast<const type_t*>(value) != nullptr;
336  } catch (const std::bad_cast&) {
337  return false;
338  }
339  }
340 
347  template<typename type_t, typename param_t>
348  bool is(const param_t& value) {
349  return is<type_t>(&value);
350  }
351 
358  template<typename type_t, typename param_t>
359  bool is(param_t* value) {
360  try {
361  if (value == nullptr) return false;
362  return dynamic_cast<type_t*>(value) != nullptr;
363  } catch (const std::bad_cast&) {
364  return false;
365  }
366  }
367 
374  template<typename type_t, typename param_t>
375  bool is(param_t& value) {
376  return is<type_t>(&value);
377  }
378 
385  template<typename new_type_t, typename current_type_t>
386  bool is(std::shared_ptr<current_type_t>& value) {
387  try {
388  unused_(dynamic_pointer_cast<new_type_t>(value));
389  return true;
390  } catch (const std::exception&) {
391  return false;
392  }
393  return false;
394  }
395 }
#define unused_
It may be used to suppress the "unused variable" or "unused local typedefs" compiler warnings when th...
Definition: unused.h:31
bool is< uint64_t >(uint64_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:276
bool is< ullong_t >(ullong_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:294
bool is< uint16_t >(uint16_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:240
bool is< float >(float value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:114
bool is< int64_t >(int64_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:186
bool is< decimal_t >(decimal_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:78
bool is< uint8_t >(uint8_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:222
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:305
bool is< int32_t >(int32_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:168
bool is< int8_t >(int8_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:132
bool is< uint32_t >(uint32_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:258
bool is< double >(double value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:96
bool is< llong_t >(llong_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:204
bool is< bool >(bool value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:60
bool is< int16_t >(int16_t value)
Checks if the result of an expression is compatible with a given type.
Definition: is.h:150
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::parse methods.
Contains xtd fundamental types.
Contains unused_ keyword.