| |
| Posted by H. S. Teoh in reply to ryuukk_ | PermalinkReply |
|
H. S. Teoh
Posted in reply to ryuukk_
| On Tue, Apr 26, 2022 at 04:04:25PM +0000, ryuukk_ via Digitalmars-d wrote: [...]
> My wishlist:
[...]
> - builtin tagged union
There's already std.variant.Variant, and one or two dub packages that do similar things.
> - builtin multiple return type
std.typecons.Tuple does an OK job of it (just return `Tuple!(int,
string)`, for example). It's also pretty easy to write your own
template for doing this in just a few of lines of code:
struct MultiRet(T...) {
T values;
alias values this;
}
auto multiRet(T...)(T values) {
return MultiRet!T(values);
}
auto myFunc() {
return multiRet(10, "string", 3.14159);
static assert(is(typeof(return) == MultiRet!(int,
string, double)));
}
auto values = myFunc();
assert(values[0] == 10);
assert(values[1] == "string");
assert(values[2] == 3.14159);
T
--
He who sacrifices functionality for ease of use, loses both and deserves neither. -- Slashdotter
|