HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
hf::utils Namespace Reference

Functions

template<typename T , typename... Args>
std::unique_ptr< T > make_unique_nothrow (Args &&... args)
 Creates a unique_ptr using nothrow new for exception-free design.
 
template<typename T >
std::unique_ptr< T[]> make_unique_array_nothrow (size_t size)
 Creates a unique_ptr for arrays using nothrow new.
 

Function Documentation

◆ make_unique_array_nothrow()

template<typename T >
std::unique_ptr< T[]> hf::utils::make_unique_array_nothrow ( size_t size)

Creates a unique_ptr for arrays using nothrow new.

Specialized version for creating arrays with nothrow allocation.

Template Parameters
TThe array element type
Parameters
sizeNumber of elements to allocate
Returns
std::unique_ptr<T[]> Valid pointer on success, nullptr on allocation failure
Array Allocation Example:
if (!arr) {
// Handle allocation failure
return false;
}
// Use arr safely
std::unique_ptr< T[]> make_unique_array_nothrow(size_t size)
Creates a unique_ptr for arrays using nothrow new.
Definition memory_utils.h:67

◆ make_unique_nothrow()

template<typename T , typename... Args>
std::unique_ptr< T > hf::utils::make_unique_nothrow ( Args &&... args)

Creates a unique_ptr using nothrow new for exception-free design.

This function template provides a safe alternative to std::make_unique for environments that require no-exception guarantees. It uses nothrow new to allocate memory and returns nullptr on allocation failure instead of throwing std::bad_alloc.

Template Parameters
TThe type to create
ArgsParameter pack for constructor arguments
Parameters
argsArguments to forward to T's constructor
Returns
std::unique_ptr<T> Valid pointer on success, nullptr on allocation failure
if (!ptr) {
// Handle allocation failure
return false;
}
// Use ptr safely