10 ms·
Non-nullable pointers for C++
- wuch 11y agoUsing types to encode additional invariants is of course very useful, though those pointers does not enforce non-nullability. For example you can transfer ownership out of them more than once: void f(nn_unique_ptr<std::string> a, nn_unique_ptr<std::string> b) { // Null pointer dereference in one of following lines: std::cout << *a << std::endl; std::cout << *b << std::endl; } int main() { std::bind(f, _1, _1)(nn_make_unique<std::string>("Hello!")); }