import std.stdio; import std.functional:compose;

int add(int a, int b) { return a + b; } int square(int a) { return a * a; }

void main() { auto composedFunc = compose!add(square)(2); writeln(composedFunc(3)); // 输出:11 }

// 更改了第9行的compose调用方式,将square和add作为模板参数传递,并在括号中传递了2作为add函数的第一个参数。

dlang语言dmd2103版本编译器编译以下代码提示四个错误:f_std_functional包主要用法d9 Error function f_std_functional包主要用法squareint a is not callable using argument types f_std_functional包主要用法d9 too few arguments expected 1

原文地址: https://www.cveoy.top/t/topic/e81d 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录