xtd 0.2.0
is.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "any.hpp"
6#include "parse.hpp"
7#include "types.hpp"
8#include "unused.hpp"
9#include <limits>
10#include <memory>
11#include <stdexcept>
12
14namespace xtd {
16 template<class value_t>
17 inline bool is(bool value) {return false;}
18 template<class value_t>
19 inline bool is(char value) {return false;}
20 template<class value_t>
21 inline bool is(char16 value) {return false;}
22 template<class value_t>
23 inline bool is(char32 value) {return false;}
24 template<class value_t>
25 inline bool is(char8 value) {return false;}
26 template<class value_t>
27 inline bool is(wchar value) {return false;}
28 template<class value_t>
29 inline bool is(decimal value) {return false;}
30 template<class value_t>
31 inline bool is(double value) {return false;}
32 template<class value_t>
33 inline bool is(float value) {return false;}
34 template<class value_t>
35 inline bool is(sbyte value) {return false;}
36 template<class value_t>
37 inline bool is(int16 value) {return false;}
38 template<class value_t>
39 inline bool is(int32 value) {return false;}
40 template<class value_t>
41 inline bool is(int64 value) {return false;}
42 template<class value_t>
43 inline bool is(slong value) {return false;}
44 template<class value_t>
45 inline bool is(xtd::byte value) {return false;}
46 template<class value_t>
47 inline bool is(uint16 value) {return false;}
48 template<class value_t>
49 inline bool is(uint32 value) {return false;}
50 template<class value_t>
51 inline bool is(uint64 value) {return false;}
52 template<class value_t>
53 inline bool is(xtd::ulong value) {return false;}
55
73 template<>
74 inline bool is<bool>(bool value) {
75 return true;
76 }
77
95 template<>
96 inline bool is<char>(char value) {
97 return true;
98 }
99
117 template<>
118 inline bool is<char16>(char16 value) {
119 return true;
120 }
121
139 template<>
140 inline bool is<char32>(char32 value) {
141 return true;
142 }
143
161 template<>
162 inline bool is<char8>(char8 value) {
163 return true;
164 }
165
183 template<>
184 inline bool is<wchar>(wchar value) {
185 return true;
186 }
187
205 template<>
206 inline bool is<decimal>(decimal value) {
207 return true;
208 }
209
227 template<>
228 inline bool is<double>(double value) {
229 return true;
230 }
231
249 template<>
250 inline bool is<float>(float value) {
251 return true;
252 }
253
271 template<>
272 inline bool is<sbyte>(sbyte value) {
273 return true;
274 }
275
293 template<>
294 inline bool is<int16>(int16 value) {
295 return true;
296 }
297
315 template<>
316 inline bool is<int32>(int32 value) {
317 return true;
318 }
319
337 template<>
338 inline bool is<int64>(int64 value) {
339 return true;
340 }
341
359 template<>
360 inline bool is<slong>(slong value) {
361 return true;
362 }
363
381 template<>
382 inline bool is<xtd::byte>(xtd::byte value) {
383 return true;
384 }
385
403 template<>
404 inline bool is<uint16>(uint16 value) {
405 return true;
406 }
407
425 template<>
426 inline bool is<uint32>(uint32 value) {
427 return true;
428 }
429
447 template<>
448 inline bool is<uint64>(uint64 value) {
449 return true;
450 }
451
469 template<>
470 inline bool is<xtd::ulong>(xtd::ulong value) {
471 return true;
472 }
473
484 template<class type_t>
485 bool is(xtd::any value) {
486 try {
488 return true;
489 } catch (const std::bad_cast&) {
490 return false;
491 }
492 }
493
504 template<>
505 inline bool is<xtd::any>(xtd::any value) {
506 return true;
507 }
508
519 template<class type_t, class param_t>
520 bool is(const param_t* value) {
521 try {
522 if (value == nullptr) return false;
523 return dynamic_cast<const type_t*>(value) != nullptr;
524 } catch (const std::bad_cast&) {
525 return false;
526 }
527 }
528
539 template<class type_t, class param_t>
540 bool is(const param_t& value) {
541 return is<type_t>(&value);
542 }
543
554 template<class type_t, class param_t>
555 bool is(param_t* value) {
556 try {
557 if (value == nullptr) return false;
558 return dynamic_cast<type_t*>(value) != nullptr;
559 } catch (const std::bad_cast&) {
560 return false;
561 }
562 }
563
574 template<class type_t, class param_t>
575 bool is(param_t& value) {
576 return is<type_t>(&value);
577 }
578
589 template<class new_type_t, class current_type_t>
591 auto result = std::dynamic_pointer_cast<new_type_t>(value.pointer());
592 if (result) return true;
593 return false;
594 }
595}
Contains xtd::any type and std::bad_any_cast exception.
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
__slong__ slong
Represents a 32-bit or 64-bit signed integer.
Definition slong.hpp:27
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
__ulong__ ulong
Represents a 32-bit or 64-bit unsigned integer.
Definition ulong.hpp:27
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
uint8_t byte
Represents a 8-bit unsigned integer.
Definition byte.hpp:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
int16_t int16
Represents a 16-bit signed integer.
Definition int16.hpp:23
uint16_t uint16
Represents a 16-bit unsigned integer.
Definition uint16.hpp:23
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:23
std::any any
Represents the any alias on std::any.
Definition any.hpp:24
bool is< float >(float value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:250
bool is< slong >(slong value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:360
bool is< wchar >(wchar value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:184
bool is< xtd::ulong >(xtd::ulong value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:470
type_t any_cast(const xtd::any &operand)
Performs type-safe access to the contained object.
Definition any_cast.hpp:22
bool is< sbyte >(sbyte value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:272
bool is< decimal >(decimal value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:206
bool is< int64 >(int64 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:338
bool is< char16 >(char16 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:118
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:485
bool is< xtd::any >(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:505
bool is< char32 >(char32 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:140
bool is< uint64 >(uint64 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:448
bool is< double >(double value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:228
bool is< uint16 >(uint16 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:404
bool is< bool >(bool value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:74
bool is< uint32 >(uint32 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:426
bool is< char8 >(char8 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:162
bool is< int32 >(int32 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:316
bool is< char >(char value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:96
bool is< int16 >(int16 value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:294
bool is< xtd::byte >(xtd::byte value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:382
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::parse methods.
Contains xtd fundamental types.
Contains unused_ keyword.