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

https://github.com/na-trium-144/nullp-checker

nullptr checker for c++ smart pointer
https://github.com/na-trium-144/nullp-checker

cpp11 null-check null-safety

Last synced: 12 months ago
JSON representation

nullptr checker for c++ smart pointer

Awesome Lists containing this project

README

          

# ぬるぽチェッカー

c++のスマートポインタ(や配列)を置き換え、nullptr(や範囲外)にアクセスしたときに変数名とともに例外を投げます

## usage
* STLの各種クラスをnpchkのクラスで置き換えて使います
* `std::shared_ptr` → `npchk::shared_ptr`
* `std::array` → `npchk::array`
* `std::vector` → `npchk::array`
* `std::deque` → `npchk::deque`
* エラーメッセージの表示のために変数名を登録する必要があります
* 変数の定義時に`NPCHK`マクロを使用すると自動で設定できます
* `NPCHK`マクロはnpchkのクラスがネストしていても(例えば`npchk::array,3>`とか)使えます
* 型のテンプレートに`,`を含む場合は型名全体を`( )`で囲う
* マクロ1つで変数8個まで同時に定義できます
* inlineは`inline NPCHK(...);`
* externは普通に宣言し定義時にのみ`NPCHK`を使う
```c++
// std::array var の代わりに
NPCHK((npchk::array), var);
```
* または`var.setName("var");`
* これもnpchkのクラスがネストしている場合は再帰的に設定されます

## example
```c++
#include "npchk.hpp"
#include
#include

struct Hoge {
int val;
Hoge(int val) : val(val) {}
};

NPCHK(npchk::shared_ptr, hoge1, hoge2);

int main() {
hoge1 = std::make_shared(3);
std::cout << hoge1->val << std::endl;
std::cout << hoge2->val << std::endl;
}
```

```
3
terminate called after throwing an instance of 'std::runtime_error'
what(): hoge2 is nullptr
中止 (コアダンプ)
```