SaferCPlusPlus
A collection of safe data types that are compatible with, and can substitute for, common unsafe native c++ types
Install / Use
/learn @duneroadrunner/SaferCPlusPlusREADME
Feb 2025
Overview
"SaferCPlusPlus" is essentially a collection of safe data types intended to facilitate memory and data race safe C++ programming. This library is intended to work with a safety assuring static analyzer like scpptool and, optionally, the Core Guidelines lifetime checker, over their various stages of development and availability. (Including situations where they are not available at all.)
The library's elements are designed, as much as possible, to seamlessly integrate with all manner of existing and future C++ code. It includes things like:
-
Drop-in replacements for
std::vector<>,std::array<>andstd::string. -
Replacements for
std::string_viewandstd::span. -
Drop-in replacements for
int,size_tandboolthat ensure against the use of uninitialized values and address the "signed-unsigned mismatch" issues. -
Data types for safe sharing of objects among concurrently executing threads.
-
Replacements for native pointers/references with various flexibility and performance trade-offs.
While a "static safety analyzer/enforcer" like the scpptool would be required to ensure complete safety, the SaferCPlusPlus library elements have a lot of safety enforcement already built in. The library is extensive enough that most existing uses of unsafe C++ elements can be replaced.
Besides zero-overhead pointers that enforce some of the necessary restrictions that would be imposed by a complete "static safety analyzer/enforcer", the library provides a reference counting pointer that's smaller and faster than std::shared_ptr<>, and (non-owning) unrestricted pointers that ensure memory safety via run-time checks. The latter two being not (yet) provided by the Guidelines Support Library, but valuable in the context of having to work around the somewhat draconian restrictions imposed by the (eventual completed) lifetime checker.
To see the library in action, you can check out some benchmark code. There you can compare traditional C++ and (high-performance) SaferCPlusPlus implementations of the same algorithms. Also, the msetl_example.cpp and msetl_example2.cpp files contain usage examples of the library's elements. But at this point, there are a lot of them, so it might be more effective to peruse the documentation first, then search those files for the element(s) you're interested in. (An online interactive version of these examples is also available, but the whole collection is large enough that the build will likely time-out. Often, the documentation for individual library elements will include a link to a more specific interactive example that should build fine.)
Elements in this library are currently based on the C++17 version of their counterpart APIs. (C++14 is still supported.)
Supported platforms
Tested with the microsoft compiler (v.19.50.35718), g++13.3.0 and clang++18.1.3 (Ubuntu 24.04.1). Versions of g++ prior to version 5 are not supported. Apple clang++ is not currently a regular test target. With the microsoft compiler, compiling in "conformance" mode (/permissive-) (which is not the default when using C++17 or lower) is recommended.
Table of contents
-
Comparisons
- <details> <summary>Registered pointers</summary> </details>
- <details> <summary>Norad pointers</summary> </details>
- <details> <summary>Reference counting pointers</summary> </details>
- <details> <summary>Single owner pointer</summary> </details>
- <details> <summary>Scope pointers</summary> </details>
-
<details>
<summary>Multithreading</summary>
- Overview
- TAsyncPassableObj
- thread
- async()
- Asynchronously shared objects
- Scope threads
- access controlled objects
- xscope_thread_carrier
- xscope_future_carrier
- make_xscope_asyncsharedv2acoreadwrite()
- make_xscope_aco_locker_for_sharing()
- make_xscope_exclusive_strong_pointer_store_for_sharing()
- TXScopeExclusiveStrongPointerStoreForAccessControl
- exclusive writer objects
- scope atomics
- TXScopeACORASectionSplitter and TXScopeAsyncACORASectionSplitter
- static and global variables
- <details> <summary>Arrays</summary> </details>
- <details> <summary>Vectors</summary> </details>
-
<details>
<summary>Strings</summary>
- Overview
- mstd::string
- nii_string
- xscope_borrowing_fixed_nii_basic_string
- TStringSection
- [TNRPStringSection](#txscopenrpstringsection-txscopenrpstringconstsection-tnrpstringsect
Related Skills
node-connect
338.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.4kCommit, push, and open a PR
