博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++11 : Local and Unnamed Types as Template Arguments
阅读量:5299 次
发布时间:2019-06-14

本文共 2703 字,大约阅读时间需要 9 分钟。

 

 

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.

转载于:https://www.cnblogs.com/lvdongjie/p/4489922.html

你可能感兴趣的文章
display:inline-block下的IE元素
查看>>
JS中innerHTML,innerText,value
查看>>
Net设计模式实例之桥接模式( Bridge Pattern)
查看>>
PHP-redis中文文档
查看>>
【NOIP 模拟赛】改造二叉树 最长上升子序列
查看>>
C++中的volatile关键字
查看>>
一,数字类型
查看>>
[Knowledge-based AI] {ud409} Lesson 2: 02 - Introduction to CS7637
查看>>
李祥林:从美国经验看中国资产证券化的发展
查看>>
Java中Runnable和Thread的区别
查看>>
kbengine里如何使用git快速下载项目?
查看>>
ubuntu18.04下安装oh-my-zsh
查看>>
C# Winform下一个热插拔的MIS/MRP/ERP框架15(窗体基类场景1)
查看>>
图片转换成base64_encode的链接代码示例
查看>>
如何制作软件发布cab包
查看>>
Vue电商后台管理系统项目第2天-首页添加表格动态渲染数据&分页
查看>>
eclipse3.2.1+PyDev开发python的中文问题
查看>>
使用JDK自带的工具将中文转换为ascii码
查看>>
App版本号定义与说明基础知识
查看>>
angular.js和ionic框架搭建一个webApp
查看>>