将一个函数中的可变参数传递给D中的另一个函数 [英] Passing variadic arguments in one function to another function in D

查看:76
本文介绍了将一个函数中的可变参数传递给D中的另一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可变的D样式函数 foo(format,...),它是对 writefln 。我想做这样的事情:

I have a variadic D-style function foo(format, ...), which is a wrapper around writefln. I'd like to do something like this:

foo(format, <...>) {
    //...
    writefln(format, ...);
}

本质上,将省略号参数传递给writefln。我知道在C / C ++中这不容易/不可能,但是有没有办法在D中完成呢?

Essentially, passing on the ellipsis parameter(s) to writefln. I understand that this isn't easy/possible in C/C++, but is there a way to accomplish this in D?

推荐答案

import std.stdio;
void customWrite(Args...)(string format, Args args)
{
    writefln(format, args);
}

这篇关于将一个函数中的可变参数传递给D中的另一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆