草庐IT

make_pair

全部标签

c++ - std::make_pair、c++11 和显式模板参数

这个问题在这里已经有了答案:C++11make_pairwithspecifiedtemplateparametersdoesn'tcompile(1个回答)关闭7年前。重新编辑:首先,这只是一个好奇的问题,我知道,std::pair或许多其他解决方案可以根除这个问题。你能告诉我,下面这个问题的背后究竟是什么吗?此代码是一个在c++03上运行但在c++11上失败的简单示例。std::pairgetsth(int*param){returnstd::make_pair(param,0);}intmain(intargc,char*argv[]){int*a=newint(1);std::

c++ - 如何在 Visual Studio 中解决 make_shared 的 10 个限制

在一些旧代码上使用C++10的新功能时,我遇到了无法调用带有12个参数的make_shared的问题。我记得Microsoft的STL谈到他们如何为make_shared使用仿真,并且10是最大值。显然仅仅为此重构代码是不可能的,所以基本上我的问题是-有没有办法在VS2010中为make_shared获取超过10个参数。 最佳答案 make_shared(1,2,3,4,5,6,7,8,9,10,11,12);可以替换为shared_ptr(newfoobar(1,2,3,4,5,6,7,8,9,10,11,12));在C++11中

c++ - make_pair 是在栈上还是堆上?

如果我从不同的范围将它插入到map中,是否需要分配一对?#include#include#include#includeusingnamespacestd;voidparseInput(intargc,char*argv[],unordered_map*inputs);intmain(intargc,char*argv[]){unordered_map*inputs=newunordered_map;parseInput(argc,argv,inputs);for(auto&it:*inputs){cout*inputs){inti;for(i=1;iinsert(make_pair(

c++ - Visual Studio 2010 中 std::make_shared() 的友元函数(不是 Boost)

如何创建std::make_shared()的友元函数。我试过:classMyClass{public:friendstd::shared_ptrstd::make_shared();//or//friendstd::shared_ptrstd::make_shared();protected:MyClass();};但它不起作用(我使用的是VisualStudio2010SP1) 最佳答案 如何向您的类添加一个静态方法:classFoo{public:staticshared_ptrcreate(){returnstd::shar

c++ - 特化 std::make_shared

我有一个具有严格对齐要求(由于使用了AVX操作)的类型,它大于平台默认对齐方式。为了简化此类的使用,我想专门化std::make_shared以始终为该类型使用合适的分配器。像这样:namespacestd{templateinlineautomake_shared(Args&&...args){returnstd::allocate_shared(allocator_type,std::forward(args)...);}}我的问题是,标准允许这样做吗?它会按预期工作吗? 最佳答案 来自N4140[namespace.std]/

c++ - 尝试将 std::pair 插入 std::set

我不明白这段代码中的错误是什么:#include#include#includeusingnamespacestd;classA{public:A(unsignedinta):_a(a){}A():_a(0){}unsignedinta()const{return_a;}private:unsignedint_a;};classB{public:B(unsignedintb):_b(b){}B():_b(0){}unsignedintb()const{return_b;}private:unsignedint_b;};voiddisplay(constPoint&point){//co

c++ - SPARC : How to handle integer doubleword pairs? 的 GCC 内联汇编

据我了解,在SPARC中,32位整数存储在单个寄存器中,64位整数存储在相邻的寄存器对中,偶数寄存器包含高32位,奇数寄存器包含低位32位。我需要编写一些专门的SPARC内联汇编宏(内联汇编函数也可以)来处理64位整数双字对,但我不知道如何进行通用引用(使用GCC扩展内联汇编)到我的内联汇编中这对的两半。虽然我的汇编宏比下面显示的MULTIPLY()宏稍微复杂一点,但乘法示例(如果有效)将演示如何处理64位双字对的两半。谁能告诉我如何修复我的MULTIPLY()宏?以防万一,我在...bash-2.03$uname-aSunOS[...]5.8Generic_117350-39sun4

c++ - 为什么不允许使用 `make_unique<T[N]>`?

假设命名空间std贯穿始终。C++14委员会草案N3690定义了std::make_unique因此:[n3690:20.9.1.4]:unique_ptrcreation   [unique.ptr.create]templateunique_ptrmake_unique(Args&&...args);1Remarks:ThisfunctionshallnotparticipateinoverloadresolutionunlessTisnotanarray.2Returns:unique_ptr(newT(std::forward(args)...)).templateunique

c++ - 为什么此生成文件适用于 make 3.81 而不是 3.82?

我有一个非常简单的makefile来构建一个静态库,多年来它在GNUmake版本3.81上运行良好,但在版本3.82上运行失败。我已经阅读了有关向后兼容性的问题,但这些问题似乎并不适用。我还检查了这里的几个帖子,例如MakefileSyntax:Staticlibrarylib$(library).a($objects)和Makefile-tocreateastaticlibrary,但找不到解决方案。这是我的生成文件:FILES=file1.ccfile2.ccfile3.ccOBJ_FILES=$(FILES:.cc=.o)libname.a:libname.a($(OBJ_FIL

c++ - 为什么宏 __STL_FUNCTION_TMPL_PARTIAL_ORDER 应该将模板函数包含在 std_pair.h 中

今天在STL_pair.h中看到如下代码:#ifdef__STL_FUNCTION_TMPL_PARTIAL_ORDERtemplateinlinebooloperator!=(constpair&__x,constpair&__y){return!(__x==__y);}templateinlinebooloperator>(constpair&__x,constpair&__y){return__y我不认为模板函数与偏特化有任何关联的功能模板。我错了吗? 最佳答案 编译器如何处理函数调用在C++中调用函数模板经历了名称查找(标准