An open API service indexing awesome lists of open source software.

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

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;
```