通常,我们可以使用动态分配的大括号初始化来创建一个数组
int* arr = new int[5]{1,1,2,4,5};
Run Code Online (Sandbox Code Playgroud)
但这可以使用智能指针,特别是使用 std::make_unique 吗?我尝试过以下方法:
unique_ptr<int[]> arr(5) {1,1,2,4,5};
unique_ptr<int[]> arr = make_unique<int[]>(5){1,1,2,4,5};
unique_ptr<int[]> arr = make_unique<int[]>({1,1,2,4,5});
Run Code Online (Sandbox Code Playgroud)
但没有用,而且我认为使用智能指针甚至不可能实现这一点。任何有关如何对智能指针使用大括号初始化的建议将不胜感激。
是的,我知道std::vector,但希望是否有其他方法。