当前位置:网站首页>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))
{
// ...
}
或者是如果用两种不同类型和隐式转换来调用它,会得到两个不同的模板实例?
边栏推荐
- Cloud Migration Practice of Redis
- PHP 判断文件是否有内容,没有内容则复制另一个文件写入
- 机器学习实战(2)——端到端的机器学习项目
- MySQL interview questions
- mSystems | Zhongnong Wang Jie Group Reveals the Mechanisms Affecting Soil "Plastic Interstitial" Microbial Communities
- shell:常用小工具(sort、uniq、tr、cut)
- shell:正则表达式及三剑客grep命令
- Fragment's show and hide
- the height of the landscape
- malloc 函数详解
猜你喜欢

Efficient and Robust 2D-to-BEV Representation Learning via Geometry-guided Kernel Transformer 论文笔记

进程和计划任务管理

Short read or OOM loading DB. Unrecoverable error, aborting now

M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation

Error: Rule can only have one resource source (provided resource and test + include + exclude)

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

Reversing words in a string in LeetCode

鸿蒙开发从hello world开始

3DS MAX 批量导出文件脚本 MAXScript 带界面

shell:常用小工具(sort、uniq、tr、cut)
随机推荐
CodeForces - 811A
Detailed explanation of es6-promise object
Jiugongge lottery animation
Ethernet channel 以太信道
Codeforces Round #276 (Div. 1) B. Maximum Value
简单的写一个防抖跟节流
Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
2022年五大云虚拟化趋势
记录几道整型提升的题目
ArcMAP has a problem of -15 and cannot be accessed [Provide your license server administrator with the following information:Err-15]
tampercfg内核模块导致机器频繁crash
AWS 安全基础知识
神了!阿里数据库专家纯手写了这份604页的Oracle+MySQL攻坚指南
【POI 2008, BLO】Cut Point
A can make large data clustering method of 2000 times faster, don't poke
Open Office XML 格式里如何描述多段具有不同字体设置的段落
ABAP 里文件操作涉及到中文字符集的问题和解决方案试读版
借数据智能,亚马逊云科技助力企业打造品牌内生增长力
【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
BEVDet4D: Exploit Temporal Cues in Multi-camera 3D Object Detection Paper Notes