(这是C++系列随笔的第二篇,这一系列是我练习C++而查的资料)

extracted from C++ Primer 5th. edition pp. 425


Using a Comparison for the Key Type

The type of the operation that a container uses to organize its elements is part of the type of that container. To specify our own operation, we must supply the type of that operation when we define the type of an associative container (including prioroty_queue). The operation type is specified following the element type inside the angle brackets that we use to say which type of container we are defining. (We are actually required to define a parameter type not to pass an argument.)

Each type inside the angle brackets is just that, a type (please pay attention to this sentence). We supply a particular comparison operation (more generally, a callable object: a pointer to function or a function object) of the specified type (that must have the same type as specified inside the angle brackets, and conversely we msut specify the type inside the angle brackets the same type as the constructor argument we are going to and allowed to supply (from outside? sounds subtle...)) when we create a container.

(C++ Primer, 5th. Ed. pp. 249)


Related Topic:

Function Pointer Parameters

Just as with arrays, we cannot define parameters of function type but can have a parameter that is a pointer to function. As with arrays, we can write a parameter that looks like a function type (when declaring or defining a function), but it will be treated as a pointer:

//third parameter is a function type and is automatically treated as a pointer to function
void useBIgger(const string &s1, const string &s2, bool pf(const string &, const string &));
//equivalent declaration: explicitly define the parameter as a pointer to function
void useBIgger(const string &s1, const string &s2, bool (*pf)(const string &, const string &));

However we cannot do so when defining the type of an associative container (a parameter that looks like a functoin type will not be treated as a pointer, and thus illegal):

//error
priority_queue<P, vector<P>, bool (const P&, const P&)> que(cmp);
//OK
priority_queue<P, vector<P>, bool (*) (const P&, const P&)> que(cmp);
//a simplified declaration using decltype
priority_queue<P, vector<P>, decltype(cmp)*> que(cmp);

转载于:https://www.cnblogs.com/Patt/p/4831021.html

Using a Comparison Function for the Key Type相关推荐

  1. Git error: Unable to negotiate with X.X.X.X : no matching host key type found . their offer: ssh-dss

    2019独角兽企业重金招聘Python工程师标准>>> I am trying to create a git repository on my web host and clone ...

  2. Unable to negotiate with xx.xx port xx: no matching host key type found. Their offer: ssh-rsa....

    背景 下载安装了官网最新的Git: 安装没问题,配置了name和email: 同时也配置了ssh秘钥到代码仓库: 使用git bash命令或者从idea中clone代码,报错如下: Unable to ...

  3. no matching host key type found. Their offer: ssh-rsa 问题解决

    最近升级了Mac OS Ventura 13.0.1后发现ssh指定密钥登录服务器失败. no matching host key type found. Their offer: ssh-rsa 进 ...

  4. Unable to negotiate with XXXX port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss

    问题描述 代码仓库已经添加了ssh公钥之后,克隆代码到本地时就报了这个问题 执行命令 git clone git@xxxxxxxxxxxxx.git 不能正常clone代码,报错信息如下: Unabl ...

  5. macOS Ventura no matching host key type found. Their offer: ssh-rsa

    macOS Ventura 正式退出后,我勇敢的吃了螃蟹. 在提交代码的时候遇见了no matching host key type found. Their offer: ssh-rsa  的错误, ...

  6. scp或者ssh报错“no matching host key type found. Their offer: ssh-rsa,ssh-dss“

    scp或者ssh报错"no matching host key type found. Their offer: ssh-rsa,ssh-dss" 原因:OpenSSH 7.0以后 ...

  7. win git 报错 no matching host key type found. Their offer: ssh-rsa

    问题描述 zeqiwk@ZEQIWK-PC MINGW64 ~/Desktop $ ssh -T -p 10022 gogs@git.e-nci.com Unable to negotiate wit ...

  8. git clone no matching host key type found. Their offer: ssh-rsa,ssh-dss... 报错

    Unable to negotiate with 主机地址 port 端口号: no matching host key type found. Their offer: ssh-rsa,ssh-ds ...

  9. ssh no matching host key type found. Their offer: ssh-rsa

    前两天升级macOS 13 Ventura后链接公司堡垒机出现一下问题 ➜ ~ ssh -p 222 ****@**** Unable to negotiate with *** port 222: ...

最新文章

  1. 【物理方程】物理学中最难的方程之一,你知道多少?
  2. ue4小白人骨骼定义_UE4角色骨架创建流程_资源库
  3. linux下将只读文件改为可读可写
  4. InnoDB 引擎独立表空间 innodb_file_per_table
  5. 字符数组和字符串的小细节
  6. PHP mongodb运用,MongoDB在PHP下的应用学习笔记
  7. python之禅源代码_python之禅
  8. matlab查表svpwm,SVPWM的查表生成方式代码
  9. 升级opengl和显卡驱动_又更新了!英伟达OpenGL 4.4显卡驱动下载
  10. android 小米盒子开发,接小米盒子Android SDK
  11. 阿里云网站域名备案流程全过程(图文讲解)
  12. 台式计算机怎么开声音,台式机如何设置声音
  13. vsd格式文件用什么打开? .vsd
  14. EndNote使用教程
  15. 频点、带宽、FFT点数、采样率的关系
  16. 每天3个面试题精研 - 前端 - 第4-6天
  17. 关于对vue-particle-effect-button的使用
  18. android 弹簧震动动画,Android-Rebound(弹簧系统-让动画不再僵硬)的简单使用与源码分析...
  19. 计算机一级msoffice考试操作题教程,计算机一级《MS Office》上机操作练习题
  20. Proteus仿真51开发板

热门文章

  1. mysql 连接 110 超时_Nginx和mysql上行超时超时(110:连接超时)
  2. 【maven】scalac:error while loading <root>,Error accessing
  3. 【Antlr】Antler 解析 没有进入 visit 相关方法中 一个愚蠢的问题
  4. 60-10-050-命令-kafka-broker-api-versions.sh
  5. 【MySQL】MySQL常见的读写分离方法
  6. 【Docker】Mac下Docker启动Kubernetes
  7. 【Antlr】unknown attribute text for rule stat in $stat.text
  8. SpringBoot基础篇日志管理之默认配置
  9. scala学习-11-package object
  10. k8s 和 Docker 到底是什么关系?