Questions tagged «list-initialization»



1
我可以通过元素的完美转发来列表初始化std :: vector吗?
我注意到std :: vector的聚合 列表初始化在以下情况下执行复制初始化移动更适用。同时,多个emplace_backs可以满足我的需求。 我只能提出编写模板函数的不完善解决方案init_emplace_vector。但是,它仅对非显式单值构造函数最佳。 template <typename T, typename... Args> std::vector<T> init_emplace_vector(Args&&... args) { std::vector<T> vec; vec.reserve(sizeof...(Args)); // by suggestion from user: eerorika (vec.emplace_back(std::forward<Args>(args)), ...); // C++17 return vec; } 题 我真的需要使用emplace_back来尽可能高效地初始化std :: vector吗? // an integer passed to large is actually the size of the resource std::vector<large> v_init { …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.