当前位置:网站首页>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))
{
// ...
}
或者是如果用两种不同类型和隐式转换
来调用它,会得到两个不同
的模板实例?
边栏推荐
- MySQL面试题整理
- YTU 2295: KMP模式匹配 一(串)
- 【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
- YTU 2295: KMP pattern match one (string)
- C#实现访问OPC UA服务器
- Basic knowledge of switches
- 生成树协议STP(Spanning Tree Protocol)
- Jiugongge lottery animation
- ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
- Existing in the rain of PFAS chemical poses a threat to the safety of drinking water
猜你喜欢
Stream通过findFirst()查找满足条件的一条数据
友邦人寿可观测体系设计与落地
Efficient and Robust 2D-to-BEV Representation Learning via Geometry-guided Kernel Transformer 论文笔记
Basic knowledge of switches
Open source SPL wipes out tens of thousands of database intermediate tables
机器学习实战(2)——端到端的机器学习项目
SenseTime self-developed robotic arm, the first product is an AI chess-playing robot: Guo Jingjing is also invited as an endorsement
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
AWS Security Fundamentals
重要通知 | “移动云杯”算力网络应用创新大赛初赛延期!!
随机推荐
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
数据产品经理那点事儿 二
Fragment-hide和show
[219] The training course notes of the go engineer with more than 3,000 MOOCs 02 Programming ideas in the go language
LeetCode·每日一题·640.求解方程·模拟构造
系统的安全和应用(不会点安全的东西你怎么睡得着?)
M²BEV: Multi-Camera Joint 3D Detection and Segmentation with Unified Bird’s-Eye View Representation
大佬们有遇到过这个问题吗? MySQL 2.2 和 2.3-SNAPSHOT 都这样,貌似是
需要被记录的OpenStack相关的命令_自己用
浙大、阿里提出DictBERT,字典描述知识增强的预训练语言模型
【MinIO】工具类使用
鸿蒙开发从hello world开始
一种能让大型数据聚类快2000倍的方法,真不戳
CodeForces-834C
I would like to ask the big guys, how to solve this error when cdc oracle initializes a 3 million table task running
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
递归递推之递归的函数
Stream通过findFirst()查找满足条件的一条数据
the height of the landscape
Blast!ByteDance successfully landed, only because the interview questions of LeetCode algorithm were exhausted