V!T v(T)(T[] values...) { return V!T(values); }
struct V(T)
{
private T[] values;
alias values this;
this(T[] values...) { this.values = values; }
typeof(mixin("T.init ", op, " typeof(S.init[0]).init"))[] opBinary(string op, S)(return scope S rhs) return
in (rhs.length == values.length)
{
auto result = new typeof(return)(values.length);
foreach (i, ref x; result)
{
x = mixin("values[i] ", op, " rhs[i]");
}
return result;
}
typeof(mixin("typeof(S.init[0]).init ", op, " T.init"))[] opBinaryRight(string op, S)(return scope S lhs) return
if (!is(S : V!X, X))
in (lhs.length == values.length)
{
auto result = new typeof(return)(values.length);
foreach (i, ref x; result)
{
x = mixin("lhs[i] ", op, " values[i]");
}
return result;
}
}
@safe unittest
{
auto a = [1,2,3].v + [4,5,6];
static assert(is(typeof(a) == int[]));
assert(a == [5,7,9]);
enum as = ["a": 1, "b": 3];
enum bs = ["a": 3, "c": 2];
auto ps = ["a", "b"].v in [ as, bs ];
static assert(is(typeof(ps) == int*[]));
assert(ps.length == 2);
assert(ps[0] !is null && *ps[0] == 1);
assert(ps[1] is null);
auto b = ['a', 'B', '3'] ~ ["bc", "CDE", "4567"].v;
static assert(is(typeof(b) == string[]));
assert(b == ["abc", "BCDE", "34568" ]);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现