c++11 : Local and Unnamed Types as Template Arguments
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的更多相关文章
- C++ Templates (1.4 默认模板实参 Default Template Arguments)
		
返回完整目录 目录 1.4 默认模板实参 Default Template Arguments 1.4 默认模板实参 Default Template Arguments 可以为模板参数定义默认值,这 ...
 - Std::map  too few template arguments
		
在上述的代码中,红色波浪线的部分编译的时候报错: error C2976: 'std::map' : too few template arguments 换成std::map<std::str ...
 - tornado学习笔记11 Web应用中模板(Template)使用应用实践
		
上一篇中(Web应用中模板的工作流程分析),已经分析了模板的渲染流程,以及相关参数获取及设置原理.这篇主要讲述模板在实际应用案例. 11.1 需求 根据用户输入的两次密码,判断两次密码是否一致,并将判 ...
 - (11)zabbix item types监控类型
		
1. 什么是item types item types是由zabbix提供的各种类型的检查器(这样翻译很奇怪),大致就是Zabbix agent, Simple checks, SNMP, Zabbi ...
 - C++学习三  模板类出错总结(Missing template arguments before 'L')
		
一.模板类的说明 模板类有一个好处是可以放宽你输入的数据类型. 比如有这样的一个函数: int add(int x, int y) { return x+y; } 这个函数对于int类型的x,y才适合 ...
 - C++11 能好怎?
		
0. 摘要 近期读了一些关于C++11标准的材料. 本篇博客将从新标准的优点.与旧版本的区别和使用方法三个角度,大致介绍我对C++11的认识. C++11标准,原名C++0x, 是03版旧标准的更新. ...
 - c++11介绍
		
C++11标准是 ISO/IEC 14882:2011 - Information technology -- Programming languages -- C++ 的简称[1] . C++11 ...
 - VS2010对C++11的支持列表(感觉大部分都不支持)
		
c++11,就是之前的c++0x,已经成为了最新的c++标准.像咱这样天天用c++的,就赶紧follow一下.学习成果,放在这里,不说分享,至少自己增强下记忆. 首先,给出一些有用的链接. http: ...
 - C++ Standards Support in GCC -  GCC 对 C++ 标准的支持
		
C++ Standards Support in GCC - 2019-2-20 GCC supports different dialects of C++, corresponding to th ...
 
随机推荐
- Android Studio中常用设置与快捷键
			
常用设置: 1.Tab不用4个空格Code Style->Java->Tabs and Indents->Use tab characterCode Style->Genera ...
 - Linux文件和目录操作管理命令
			
1.pwd:显示工作目录路径 -p:显示实际物理路径 -l:显示链接路径 2.cd:更改工作目录路径 cd:进入用户主目录 cd~:进入用户主目录 cd-:返回进入此目录之前所在的目录 cd..:返回 ...
 - awk命令简单学习
			
请执行命令取出linux中eth0的IP地址(请用cut,有能力者也可分别用awk,sed命令答). 解答: 说明:此题解答方法已经给大家讲解了不下15种,还可以有很多,在这里给大家着重讲下awk的技 ...
 - C程序第二章节:算法
			
1.主要讲了:算法,3种基本结构化的算法(顺序,选择,循环结构),N-S流程图表示算法,伪代码表示算法. 2.输入10个数,输出其中最大的一个数. #include <stdio.h>in ...
 - Java中的HashMap和Hashtable
			
代码: import java.util.*; public class test{ public static void main(String[] args) { HashMap hm = new ...
 - centos6.2下安装星际译王stardict3.0
			
星际译王是一个Linux下很好的翻译软件. 我的系统是centos6.2 32位版.本来在http://code.google.com/p/stardict-3/downloads/list 上下的源 ...
 - Python学习笔记七-错误和异常
			
程序员总是和各种错误打交道,学习如何识别并正确的处理程序错误是很有必要的. 7.1错误和异常 1.错误 从软件方面来看,错误分为语法错误和逻辑错误两种.这两种错误都将导致程序无法正常进行下去,当Pyt ...
 - 数据分页SQL语句的比较
			
建立表 CREATE TABLE [TestTable] ( , ) NOT NULL , ) COLLATE Chinese_PRC_CI_AS NULL , ) COLLATE Chinese_P ...
 - Android 之 AlertDialog 用户登录
			
1:activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/androi ...
 - HADOOP在处理HIVE时权限错误的解决办法
			
今天,小乔操作时发现问题: org.apache.hadoop.security.AccessControlException: Permission denied: user=root, acces ...