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. iOS 网络与多线程--3.异步Get方式的网络请求(非阻塞)

    通过Get请求方式,异步获取网络数据,异步请求不会阻塞主线程(用户界面不会卡死),而会建立一个新的线程. 代码如下 ViewController.h文件 // // ViewController.h ...

  2. 武汉科技大学ACM:1004: Lake and Island

    Problem Description 北园孩子的专属福利来啦~学校从北区宿舍到湖心岛修建了一条通道让北园的同学们可以上去一(kuang)同(xiu)玩(en)耍(ai),这一天,IcY向ahm001 ...

  3. 武汉科技大学ACM :1004: 零起点学算法74——Palindromes _easy version

    Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”. Input 输入包含多 ...

  4. Java语言实现简单FTP软件------>FTP软件本地窗口的实现(五)

    1.首先看一下本地窗口的布局效果 2.看一下本地窗口实现的代码框架 2.本地窗口的具体实现代码LocalPanel.java package com.oyp.ftp.panel.local; impo ...

  5. intent.setFlags方法中参数值的含义

    intent.setFlags()方法中参数的含义 1.FLAG_ACTIVITY_NEW_TASK: 例如现在栈一的情况是:A    B   C(C位于栈顶),C通过intent跳转到D,并且这个I ...

  6. java中的hashcode方法作用以及内存泄漏问题

    本文装载:http://hi.baidu.com/iduany/item/6d66dfc9d5f2da1650505870 hashCode()方法的作用&使用分析 一直以来都想写篇文章来说明 ...

  7. Intellij idea 12和设置快捷键修改(加快项目的开发速度与养成良好习惯)

    1.为了养成良好的代码习惯idead中的javascript jSLint能显示不良的代码设置如下    2.Intellij idea 12每一次修改,保存生成都要按ctrl+shift+F9非常影 ...

  8. jquery读取后台代码

    前台代码: <script type="text/javascript"> $(function () {            $("#btn") ...

  9. Android之GPS应用开发

    LocationManager--------------->Context.LOCATION_SERVICE LocationProvider--------------->Locati ...

  10. CRegKey 注册表操作

    CRegKey 注册表操作 标签: accessnulluserpathbyteie 2011-11-03 13:55 3477人阅读 评论(0) 收藏 举报  分类: win32(7)  1.简介 ...