gpt4 book ai didi

c++ - std::make_unique(size) 值初始化

转载 作者:可可西里 更新时间:2023-11-01 18:29:11 24 4
gpt4 key购买 nike

std::make_unique<double[]>(1000)

总是值初始化元素?好吧,我研究了实现,clang 以及 g++ 都在使用

new T[size]()

进行值初始化。

但我找不到符合 C++14/17 标准的实现必须这样做。

最佳答案

如果标准库符合 C++14,那么是的,它必须这样做(使用 new T[size] )。来自 C++14 §20.8.1.4[unique.ptr.create]/4:

template <class T> unique_ptr<T> make_unique(size_t n);

  • Returns: unique_ptr<T>(new remove_extent_t<T>[n]()).

关于c++ - std::make_unique<T[]>(size) 值初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39290088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com