D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17815 - Allow casting of AliasSeq
Summary: Allow casting of AliasSeq
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-07 13:50 UTC by Simen Kjaeraas
Modified: 2024-12-13 18:54 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Simen Kjaeraas 2017-09-07 13:50:43 UTC
The following code does not currently compile:

    import std.meta : AliasSeq;
    AliasSeq!(int, float) a;
    auto b = cast(AliasSeq!(byte, byte))a;

Casting a set of values to a set of types is something that comes up every now and then. It can currently be done using a variation of this function:

    template castTuple(T...) {
        auto castTuple(Args...)(Args args) if (Args.length == T.length) {
            static if (T.length == 0) {
                return tuple();
            } else {
                auto result = .castTuple!(T[1..$])(args[1..$]);
                return tuple(cast(T[0])args[0], result.expand);
            }
        }
    }

The compiler however, has all the necessary information to make the first example compile.
Comment 1 dlangBugzillaToGithub 2024-12-13 18:54:27 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19314

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB