Skip to content

Commit 07f07b4

Browse files
committed
2 parents ffda672 + a42bc2c commit 07f07b4

File tree

1 file changed

+53
-26
lines changed

1 file changed

+53
-26
lines changed

README.md

+53-26
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,87 @@
11
# 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.
38

9+
# Release Note
10+
version 1.0 released.
411

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>
730
```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 > > > {};
933
```
1034
```is_smart_ptr<T>::value```/```is_smart_ptr_v<T>``` is ```true``` if ```T``` is ```std::shared_ptr``` or ```std::unique_ptr```.
1135

12-
Evaluation occurs after removing const, volatile, reference.
36+
1337
* is_shared_ptr<T>
1438
```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 > > > {};
1641
```
1742
```is_shared_ptr<T>::value```/```is_shared_ptr_v<T>``` is ```true``` if ```T``` is ```std::shared_ptr```.
1843
19-
Evaluation occurs after removing const, volatile, reference.
2044
* is_unique_ptr<T>
2145
```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 > > > {};
2348
```
2449
```is_unique_ptr<T>::value```/```is_unique_ptr_v<T>``` is ```true``` if ```T``` is ```std::unique_ptr```.
2550

26-
Evaluation occurs after removing const, volatile, reference.
2751

28-
## inherit_from_a_pointer
29-
* inherit_from_smart_pointer<T>
52+
## Soft Type Traits
53+
* is_ptr_soft<T>
3054
```c++
3155
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 > >* >() ) );
3357
```
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>
3961
```c++
4062
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 > >* >() ) );
4264
```
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```.
4466

45-
Evaluation occurs after removing const, volatile, reference.
46-
47-
* inherit_from_unique_pointer<T>
67+
* is_shared_ptr_soft<T>
4868
```c++
4969
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 > >* >() ) );
5171
```
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```.
5373

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```.
5580

5681
# example
57-
![Smart Pointer Type Trait](https://user-images.githubusercontent.com/73771162/146510184-589f642d-3451-4a41-976b-d09cb144b2c9.PNG)
82+
![Smart Pointer Type Trait1](https://user-images.githubusercontent.com/73771162/146930931-ff47a89d-86ab-402c-a558-fccd9670edc3.PNG)
83+
![Smart Pointer Type Trait2](https://user-images.githubusercontent.com/73771162/146931121-43c0be51-8a52-4f49-a87f-b00562bacd1f.PNG)
84+
5885

5986
## reference
6087

0 commit comments

Comments
 (0)