标准库具有附加可选模板参数的容器? [英] Standard Library Containers with additional optional template parameters?

查看:103
本文介绍了标准库具有附加可选模板参数的容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文章中多次阅读声明 - 我想将此问题添加到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>();
}


$ b

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.

推荐答案

我发现了以下问题报告,表示


没有歧义;标准是明确的书面。库实现者不允许向标准库类添加模板参数。这不属于似乎规则,因此只有当标准给予执行者这样做的明确许可时才允许。这需要更改标准。

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆