I was wondering whether there was a method built into phobos for expanding the "isImplictlyConvertible" template to work for variadic templates.

To explain what I mean by this, normally "isImplicitlyConvertible(To, From)" checks whether or not a type "From" may implicitly be converted to a type "To".

struct Foo(V)
{
    this(V)(V value) if (isImplictlyConvertible!(V, T))
    {
        // do stuff
    }
}

When "From" is variadic, I would like it for each type in "From" to be checked whether it may implicitly be converted to type "To".

struct Foo(V)
{
    this(Vs...)(Vs values) if (eachIsImplictlyConvertible!(T, Vs))
    {
        // do stuff
    }
}

This can be accomplished off the top of my head by taking the code from std.traits for "isImplicitlyConvertible" and making the following change.

template eachIsImplictlyConvertible(To, From...)
{
    enum bool eachIsImplictlyConvertible = is(typeof({
        void fun(ref From vs)
        {
            void gun(To) {}
            foreach (v; vs) // +
            {
                gun(v);
            }
        }
    }));
}

Implementing this means I have an ostensibly valid method of accomplishing what I desire. Though, I am curious whether there's a way to facilitate this that is currently available in phobos, without having to implement another traits function.

Thanks,
rpeio




Reply via email to