草庐IT

make_pair

全部标签

c++ - 模板函数的 'typedef' (boost::make_shared)

我正在将我的项目迁移到C++11,我正在尝试使用尽可能多的标准库。在完成迁移之前,我需要一种快速的方法来在shared_ptr的boost和STL实现之间切换(以进行基准测试、单元测试等)。所以我为shared_ptr定义了一个别名,如下所示:#ifdef_USE_BOOST_templateusingshared_ptr=boost::shared_ptr#elsetemplateusingshared_ptr=std::shared_ptr#endif现在我需要为make_shared做同样的事情...但是怎么做呢?宏观?wrapper?我真的不喜欢他们中的任何一个。有哪些替代方案

c++ - 为什么 boost::assign::list_of 不适用于 pair<string, vector<string>>?

我不明白为什么这不起作用(VisualC++2012):#include#include#include#includeusingnamespacestd;intmain(){pair>("^",boost::assign::list_of("rules"));}错误是:include\utility(138):errorC2668:'std::vector::vector':ambiguouscalltooverloadedfunctionwith[_Ty=std::string]include\vector(786):couldbe'std::vector::vector(std:

c++ - 如何在 `make uninstall` 期间从 QT5 中的 qmake 运行自定义命令?

我有一个QT项目,它在运行makeinstall时向系统安装服务。.pro文件的相关部分如下:init.path=/etc/init.d/init.files=myservicenameupdaterc.path=/etc/init.d/updaterc.extra=chmod755$$init.files;\update-rc.d$$init.filesdefaults9703;\service$$init.filesstartINSTALLS+=target...initupdaterc这会正确安装服务,然后启动它。但是,当我运行makeuninstall时,虽然安装的文件被正确删

c++ - 如何创建包含 std::atomic 的 std::pair?

我不知道如何创建以下内容:std::pair,int>我总是得到/usr/include/c++/5.5.0/bits/stl_pair.h:139:45:error:useofdeletedfunction'std::atomic::atomic(conststd::atomic&)':first(__x),second(std::forward(__y)){}我试过了std::pair,int>pair=std::make_pair(true,1);//doesn'tworkstd::pair,int>pair=std::make_pair({true},1);//doesn'tw

c++ - binary_search 与 std::pair 使用自定义运算符

我正在尝试进行binary_search,包括一个整数对vector和一个整数,如下所示:#include#includeusingnamespacestd;typedefvector>int_pairs;booloperator&r){returnr.first(1,2));pairs_vec.push_back(pair(2,2));size_ti(2);binary_search(pairs_vec.begin(),pairs_vec.end(),i);}编译器告诉我operator未定义:erreur:nomatchfor‘operator’)我的做法是否正确?我尝试以多种不同

c++ - make_signed<unsigned long>::type 是 int?

我使用的是VisualStudio2010,下面的代码让我有些困惑:#includeautox=std::make_signed::type();x将是int类型,但我预计会很长。我知道VS10中的int和long都是4字节整数。但是即使一个signedlong装进一个int,int对我来说也不是unsignedlong对应的signedinteger类型。所以我的问题是:这是错误/技术错误还是标准规范允许这种结果? 最佳答案 C++1120.9.7.3[meta.trans.sign]描述了make_signed:IfTnames

c++ - 不完整类型 struct std::hash 与 unordered_map 的无效使用,其中 std::pair of enum class 作为键

我想使用unordered_map,std::uint8_t>用于管理一些像素图格式。这里是最少的代码:#include#include#include#include#includeenumclassPNM:std::uint8_t{PBM,PGM,PPM};enumclassFormat:bool{BIN,ASCII};structpair_hash{public:templatestd::size_toperator()(conststd::pair&x)const{returnstd::hash()(x.first)^std::hash()(x.second);}};intma

c++ - 如何检测 make 依赖列表中的 header 更改

经过近十年的C#和VC++编码,我回到了linux–g++–make–emacs环境。试图刷新我关于编写make文件的内存我没有遇到太多问题,但我偶然发现了以下问题,我承认我不记得我过去是如何解决它的:假设一个特定的.cpp文件对其他几个头文件有一些依赖性(撇开它易于处理的相应头文件)......检测某些.h已更改的最佳方法是什么?我当然不喜欢将它们放在我的目标依赖列表中的想法,因为这是一个手动且容易出错的过程!简单的答案当然是只要有.h更改就构建干净,但我真的不记得标准方法是什么......。在VC++中,我不必处理这个问题,因为IDE非常擅长处理依赖关系......

c++ - Netbeans远程C++开发 "No rule to make target"错误

在Netbeans中创建一个简单的远程C++开发应用程序时,出现以下错误:gmake[2]:Enteringdirectory'/path/to/project'gmake[2]:***Noruletomaketarget'/path/to/project/cpp/file'gmake[2]:Leavingdirectory'/path/to/project'BUILDFAILED(exitvalue2,totaltime:1s)要重现此错误,我只需创建一个新的C/C++项目,选择一个我已经配置的远程主机。当我添加具有相应.h文件的.ccp文件时,出现此错误。我什至不必使用或包含这些文

c++ - 为什么 std::make_pair 按值而不是 const 引用获取输入?

引用本网站http://www.cplusplus.com/reference/std/utility/make_pair/std::make_pair具有此签名(和可能的实现):templatepairmake_pair(T1x,T2y){return(pair(x,y));}我想知道为什么std::make_pair的输入参数是按值而不是常量引用?这有什么特别的原因吗? 最佳答案 它最初是通过const引用获取参数,但这引入了一些意想不到的问题。缺陷报告后改为按值传递:http://www.open-std.org/jtc1/s