d返回多个常量值

原文
想要这样:

bool func (const out Key k, const out Val v) { k = this.key.dup; v = this.val.dup; return true;    }

你可以这样:

import std.typecons;

auto func(Key, Value)(Key k, Value v)
{
    return Tuple!(const(Key), const(Value))(k, v);
}

void main()
{
    string k;
    uint v;
    auto result = func(k, v);

    static assert(is(typeof(result[0]) == const(string)));
    static assert(is(typeof(result[1]) == const(uint)));
}
posted @ 2023-01-03 14:59  zjh6  阅读(37)  评论(0)    收藏  举报  来源