草庐IT

make_pair

全部标签

c++ - Qt 需要 C++11 支持"make error

我尝试按照README.md中的说明从源代码编译最新的平铺。我的工作环境:平铺源代码:tiled-0.16.1Mac操作系统:10.11.1Xcode:7.1Q制作:3.0Qt:5.7.0苹果LLVM:7.0.0但是make失败并出现以下错误:Infileincludedfrompythonplugin.cpp:21:Infileincludedfrom./pythonplugin.h:30:Infileincludedfrom../../libtiled/logginginterface.h:33:Infileincludedfrom../../libtiled/tiled_glob

c++ - std::tuple 和 std::pair 是否支持聚合初始化?

Aggregateinitialization除其他事项外,还需要没有用户提供的构造函数。但是std::tuple和std::pair对有一大组overloadedconstructors.从核心语言的角度来看,这些构造函数是用户提供还是用户声明?使用C++17可以编写(更新/说明:其中nocopy是不能复制或移动的类,例如std::mutex)autoget_ensured_rvo_str(){returnstd::pair(std::string(),nocopy());}编辑:不,这是不可能的,如答案链接和下面的答案中所述。这需要聚合初始化(对于上下文:Multipleretur

c++ - std::make_unique(以及 emplace、emplace_back)对 initializer_list 参数的笨拙推导

假设我有这个结构:structposition{intx,y;};和另一个将this作为构造函数参数的类:classpositioned{public:positioned(positionp):pos(p){}private:positionpos;};我怎样才能得到简单的autobla=std::make_unique({1,2});上类?目前,编译器试图通过initializer_list匹配并调用make_unique的数组变体,这很愚蠢,因为positioned只有一个构造函数。emplace出现同样的问题和emplace_back功能。几乎所有将其可变模板参数转发给类的构造

c++ - 使用 make_shared 和 make_unique 时需要检查 nullptr 吗?

如果我使用make_shared或make_unique创建指针,我是否必须检查它是否为nullptr,例如:std::unique_ptrp=std::make_unique();if(p==nullptr){........}如果您真的内存不足,std::make_unique将通过预期。所以你永远不会从std::make_unique得到空指针。这是正确的吗?所以在执行make_shared和make_unique时不需要检查nullptr吗? 最佳答案 来自std::make_unique上的cppreference(类似于

c++ - 更改时 Make 不会重建 header

我有一个项目,我定期修改header,当我这样做时,忘记了makeclean然后make,我得到了各种奇怪的行为。我目前正在使用QtCreator作为我的IDE,但我已经在独立于Qt的项目中看到过这种情况。我的项目变得相当大,每次更改header时都必须重建,这变得效率低下。有什么想法吗?供将来引用:如果使用QMake系统:DEPENDPATH+=.\HeaderLocation1/\HeaderLocation2/\HeaderLocation2/HeaderSubLocation1/\HeaderLocation2/HeaderSubLocation2/\HeaderLocatio

c++ - 它是非标准的 std::pair 实现、编译器错误还是非标准代码?

以下代码在VS2005和gcc-4.3.4上编译.#include#includetemplatestructX{};typedefstd::pairPr;Xvar;intmain(){std::cout但是它在VS2010上编译失败并出现错误消息:1>d:\a\testvs10\testvs10.cpp(13):errorC2440:'specialization':cannotconvertfrom'intstd::_Pair_base::*'to'intstd::pair::*'1>with1>[1>_Ty1=int,1>_Ty2=int1>]1>Standardconversi

c++ - 使用 MinGW 时 NetBeans Make 命令

我正在尝试使用NetBean来编写C++程序,我已经遵循了每个在这里找到的命令:https://netbeans.org/community/releases/68/cpp-setup-instructions.html#compilers_windows但是,我在使用netbeans中的make命令选项时遇到了问题。我已经将基本目录设置为M:\c++\bin,我在其中安装了MinGW,并将make命令设置为M:\MinSYS\bin\make.exe,但是在尝试构建一个简单程序时,netbeans会生成以下错误:"/M/c++/MinSYS/bin/make.exe"-fnbproj

c++ - 是否可以强制 `std::make_shared` 使用类的新运算符?

是否可以强制std::make_shared使用类的new运算符?这涉及另一个SOquestion.根据那个问题,std::make_shared使用自定义分配器:Fromthestandard(§20.7.2.2.6shared_ptrcreation):Effects:AllocatesmemorysuitableforanobjectoftypeTandconstructsanobjectinthatmemoryviatheplacementnewexpression::new(pv)T(std::forward(args)...).因此,我认为我可以使用自定义放置新运算符,但这

c++ - 带有大括号初始化的 make_unique

https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique写道std::make_unique可以实现为templatestd::unique_ptrmake_unique(Args&&...args){returnstd::unique_ptr(newT(std::forward(args)...));}这不适用于没有构造函数的普通结构。这些可以用大括号初始化,但没有非默认构造函数。示例:#includestructpoint{intx,z;};intmain(){std::make_unique(1,2);}Com

c++ - std::pair 的通用 lambda 参数

我想看看这在C++14通用lambda中是否可行,但我找不到正确的方式来表达它(或者可能是不可能的)。简化的例子是:autoconfirmOperation=[](autopr){assert(pr.second);};这个想法是,如果你向它传递一个std::pair,其中second是一个bool(例如从emplace函数),可以看这个bool。如果这是一个模板参数,我可以显式地显示pair以及pair的类型,但我认为这对lambda来说不可能吗?因此,我将整个参数标记为通用的,因此编译器似乎无法推断出我正在向它传递map的emplace()的返回值。有什么办法吗?