当前位置:网站首页>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))
{
// ...
}
或者是如果用两种不同类型和隐式转换来调用它,会得到两个不同的模板实例?
边栏推荐
猜你喜欢

【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解

2022-08-09: What does the following go code output?A: No, it will panic; B: Yes, it can run correctly; C: Not sure, see the voting result.package main import (“fmt“ “syn

矩阵键盘&基于51(UcosII)计算器小项目

广东10个项目入选工信部2021年物联网示范项目名单

Code Casual Recording Notes_Dynamic Programming_70 Climbing Stairs

记录几道整型提升的题目

高数_证明_弧微分公式

Jiugongge lottery animation
![[target detection] small script: extract training set images and labels and update the index](/img/9d/0f88b484cee1b85df6bc1153d9b6b4.png)
[target detection] small script: extract training set images and labels and update the index

八大排序总是忘?快来这里~
随机推荐
大佬们有遇到过这个问题吗? MySQL 2.2 和 2.3-SNAPSHOT 都这样,貌似是
日志@Slf4j介绍使用及配置等级
PHP 判断文件是否有内容,没有内容则复制另一个文件写入
【学习笔记】Redis的持久化
汉字检测和关键词检测
借数据智能,亚马逊云科技助力企业打造品牌内生增长力
Reversing words in a string in LeetCode
友邦人寿可观测体系设计与落地
指针(C语言初解)
3DS MAX batch export file script MAXScript with interface
Blast!ByteDance successfully landed, only because the interview questions of LeetCode algorithm were exhausted
ABAP 里文件操作涉及到中文字符集的问题和解决方案试读版
SecureCRTPortable – 破解
Redis上云迁移实践
Shell:数组
shell:正则表达式及三剑客grep命令
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
CodeForces - 834C
学习日记9
网络安全——XSS之被我们忽视的Cookie