当前位置:网站首页>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))
{
// ...
}
或者是如果用两种不同类型和隐式转换来调用它,会得到两个不同的模板实例?
边栏推荐
- 锂电池技术
- NAACL 2022 | 简单且高效!随机中间层映射指导的知识蒸馏方法
- 领域驱动实践总结(基本理论总结与分析V+架构分析与代码设计+具体应用设计分析)
- How to describe multiple paragraphs with different font settings in Open Office XML format
- C# InitializeComponent() does not exist in the current context
- Reversing words in a string in LeetCode
- C# 当前上下文中不存在InitializeComponent()
- Jiugongge lottery animation
- Wirshark common operations and tcp three-way handshake process example analysis
- Network Saboteur
猜你喜欢

系统架构系列文章三--解决传统企业核心系统的性能问题

Error: Rule can only have one resource source (provided resource and test + include + exclude)
![[Study Notes] Persistence of Redis](/img/e4/d3c09754ca5ac4fdad2653ccca6d82.png)
[Study Notes] Persistence of Redis

DNS欺骗-教程详解

开源SPL消灭数以万计的数据库中间表

商汤自研机械臂,首款产品是AI下棋机器人:还请郭晶晶作代言

2022年五大云虚拟化趋势

【学习笔记】Redis的持久化

ABAP 里文件操作涉及到中文字符集的问题和解决方案试读版

Error: Rule can only have one resource source (provided resource and test + include + exclude)
随机推荐
【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
Network Saboteur
一汽奥迪:持续34年聚焦品质与体验 立足市场需求推进产品迭代
网络安全——XSS之被我们忽视的Cookie
系统架构系列文章三--解决传统企业核心系统的性能问题
Fragment's show and hide
【目标检测】小脚本:提取训练集图片与标签并更新索引
Stream通过findFirst()查找满足条件的一条数据
借数据智能,亚马逊云科技助力企业打造品牌内生增长力
Basic knowledge of switches
学习日记8
the height of the landscape
第三方软件测评有什么作用?权威软件检测机构推荐
数据产品经理那点事儿 一
交换机的基础知识
递归递推之计算组合数
【量化交易行情不够快?】一文搞定通过Win10 wsl2 +Ubuntu+redis+pickle实现股票行情极速读写
C#报错 The ‘xmins‘ attribute is not supported in this context
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
Redis 定长队列的探索和实践