In N2402, Anthony Williams proposes that local types, and unnamed types be usable as template arguments. At the February 2008 (Bellevue) meeting, the Core working group supported the use of local types but was concerned about unnamed types. In addition, the WG did not support the mechanism used to accomplish this change in N2402.

I discussed the unnamed type issue with Anthony Williams and others. Use of unnamed types as template arguments was considered a useful facility and does not seem to present any particular implementation issues. In particular, it is fairly common practice to use unnamed enumerations in header files. Consequently, unnamed types have been retained in this proposal. Note that a namespace scope unnamed enumeration in one translation unit is distinct from one in another translation unit. So in the example below, x and y are initalized by two different instances of f

file1.c: template <class T> int f(T t); enum {e1}; int x = f(e1); file2.c: template <class T> int f(T t); enum {e1}; int y = f(e1);

N2402 makes local types and unnamed types usable as template arguments by giving them linkage. As mentioned above, the Core Working Group did not favor this solution. This document provides drafting to allow local and unnamed types to be used as template arguments by revising the rules for template arguments to permit such types.

Working Paper Changes

Change 3.5 [basic.link] paragraph 8 as follows:

A type without linkage shall not be used as the type of a variable or function with linkage, unless

  • the variable or function has extern "C" linkage., or
  • the type without linkage was named using a dependent type (14.6.2.1).

Delete the following sentence from 3.5 [basic.link] paragraph 8:

This implies that names with no linkage cannot be used as template arguments (14.3).

Add the following example after paragraph 8:

[ Example: template <class T> struct A { // in A<X>, the following is allowed because the type with no linkage // X is named using template parameter T. friend void f(A, T){} }; template <class T> void g(T t) { A<T> at; f(at, t); } int main() { class X {} x; g(x); } -- end example]

In 14.3.1 [temp.arg.type] paragraph 2 remove the following text:

A type without linkage (3.5) shall not be used as a template argument for a template type parameter.

Replace the example in paragraph 2 with the following:

[ Example: template <class T> class X { }; template <class T> void f(T t) { } struct {} unnamed_obj; void f() { struct A { }; enum { e1 }; typedef struct {} B; B b; X<A> x1; // OK X<A*> x2; // OK X<B> x3; // OK f(e1); // OK f(unnamed_obj); // OK f(b); // OK } -- end example]

End of document.

c++11 : Local and Unnamed Types as Template Arguments的更多相关文章

  1. C++ Templates (1.4 默认模板实参 Default Template Arguments)

    返回完整目录 目录 1.4 默认模板实参 Default Template Arguments 1.4 默认模板实参 Default Template Arguments 可以为模板参数定义默认值,这 ...

  2. Std::map too few template arguments

    在上述的代码中,红色波浪线的部分编译的时候报错: error C2976: 'std::map' : too few template arguments 换成std::map<std::str ...

  3. tornado学习笔记11 Web应用中模板(Template)使用应用实践

    上一篇中(Web应用中模板的工作流程分析),已经分析了模板的渲染流程,以及相关参数获取及设置原理.这篇主要讲述模板在实际应用案例. 11.1 需求 根据用户输入的两次密码,判断两次密码是否一致,并将判 ...

  4. (11)zabbix item types监控类型

    1. 什么是item types item types是由zabbix提供的各种类型的检查器(这样翻译很奇怪),大致就是Zabbix agent, Simple checks, SNMP, Zabbi ...

  5. C++学习三 模板类出错总结(Missing template arguments before 'L')

    一.模板类的说明 模板类有一个好处是可以放宽你输入的数据类型. 比如有这样的一个函数: int add(int x, int y) { return x+y; } 这个函数对于int类型的x,y才适合 ...

  6. C++11 能好怎?

    0. 摘要 近期读了一些关于C++11标准的材料. 本篇博客将从新标准的优点.与旧版本的区别和使用方法三个角度,大致介绍我对C++11的认识. C++11标准,原名C++0x, 是03版旧标准的更新. ...

  7. c++11介绍

    C++11标准是 ISO/IEC 14882:2011 - Information technology -- Programming languages -- C++ 的简称[1]  . C++11 ...

  8. VS2010对C++11的支持列表(感觉大部分都不支持)

    c++11,就是之前的c++0x,已经成为了最新的c++标准.像咱这样天天用c++的,就赶紧follow一下.学习成果,放在这里,不说分享,至少自己增强下记忆. 首先,给出一些有用的链接. http: ...

  9. C++ Standards Support in GCC - GCC 对 C++ 标准的支持

    C++ Standards Support in GCC - 2019-2-20 GCC supports different dialects of C++, corresponding to th ...

随机推荐

  1. Wcf序列化的循环引用问题1

    1.Wcf数据契约序列化,使用的类DataContractSerializer 默认如果类不指定[DataContract],则序列化类的所有字段,并且在出现循环引用的时候回抛出异常,服务终止 msd ...

  2. (转,感谢原作者!)既然选择了Linux,有何必在乎这些——Linux wine国服LOL英雄联盟,完美运行!!

    Linux下玩国服LOL,国服哦.网络上随处都可以搜到wine美服LOL的教程,但腾讯运营的国服客户端跟美服原版相差比较大,按照美服的方式不能搞起国服LOL,由于宿舍文化,这几天我专注于wine一个国 ...

  3. XML DOM 总结一

        对这个基本概念我不介绍太多,无非就是一定格式的文本而已,我现在侧重于如何使用它.      首先看看.NET对它的支持.      首先看看这个类图:            所有的都是基于Xm ...

  4. pragram once

    #pragma once   [1]#pragma once这个宏有什么作用? 为了避免同一个文件被include多次,C/C++中有两种宏实现方式:一种是#ifndef方式,一种是#pragma o ...

  5. C#实现MySQL数据库中的blob数据存储

    在MySQL数据库中,有一种blob数据类型,用来存储文件.C#编程语言操作MySQL数据库需要使用MySQL官方组件MySQL.Data.dll. Mysql.Data.dll(6.9.6)组件下载 ...

  6. JS浏览器关闭时清空cookie

    function addCookie(objName,objValue,objHours){    var str = objName + "=" + escape(objValu ...

  7. 初始化JQuery方法与(function(){})(para)匿名方法介绍

    一.初始化JQuery对象 DOM加载完成时运行代码 1.$(document).ready(function(){ 全写 // 在这里写你的代码... }); 2.jQuery(function() ...

  8. DedeCMS标签 PHP判断语句写法

    缩略图标签的判断写法,如果有图片就显示,没图片就显示别的. {dede:field name=litpic runphp='yes'} if(!empty(@me)) { @me="< ...

  9. Windows坐标系

    .逻辑坐标 逻辑坐标是独立于设备的,它与设备点的大小无关.使用逻辑单位,是实现"所见即所得"的基础.当程序员在调用一个画线的GDI函数LineTo,画出25.4mm(1英寸) 长的 ...

  10. MVC中修改报错

    修改的时候有空值传入.