Created
March 7, 2014 14:41
-
-
Save derrickturk/9412661 to your computer and use it in GitHub Desktop.
Sometimes (*cough* linking GNU new (nothrow) still brings in a bunch of exception-handling crap *cough*) you just need an easy malloc'd buffer with automatic lifetime management.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T> | |
using auto_buf = std::unique_ptr<T[], void(&)(void*) noexcept>; | |
template<class T> | |
auto_buf<T> make_auto_buf(std::size_t n) noexcept | |
{ | |
return auto_buf<T>(static_cast<T*>(std::malloc(n * sizeof(T))), std::free); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment