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

生成树协议STP(Spanning Tree Protocol)

Reversing words in a string in LeetCode
![[Study Notes] Persistence of Redis](/img/e4/d3c09754ca5ac4fdad2653ccca6d82.png)
[Study Notes] Persistence of Redis
![[JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification](/img/3e/14a1d7c2837c896eaa0ca625eaa040.png)
[JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification

C#实现访问OPC UA服务器

Code Casual Recording Notes_Dynamic Programming_70 Climbing Stairs

AWS 安全基础知识

接口自动化测试基础篇

【量化交易行情不够快?】一文搞定通过Win10 wsl2 +Ubuntu+redis+pickle实现股票行情极速读写

Matrix Keyboard & Calculator Small Project Based on 51 (UcosII)
随机推荐
机器学习实战(2)——端到端的机器学习项目
R语言使用gt包和gtExtras包优雅地、漂亮地显示表格数据:gtExtras包的gt_highlight_rows函数高亮(highlight)表格中特定的数据行、配置高亮行的特定数据列数据加粗
数据产品经理那点事儿 一
OTA自动化测试解决方案---整体方案介绍
CodeForces - 834C
第三方软件测评有什么作用?权威软件检测机构推荐
日志@Slf4j介绍使用及配置等级
I would like to ask the big guys, how to solve this error when cdc oracle initializes a 3 million table task running
【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
发送post请求前台无法获取数据
开源SPL消灭数以万计的数据库中间表
【学习笔记】Redis的持久化
[JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification
Drive IT Modernization with Low Code
商汤自研机械臂,首款产品是AI下棋机器人:还请郭晶晶作代言
2022 Recruitment Notice for Academician Zhao Guoping Group of Shenzhen Institute of Advanced Technology, Chinese Academy of Sciences
简单的写一个防抖跟节流
Ethernet channel Ethernet channel
Matlab画分段函数「建议收藏」
神了!阿里数据库专家纯手写了这份604页的Oracle+MySQL攻坚指南