草庐IT

make_binary_op

全部标签

c++ - 你能分配一个与 make_shared 等效的数组吗?

buffer=newchar[64];buffer=std::make_shared(char[64]);???你能用make_shared()为数组分配内存吗??我可以:buffer=std::make_shared(newchar[64]);但这仍然涉及调用new,据我了解make_shared更安全、更高效。 最佳答案 您需要共享分配的内存吗?您可以改用std::unique_ptr和std::make_unique在C++14上可用:autobuffer=std::make_unique(64);会有一个std::make_

c++ - 你能分配一个与 make_shared 等效的数组吗?

buffer=newchar[64];buffer=std::make_shared(char[64]);???你能用make_shared()为数组分配内存吗??我可以:buffer=std::make_shared(newchar[64]);但这仍然涉及调用new,据我了解make_shared更安全、更高效。 最佳答案 您需要共享分配的内存吗?您可以改用std::unique_ptr和std::make_unique在C++14上可用:autobuffer=std::make_unique(64);会有一个std::make_

c++ - Valgrind 在 std::make_unique 中显示内存泄漏

我正在使用Valgrind检查内存泄漏。不幸的是,我收到了Leak_DefinitelyLost警告。附件是我的代码的简化版本,它重现了错误:#include#include#include#includeusingnamespacestd;classBase{public:explicitBase(doublea){a_=a;}virtualvoidfun()=0;protected:doublea_;};classDerived_A:publicBase{public:Derived_A(doublea,vectorb,vectorc):Base(a),b_{b},c_{c}{}v

c++ - Valgrind 在 std::make_unique 中显示内存泄漏

我正在使用Valgrind检查内存泄漏。不幸的是,我收到了Leak_DefinitelyLost警告。附件是我的代码的简化版本,它重现了错误:#include#include#include#includeusingnamespacestd;classBase{public:explicitBase(doublea){a_=a;}virtualvoidfun()=0;protected:doublea_;};classDerived_A:publicBase{public:Derived_A(doublea,vectorb,vectorc):Base(a),b_{b},c_{c}{}v

c++ - 修改 std::string::op[] 的结果是否合法?

考虑C++11中的以下内容:[C++11:21.4.5]:basic_stringelementaccess             [string.access]const_referenceoperator[](size_typepos)const;referenceoperator[](size_typepos);1  Requires:pos.2  Returns:*(begin()+pos)ifpos,otherwiseareferencetoanobjectoftypeTwithvaluecharT();thereferencedvalueshallnotbemodifie

c++ - 修改 std::string::op[] 的结果是否合法?

考虑C++11中的以下内容:[C++11:21.4.5]:basic_stringelementaccess             [string.access]const_referenceoperator[](size_typepos)const;referenceoperator[](size_typepos);1  Requires:pos.2  Returns:*(begin()+pos)ifpos,otherwiseareferencetoanobjectoftypeTwithvaluecharT();thereferencedvalueshallnotbemodifie

c++ - `std::make_tuple` 的原因是什么?

我的意思是为什么std::make_tuple存在?我知道在某些情况下,该函数会减少您必须输入的字符数量,因为您可以避免使用模板参数。但这是唯一的原因吗?是什么让std::tuple函数存在而其他类模板没有这样的函数?仅仅是因为在这种情况下您可能会更频繁地使用std::tuple吗?以下是std::make_tuple减少字符数量的两个示例://Avoidingtemplateparametersindefinitionofvariable.//Considerthattemplateparameterscanbeverylongsometimes.std::tuplet(0,0.0)

c++ - `std::make_tuple` 的原因是什么?

我的意思是为什么std::make_tuple存在?我知道在某些情况下,该函数会减少您必须输入的字符数量,因为您可以避免使用模板参数。但这是唯一的原因吗?是什么让std::tuple函数存在而其他类模板没有这样的函数?仅仅是因为在这种情况下您可能会更频繁地使用std::tuple吗?以下是std::make_tuple减少字符数量的两个示例://Avoidingtemplateparametersindefinitionofvariable.//Considerthattemplateparameterscanbeverylongsometimes.std::tuplet(0,0.0)

C++:value_type 与 make_pair,哪个更快用于 map 插入?

typedefmapKVMap;KVMapkvmap;kvmap.insert(KVMap::value_type(key,val));kvmap.insert(make_pair(key,val));以上哪个选项插入到STL映射总是更快?为什么?注意:我很清楚insert()比使用[]=向map添加(而不是更新)键值对更快。请假设我的查询是关于添加,而不是更新。因此我将其限制为insert(). 最佳答案 第一个可能是'epsilon-faster',因为这个(从标准中的23.3.1开始):typedefpairvalue_typ

C++:value_type 与 make_pair,哪个更快用于 map 插入?

typedefmapKVMap;KVMapkvmap;kvmap.insert(KVMap::value_type(key,val));kvmap.insert(make_pair(key,val));以上哪个选项插入到STL映射总是更快?为什么?注意:我很清楚insert()比使用[]=向map添加(而不是更新)键值对更快。请假设我的查询是关于添加,而不是更新。因此我将其限制为insert(). 最佳答案 第一个可能是'epsilon-faster',因为这个(从标准中的23.3.1开始):typedefpairvalue_typ