{"id":13419030,"url":"https://github.com/dropbox/nn","last_synced_at":"2025-03-15T04:31:46.280Z","repository":{"id":34727447,"uuid":"38705253","full_name":"dropbox/nn","owner":"dropbox","description":"Non-nullable pointers for C++","archived":true,"fork":false,"pushed_at":"2017-06-23T23:32:33.000Z","size":17,"stargazers_count":316,"open_issues_count":0,"forks_count":28,"subscribers_count":34,"default_branch":"master","last_synced_at":"2024-12-17T01:03:36.816Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dropbox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-07T17:59:21.000Z","updated_at":"2024-08-08T11:59:37.000Z","dependencies_parsed_at":"2022-08-04T18:30:38.100Z","dependency_job_id":null,"html_url":"https://github.com/dropbox/nn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fnn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fnn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fnn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dropbox%2Fnn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dropbox","download_url":"https://codeload.github.com/dropbox/nn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243685506,"owners_count":20330980,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:10.366Z","updated_at":"2025-03-15T04:31:46.010Z","avatar_url":"https://github.com/dropbox.png","language":"C++","funding_links":[],"categories":["TODO scan for Android support in followings","C++"],"sub_categories":[],"readme":"# `nn`: Non-nullable pointers for C++\n\n`nn` is a type that helps you enforce at compile time the contract that a given pointer\ncan't be null. It wraps around raw pointers or smart pointers, and works particularly\nwell out of the box with `std::unique_ptr` and `std::shared_ptr`.\n\nHere's an example:\n\n```cpp\nclass Widget : public WidgetBase {\npublic:\n  Widget(nn_shared_ptr\u003cGadget\u003e gadget) : m_gadget(move(gadget)) {}\n  // ...\nprivate:\n  nn_shared_ptr\u003cGadget\u003e m_gadget;\n};\n\n// nn_make_unique and nn_make_shared always return non-null values\nnn_unique_ptr\u003cWidget\u003e my_widget = nn_make_unique\u003cWidget\u003e(nn_make_shared\u003cGadget\u003e());\n\n// but what if we have a pointer already and we don't know if it's null?\nshared_ptr\u003cGadget\u003e this_might_be_null = ...\nmy_widget = nn_make_unique\u003cWidget\u003e(NN_CHECK_ASSERT(this_might_be_null));\n\n// implicit nn_unique_ptr -\u003e nn_shared_ptr works just like unique_ptr -\u003e shared_ptr\nnn_shared_ptr\u003cWidget\u003e shared_widget = move(my_widget);\n\n// the `nn` implicitly casts away if needed\nvoid save_ownership_somewhere(shared_ptr\u003cWidget\u003e);\nsave_ownership_somewhere(shared_widget);\n\n// implicit upcasts work too\nnn_shared_ptr\u003cWidgetBase\u003e base_ptr = shared_widget;\n```\n\nCompile-time checking helps find bugs sooner. At Dropbox we use `nn` pervasively in our\ncross-platform C++ codebase.\n\n## Compatibility\n\nnn is C++11 compatible. Tested with GCC 4.8, clang 3.6+ and MSVS 2015.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropbox%2Fnn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdropbox%2Fnn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdropbox%2Fnn/lists"}