- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
1.1 KiB
1.1 KiB
SmartPtr::MakeUnique
template<typename T, typename... Args>
UniqueRef<T> MakeUnique(Args&&... args);
创建独占指针的工厂函数。
描述
MakeUnique 是创建 UniqueRef<T> 的工厂函数,使用完美转发将参数传递给 T 的构造函数。相比直接使用 std::make_unique,代码更简洁。
模板参数:
T- 被创建对象的类型Args- 构造函数的参数类型
参数:
args- 转发给 T 构造函数的参数
返回: UniqueRef<T> - 新创建的独占指针
复杂度: O(1)
示例:
#include <XCEngine/Core/SmartPtr.h>
class MyClass {
public:
MyClass(int value) : m_value(value) {}
int GetValue() const { return m_value; }
private:
int m_value;
};
// 创建独占指针
Core::UniqueRef<MyClass> unique = Core::MakeUnique<MyClass>(42);
printf("Value: %d\n", unique->GetValue());
// 转移所有权
Core::UniqueRef<MyClass> moved = Core::MakeUnique<MyClass>(100);
相关文档
- SmartPtr 总览 - 返回类总览
- UniqueRef - UniqueRef 类型说明