https://github.com/zhb2000/pointer-declaration
Declare all kinds of pointers with Ptr<...>
https://github.com/zhb2000/pointer-declaration
c-plus-plus cpp
Last synced: about 1 year ago
JSON representation
Declare all kinds of pointers with Ptr<...>
- Host: GitHub
- URL: https://github.com/zhb2000/pointer-declaration
- Owner: zhb2000
- License: mit
- Created: 2021-02-03T05:02:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-03T05:13:15.000Z (over 5 years ago)
- Last Synced: 2025-04-15T02:45:42.474Z (about 1 year ago)
- Topics: c-plus-plus, cpp
- Language: C++
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pointer Declaration
A header-only C++11 "library" providing an alias template `ptrdecl::Ptr` for pointer declarations.
## Features
- Use angle brackets instead of star symbols
- Declare all kinds of pointers with uniform syntax
- Clearer sematic, especially when it comes to multi-level pointers and pointers with cv-qualifiers
## How to use
```cpp
#include "ptrdecl.hpp"
using ptrdecl::Ptr;
```
### Pointers to objects
Declare pointers to objects with `Ptr`.
```cpp
// int *p1;
Ptr p1;
// void *p2;
Ptr p2;
// const int *p3;
// int const *p3;
Ptr p3;
// int *const p4 = nullptr;
const Ptr p4 = nullptr;
// const int *const p5 = nullptr;
// int const *const p5 = nullptr;
const Ptr p5 = nullptr;
// int *const *p6;
Ptr> p6;
//const int **const p7 = nullptr;
const Ptr> p7 = nullptr;
//int *const *const p8 = nullptr;
const Ptr> p8 = nullptr;
```
### Pointers to functions
Declare pointers to functions with `Ptr`.
```cpp
// int (*p1)(int, int);
Ptr p1;
// void (*p2)();
Ptr p2;
// int *(*p3)();
Ptr()> p3;
// int (*(*p4)())();
Ptr()> p4;
// int *(*callbacks[5])();
Ptr()> callbacks[5];
```
### Pointers to data members
Declare pointers to data members with `Ptr`.
```cpp
struct C { int m; };
// int C::*p = &C::m;
Ptr p = &C::m;
```
### Pointers to member functions
Declare pointers to member functions with `Ptr`.
```cpp
struct C
{
int f(int a) { return a + 1; }
};
// int (C::*p)(int) = &C::f;
Ptr p = &C::f;
```