Skip to content

Commit 9107286

Browse files
authored
Update README.md
1 parent 90a4b30 commit 9107286

File tree

1 file changed

+41
-27
lines changed

1 file changed

+41
-27
lines changed

README.md

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,94 +3,108 @@
33

44
A simple, header-only cpp library implementing smart pointer type traits.
55
You can easily compile your code diffrently depending on which pointer-type is used.
6-
You can find inheritance and you won't have trouble with const, volatile keywords.
6+
You can detect inheritance too and you won't have trouble with const, volatile keywords.
77

88
Type traits are generally used for static assertions and static polymorphism. (C++ 17 if constexpr)
9-
However, the standard library's type traits do not support smart pointers, and do not find inheritance.
9+
However, the standard library's type traits do not support smart pointers, and do not detect inheritance.
1010
This is why smart pointer type traits are made.
1111

1212
# Release Note
13-
version 1.0 released.
13+
Version 1.0 released.
1414
> https://github.com/MyeongWoonJang/cpp-smart-pointer-type-trait/releases/tag/release
1515
1616

1717
# Installation
1818
All you need to to is copy over the smart_pointer_type_trait.hpp header file.
19-
include it in your solution, and you are good to go.
19+
Include it in your solution, and you are good to go.
2020

2121

2222
# Guide
23-
All evaluations occurs after removing const, volatile, reference.
23+
All evaluations occurs after removing const, volatile, reference.
24+
Implementation is in namespace woon2.
25+
(Use like woon2::is_smart_ptr<T>, or write using namespace woon2; in your code.)
2426

2527
## Hard Type Traits
26-
* is_ptr<T>
28+
* is_pointable<T>
2729
```c++
2830
template < typename T >
29-
struct is_ptr : is_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {};
31+
using is_pointable = detail::is_pointable_impl< detail::remove_cvr_t< T > >;
3032
```
31-
```is_ptr<T>::value```/```is_ptr_v<T>``` is ```true``` if ```T``` is ```std::shared_ptr``` or ```std::unique_ptr``` or a raw pointer.
33+
```is_ptr<T>::value```/```is_ptr_v<T>``` is ```true``` if ```T``` has ```operator*``` and ```operator->```.
34+
detects all pointable classes such as ```std::unique_ptr<T>```, ```std::shared_ptr<T>```, ```T*```.
3235

3336
* is_smart_ptr<T>
3437
```c++
3538
template < typename T >
36-
struct is_smart_ptr : is_smart_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {};
39+
using is_smart_ptr = std::conditional_t<
40+
is_shared_ptr_v< T >,
41+
std::true_type,
42+
std::conditional_t<
43+
is_unique_ptr_v< T >,
44+
std::true_type,
45+
std::false_type
46+
>
47+
>;
3748
```
3849
```is_smart_ptr<T>::value```/```is_smart_ptr_v<T>``` is ```true``` if ```T``` is ```std::shared_ptr``` or ```std::unique_ptr```.
3950

4051

4152
* is_shared_ptr<T>
4253
```c++
4354
template < typename T >
44-
struct is_shared_ptr : is_shared_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {};
55+
using is_shared_ptr = detail::is_shared_ptr_impl< detail::remove_cvr_t< T > >;
4556
```
4657
```is_shared_ptr<T>::value```/```is_shared_ptr_v<T>``` is ```true``` if ```T``` is ```std::shared_ptr```.
4758

4859
* is_unique_ptr<T>
4960
```c++
5061
template < typename T >
51-
struct is_unique_ptr : is_unique_ptr_impl< std::remove_cv_t< std::remove_reference_t< T > > > {};
62+
using is_unique_ptr = detail::is_unique_ptr_impl< detail::remove_cvr_t< T > >;
5263
```
5364
```is_unique_ptr<T>::value```/```is_unique_ptr_v<T>``` is ```true``` if ```T``` is ```std::unique_ptr```.
5465

5566

5667
## Soft Type Traits
57-
* is_ptr_soft<T>
58-
```c++
59-
template < typename T >
60-
using is_ptr_soft = decltype( is_ptr_soft_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) );
61-
```
62-
```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.
63-
6468
* is_smart_ptr_soft<T>
6569
```c++
6670
template < typename T >
67-
using is_smart_ptr_soft = decltype( is_smart_ptr_soft_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) );
71+
using is_smart_ptr_soft = decltype( detail::is_smart_ptr_soft_impl( std::declval< detail::remove_cvr_t< T >* >() ) );
6872
```
6973
```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```.
7074

7175
* is_shared_ptr_soft<T>
7276
```c++
7377
template < typename T >
74-
using is_shared_ptr_soft = decltype( is_shared_ptr_soft_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) );
78+
using is_shared_ptr_soft = decltype( detail::is_shared_ptr_soft_impl( std::declval< detail::remove_cvr_t< T >* >() ) );
7579
```
7680
```is_shared_ptr_soft<T>::value```/```is_shared_ptr_soft_v<T>``` is ```true``` if ```T``` is derived from ```std::shared_ptr```.
7781

7882
* is_unique_ptr_soft<T>
7983
```c++
8084
template < typename T >
81-
using is_unique_ptr_soft = decltype( is_unique_ptr_soft_impl( std::declval< std::remove_cv_t< std::remove_reference_t< T > >* >() ) );
85+
using is_unique_ptr_soft = decltype( detail::is_unique_ptr_soft_impl( std::declval< detail::remove_cvr_t< T >* >() ) );
8286
```
8387
```is_unique_ptr_soft<T>::value```/```is_unique_ptr_soft_v<T>``` is ```true``` if ```T``` is derived from ```std::unique_ptr```.
8488

8589
# Example
86-
![Smart Pointer Type Trait1](https://user-images.githubusercontent.com/73771162/146930931-ff47a89d-86ab-402c-a558-fccd9670edc3.PNG)
87-
![Smart Pointer Type Trait2](https://user-images.githubusercontent.com/73771162/146931121-43c0be51-8a52-4f49-a87f-b00562bacd1f.PNG)
90+
![Smart Pointer Type Trait1](https://user-images.githubusercontent.com/73771162/147122310-58b2a730-2e5e-4f7f-a734-0f690dedfdea.PNG)
91+
![Smart Pointer Type Trait2](https://user-images.githubusercontent.com/73771162/147122315-176ae870-1687-4681-840e-a6493a2bb584.PNG)
92+
8893

94+
# Credit
95+
### **Woon2**
96+
97+
# Contributing
98+
we are welcoming your contributions!😊
99+
89100

90101
# Reference
102+
[How to write a type trait is container or is vector](https://stackoverflow.com/questions/12042824/how-to-write-a-type-trait-is-container-or-is-vector) - stackoverflow
103+
104+
[Concept for Smart Pointers](https://stackoverflow.com/questions/65752626/concept-for-smart-pointers) - stackoverflow
91105

92-
[Concept for Smart Pointers](https://stackoverflow.com/questions/65752626/concept-for-smart-pointers)
93-
94-
[씹어먹는 C++ - <16 - 3. 타입을 알려주는 키워드 decltype 와 친구 std::declval>](https://modoocode.com/294)
106+
[씹어먹는 C++ - <16 - 3. 타입을 알려주는 키워드 decltype 와 친구 std::declval>](https://modoocode.com/294) - blog
95107

96-
[std::conditional](https://en.cppreference.com/w/cpp/types/conditional)
108+
[std::conditional](https://en.cppreference.com/w/cpp/types/conditional) - cppreference
109+
110+
[SFINAE](https://en.cppreference.com/w/cpp/language/sfinae) - cppreference

0 commit comments

Comments
 (0)