https://github.com/soasis/out_ptr
Repository for a C++11 implementation of std::out_ptr (p1132), as a standalone library!
https://github.com/soasis/out_ptr
Last synced: about 1 year ago
JSON representation
Repository for a C++11 implementation of std::out_ptr (p1132), as a standalone library!
- Host: GitHub
- URL: https://github.com/soasis/out_ptr
- Owner: soasis
- License: apache-2.0
- Created: 2019-05-06T21:19:38.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-04-07T00:40:19.000Z (about 1 year ago)
- Last Synced: 2025-04-07T01:28:00.321Z (about 1 year ago)
- Language: C++
- Homepage: https://thephd.github.io/_vendor/future_cxx/papers/d1132.html
- Size: 1010 KB
- Stars: 75
- Watchers: 8
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ztd.out_ptr
`ztd.out_ptr` is a simple parameter wrapper for output pointers.
[](https://travis-ci.org/ThePhD/out_ptr)
[](https://ci.appveyor.com/project/ThePhD/out-ptr)
# Quick Comparison and Example
```cpp
// Before
std::unique_ptr ptr;
if (T* tmp_ptr; !c_api_get_obj(&tmp_ptr, ...)) {
throw std::runtime_error(...);
}
else {
ptr.reset(tmp_ptr);
}
use(ptr);
```
```cpp
// After
namespace zop = ztd::out_ptr;
std::unique_ptr ptr;
if (!c_api_get_obj(zop::inout_ptr(ptr), ...)) {
throw std::runtime_error(...);
}
use(ptr);
```
# Full Examples and Documentation
There are examples and documentation contained in this repository: please, peruse them as much as you need to! Some interesting/illuminating ones:
- It works with [custom unique pointers just fine](examples/source/std.custom_unique_ptr.cpp)
- It is [customizable to your own pointer types](examples/source/custom.handle.cpp), if you need performance or different semantics
- It works with [Boost](examples/source/boost.shared_ptr.cpp) and [Standard](examples/source/std.shared_ptr.cpp) shared pointers.
- It works with things like [unique_resource](https://github.com/okdshin/unique_resource) out of the box.
# Running Tests
Right now, can be run easily VIA CMake. To ease development, all necessary dependencies -- including other Boost dependencies -- are included as submodules. You can initialize and update all submodules by performing a successful `git submodule update --init --recursive` call.
From there, CMake is run. It requires that the parameters `ZTD_OUT_PTR_TESTS` is `ON`. Examples can also be run by specifying `ZTD_OUT_PTR_EXAMPLES` and `ZTD_OUT_PTR_TESTS` to be `ON` at the same time:
```bash
md out_ptr-build
cd out_ptr-build
cmake path/to/out_ptr/src -GNinja -DZTD_OUT_PTR_TESTS=ON -DZTD_OUT_PTR_EXAMPLES=ON
cmake --build .
ctest --output-on-failure
```
You can replace the `-G` argument with the generator of your choice. You may also add the `-DCMAKE_BUILD_TYPE=Debug|Release` to test certain build types. If you do, make sure to specify it on the build and test lines as well with `cmake --build . --config Debug|Release` and `ctest --output-on-failure --build-config=Debug|Release`.
# Running Benchmarks
Benchmarks can be run by running CMake with the option `-DZTD_OUT_PTR_BENCHMARKS` set to `ON`.