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.
这篇关于具有附加可选模板参数的标准库容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:具有附加可选模板参数的标准库容器?


基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01