草庐IT

gnu-make

全部标签

c++ - 为什么不使用 `make_x()` 函数尽可能省略 move 构造函数?

我不知道为什么在最后一种情况下是在启用复制省略时调用move构造函数(甚至是强制性的,例如在C++17中):classX{public:X(inti){std::clogXmake_X(T&&arg){returnX(std::forward(arg));}intmain(){autox1=make_X(1);//1xconvertingctorinvokedautox2=X(X(1));//1xconvertingctorinvokedautox3=make_X(X(1));//1xconvertingand1xmovectorinvoked}在这种情况下,哪些规则会阻碍move构造

c++ - 为什么不使用 `make_x()` 函数尽可能省略 move 构造函数?

我不知道为什么在最后一种情况下是在启用复制省略时调用move构造函数(甚至是强制性的,例如在C++17中):classX{public:X(inti){std::clogXmake_X(T&&arg){returnX(std::forward(arg));}intmain(){autox1=make_X(1);//1xconvertingctorinvokedautox2=X(X(1));//1xconvertingctorinvokedautox3=make_X(X(1));//1xconvertingand1xmovectorinvoked}在这种情况下,哪些规则会阻碍move构造

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++ - _GNU_SOURCE 和 __USE_GNU

我想使用CPU_SET,这是一个glibclinux特定的宏,应该在sched.h中定义手册页明确指出_GNU_SOURCE必须定义以便定义宏。但是,查看标题,CPU_SET仅当__USE_GNU时才定义已定义(有#ifdef保护)。我好像记得几年前_GNU_SOURCE需要。问题:1)很明显,联机帮助页已关闭。如何通知维护人员手册页不正确?2)从_GNU_SOURCE转换的时间是什么时候?至__USE_GNU发生(根据版本或时间)3)是否存在新版本的glibc仍然使用_GNU_SOURCE的情况??或者我可以安全地假设定义__USE_GNU够了吗? 最佳答

c++ - _GNU_SOURCE 和 __USE_GNU

我想使用CPU_SET,这是一个glibclinux特定的宏,应该在sched.h中定义手册页明确指出_GNU_SOURCE必须定义以便定义宏。但是,查看标题,CPU_SET仅当__USE_GNU时才定义已定义(有#ifdef保护)。我好像记得几年前_GNU_SOURCE需要。问题:1)很明显,联机帮助页已关闭。如何通知维护人员手册页不正确?2)从_GNU_SOURCE转换的时间是什么时候?至__USE_GNU发生(根据版本或时间)3)是否存在新版本的glibc仍然使用_GNU_SOURCE的情况??或者我可以安全地假设定义__USE_GNU够了吗? 最佳答

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::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)