|
1 | 1 | # SmartPointerTypeTrait
|
2 |
| -C++ Type Traits for Smart Pointer |
| 2 | +A simple, header-only cpp library implementing smart pointer type traits. |
| 3 | +You can easily compile your code diffrently depending on which pointer-type is used. |
| 4 | +You can find inheritance and you won't have trouble with const, volatile keywords. |
| 5 | +Type traits are generally used for static assertions and static polymorphism.(C++ 17 if constexpr) |
| 6 | +However, the standard library's type traits do not support smart pointers, and do not support inheritance. |
| 7 | +This is why smart pointer type traits made. |
3 | 8 |
|
| 9 | +# Release Note |
| 10 | +version 1.0 released. |
4 | 11 |
|
5 |
| -## is_a_pointer |
6 |
| -* is_smart_pointer<T> |
| 12 | + |
| 13 | +# Installation |
| 14 | +All you need to to is copy over the smart_pointer_type_trait.hpp header file. |
| 15 | +include it in your solution, and you are good to go. |
| 16 | + |
| 17 | + |
| 18 | +# Guide |
| 19 | +All evaluations occurs after removing const, volatile, reference. |
| 20 | + |
| 21 | +## Hard Type Traits |
| 22 | +* is_ptr<T> |
| 23 | +```c++ |
| 24 | +template < typename T > |
| 25 | +struct is_ptr : is_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {}; |
| 26 | +``` |
| 27 | +```is_ptr<T>::value```/```is_ptr_v<T>``` is ```true``` if ```T``` is ```std::shared_ptr``` or ```std::unique_ptr``` or a raw pointer. |
| 28 | +
|
| 29 | +* is_smart_ptr<T> |
7 | 30 | ```c++
|
8 |
| -template < typename T > struct is_smart_ptr : is_smart_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {}; |
| 31 | +template < typename T > |
| 32 | +struct is_smart_ptr : is_smart_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {}; |
9 | 33 | ```
|
10 | 34 | ```is_smart_ptr<T>::value```/```is_smart_ptr_v<T>``` is ```true``` if ```T``` is ```std::shared_ptr``` or ```std::unique_ptr```.
|
11 | 35 |
|
12 |
| -Evaluation occurs after removing const, volatile, reference. |
| 36 | + |
13 | 37 | * is_shared_ptr<T>
|
14 | 38 | ```c++
|
15 |
| -template < typename T > struct is_shared_ptr : is_shared_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {}; |
| 39 | +template < typename T > |
| 40 | +struct is_shared_ptr : is_shared_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {}; |
16 | 41 | ```
|
17 | 42 | ```is_shared_ptr<T>::value```/```is_shared_ptr_v<T>``` is ```true``` if ```T``` is ```std::shared_ptr```.
|
18 | 43 |
|
19 |
| -Evaluation occurs after removing const, volatile, reference. |
20 | 44 | * is_unique_ptr<T>
|
21 | 45 | ```c++
|
22 |
| -template < typename T > struct is_unique_ptr : is_unique_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {}; |
| 46 | +template < typename T > |
| 47 | +struct is_unique_ptr : is_unique_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {}; |
23 | 48 | ```
|
24 | 49 | ```is_unique_ptr<T>::value```/```is_unique_ptr_v<T>``` is ```true``` if ```T``` is ```std::unique_ptr```.
|
25 | 50 |
|
26 |
| -Evaluation occurs after removing const, volatile, reference. |
27 | 51 |
|
28 |
| -## inherit_from_a_pointer |
29 |
| -* inherit_from_smart_pointer<T> |
| 52 | +## Soft Type Traits |
| 53 | +* is_ptr_soft<T> |
30 | 54 | ```c++
|
31 | 55 | template < typename T >
|
32 |
| -using inherit_from_smart_ptr = decltype( inherit_from_smart_ptr_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) ); |
| 56 | +using is_ptr_soft = decltype( is_ptr_soft_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) ); |
33 | 57 | ```
|
34 |
| -```inherit_from_smart_ptr<T>::value```/```inherit_from_smart_ptr_v<T>``` is ```true``` if ```T``` is derived from ```std::shared_ptr``` or ```std::unique_ptr```. |
35 |
| - |
36 |
| -Evaluation occurs after removing const, volatile, reference. |
37 |
| - |
38 |
| -* inherit_from_shared_pointer<T> |
| 58 | +```is_ptr_soft<T>::value```/```is_ptr_soft_v<T>``` is ```true``` if ```T``` is derived from ```std::shared_ptr``` or ```std::unique_ptr``` or is a raw pointer. |
| 59 | + |
| 60 | +* is_smart_ptr_soft<T> |
39 | 61 | ```c++
|
40 | 62 | template < typename T >
|
41 |
| -using inherit_from_shared_ptr = decltype( inherit_from_shared_ptr_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) ); |
| 63 | +using is_smart_ptr_soft = decltype( is_smart_ptr_soft_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) ); |
42 | 64 | ```
|
43 |
| -```inherit_from_shared_ptr<T>::value```/```inherit_from_shared_ptr_v<T>``` is ```true``` if ```T``` is derived from ```std::shared_ptr```. |
| 65 | +```is_smart_ptr_soft<T>::value```/```is_smart_ptr_soft_v<T>``` is ```true``` if ```T``` is derived from ```std::shared_ptr``` or ```std::unique_ptr```. |
44 | 66 |
|
45 |
| -Evaluation occurs after removing const, volatile, reference. |
46 |
| - |
47 |
| -* inherit_from_unique_pointer<T> |
| 67 | +* is_shared_ptr_soft<T> |
48 | 68 | ```c++
|
49 | 69 | template < typename T >
|
50 |
| -using inherit_from_unique_ptr = decltype( inherit_from_unique_ptr_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) ); |
| 70 | +using is_shared_ptr_soft = decltype( is_shared_ptr_soft_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) ); |
51 | 71 | ```
|
52 |
| -```inherit_from_unique_ptr<T>::value```/```inherit_from_unique_ptr_v<T>``` is ```true``` if ```T``` is derived from ```std::unique_ptr```. |
| 72 | +```is_shared_ptr_soft<T>::value```/```is_shared_ptr_soft_v<T>``` is ```true``` if ```T``` is derived from ```std::shared_ptr```. |
53 | 73 |
|
54 |
| -Evaluation occurs after removing const, volatile, reference. |
| 74 | +* is_unique_ptr_soft<T> |
| 75 | +```c++ |
| 76 | +template < typename T > |
| 77 | +using is_unique_ptr_soft = decltype( is_unique_ptr_soft_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) ); |
| 78 | +``` |
| 79 | +```is_unique_ptr_soft<T>::value```/```is_unique_ptr_soft_v<T>``` is ```true``` if ```T``` is derived from ```std::unique_ptr```. |
55 | 80 |
|
56 | 81 | # example
|
57 |
| - |
| 82 | + |
| 83 | + |
| 84 | + |
58 | 85 |
|
59 | 86 | ## reference
|
60 | 87 |
|
|
0 commit comments