当前位置:网站首页>d为何用模板参数
d为何用模板参数
2022-08-10 13:25:00 【fqbqrr】
pure @nogc @safe BigInt opAssign(T : BigInt)(T x);
//上下有何差别?
pure @nogc @safe BigInt opAssign(BigInt x);
是的,这种语法允许任何隐式转换为BigInt
;例如:
import std.bigint;
void fun(T : BigInt)(T t)
{
pragma(msg,"用T=`"~T.stringof~"`实例化");
}
struct S
{
BigInt n;
alias n this;
}
void main()
{
S s;
fun(s); // 用T = `S`实例化
}
目前无法编写需要精确类型
且无隐式转换
的模板特化.为此,必须改用模板约束
:
void fun(T)(T t)
if (is(T == BigInt))
{
// ...
}
或者是如果用两种不同类型和隐式转换
来调用它,会得到两个不同
的模板实例?
边栏推荐
- shell:正则表达式及三剑客grep命令
- Wirshark common operations and tcp three-way handshake process example analysis
- Jiugongge lottery animation
- 递归递推之Fighting_小银考呀考不过四级
- Matlab画分段函数「建议收藏」
- Existing in the rain of PFAS chemical poses a threat to the safety of drinking water
- 2022年五大云虚拟化趋势
- BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection Paper Notes
- WebView的优化与常见问题解决方案
- Efficient and Robust 2D-to-BEV Representation Learning via Geometry-guided Kernel Transformer 论文笔记
猜你喜欢
系统的安全和应用(不会点安全的东西你怎么睡得着?)
2022 Recruitment Notice for Academician Zhao Guoping Group of Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences
发送post请求前台无法获取数据
C#实现访问OPC UA服务器
代码随想录笔记_动态规划_70爬楼梯
进程和计划任务管理
广东10个项目入选工信部2021年物联网示范项目名单
网络安全——XSS之被我们忽视的Cookie
什么?你还不会JVM调优?
ABAP 里文件操作涉及到中文字符集的问题和解决方案试读版
随机推荐
Matlab画分段函数「建议收藏」
C#中导入其它自定义的命名空间
WebView的优化与常见问题解决方案
ICML 2022 | 基于随机注意力机制的可解释可泛化图学习
递归递推之递归的函数
ABAP 里文件操作涉及到中文字符集的问题和解决方案试读版
AWS 安全基础知识
【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
Keithley DMM7510 accurate measurement of ultra-low power consumption equipment all kinds of operation mode power consumption
矩阵键盘&基于51(UcosII)计算器小项目
SenseTime self-developed robotic arm, the first product is an AI chess-playing robot: Guo Jingjing is also invited as an endorsement
Stream通过findFirst()查找满足条件的一条数据
Interface Automation Testing Basics
Drive IT Modernization with Low Code
tampercfg内核模块导致机器频繁crash
LeetCode·297.二叉树的序列化与反序列化·DFS·BFS
vivado闪退或者message无显示
Have you guys encountered this problem?MySQL 2.2 and 2.3-SNAPSHOT are like this, it seems to be
指针(C语言初解)
Error: Rule can only have one resource source (provided resource and test + include + exclude)