Standard Library Containers with additional optional template parameters?(具有附加可选模板参数的标准库容器?)
问题描述
多次阅读文章中的声明 - 我想将此问题添加到 Stackoverflow,并询问社区 - 以下代码是否可移植?
Having read the claim multiple times in articles - I want to add this question to Stackoverflow, and ask the community - is the following code portable?
template<template<typename T, typename Alloc> class C>
void f() {
/* some code goes here ... */
}
int main() {
f<std::vector>();
}
提供 std::vector
的实现是否真的允许有除了两个众所周知的模板参数之外的额外的、默认的模板参数?这会使上面的代码格式错误,因为它假定有两个模板参数.有关此类声明的示例,请参阅本文的最后一段.
Is the implementation that supplies std::vector
really allowed to have additional, defaulted template parameters beyond the two well known ones? This would render the above code ill-formed, as it assumes two template parameters. See the last paragraph in this article for an example of such a claim.
推荐答案
我发现了以下 问题报告,上面写着
I found the following issue report, which says
没有歧义;标准是明确的.不允许库实现者向标准库类添加模板参数.这不属于好像"规则,因此只有在标准为实施者提供明确许可的情况下才允许这样做.这需要改变标准.
There is no ambiguity; the standard is clear as written. Library implementors are not permitted to add template parameters to standard library classes. This does not fall under the "as if" rule, so it would be permitted only if the standard gave explicit license for implementors to do this. This would require a change in the standard.
LWG 决定不进行此更改,因为它会破坏涉及模板模板参数或标准库类模板专业化的用户代码.
The LWG decided against making this change, because it would break user code involving template template parameters or specializations of standard library class templates.
说一个实现可以添加其他可选参数的书籍和人似乎是错误的.
The books and people that say an implementation may add other optional parameters seem to be wrong.
这篇关于具有附加可选模板参数的标准库容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:具有附加可选模板参数的标准库容器?


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01