具有附加可选模板参数的标准库容器?

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.

这篇关于具有附加可选模板参数的标准库容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do compilers treat variable length arrays(编译器如何处理变长数组)
Deduce template argument from std::function call signature(从 std::function 调用签名推导出模板参数)
check if member exists using enable_if(使用 enable_if 检查成员是否存在)
Uses of a C++ Arithmetic Promotion Header(C++ 算术提升标头的使用)
Parameter pack must be at the end of the parameter list... When and why?(参数包必须位于参数列表的末尾...何时以及为什么?)
quot;not declared in this scopequot; error with templates and inheritance(“未在此范围内声明模板和继承错误)