d标准库与自写函数冲突
module testcmpmodule;
//公共导入
public import std.algorithm, std.math, std.stdio;
import std.range, std.traits;
//函数重载组.
public import std.algorithm : cmp;
public import std.math : cmp;
auto cmp(A, B)(in A a, in B b)
if(!(isInputRange!A && isInputRange!B) //排除 std.algorithm.cmp
&& !(isFloatingPoint!A && isFloatingPoint!B)) //排除 std.math.cmp
{
return a==b ? 0 : a<b ? -1 : 1; //保底方式
}
//发布实用程序模块的另一个模块:
module testcmpmodule2;
public import std.algorithm, testcmpmodule, std.stdio;
//这里删除std.algorithm,就可以了.
void w(A...)(in A a){ writeln(a); }
//主要模块:
import testcmpmodule2;
void main(){
w(cmp(.1, .2)); //std.math.cmp
w(cmp("a", "b")); //std.algorithm.cmp
//<- 这里出错了
w(cmp(1, 2)); //my cmp
}
std.string
也会公开导入std.algorithm.cmp
.
//其他模块,只能看见该标模块.
public import std.string, std.uni, std.algorithm, std.math;
import std.range, std.traits;
//重载组
public import std.algorithm : cmp;
public import std.math : cmp;
...
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现