I don't think this is possible based on what I've read however I'm hoping someone here may know of some solution that would get this to work.

I have a vector (maths) class for C++

```
template <typename T, size_t N> class vec;

```

And want to create a varadic `friend` function apply to apply a function to these vectors element-wise

i.e.

```
template <typename F, typename ...Args> friend vec<typename std::result_of<pow(Args&&...)>::type, N> apply(F&& f, const vec<Args, N>&... args);

```

which is valid (untested yet)

however I want to achieve a pattern like

```
template <typename F> friend vec<typename std::result_of<F&&(T&&)>::type, N> apply(F&& f, const vec<T, N>& V);
template <typename F> friend vec<typename std::result_of<F&&(T&&, T&&)>::type, N> apply(F&& f, const vec<T, N>& V1, const vec<T, N>& V2);
template <typename F> friend vec<typename std::result_of<F&&(T&&, T&&)>::type, N> apply(F&& f, const vec<T, N>& V1, const T& V2);
template <typename F> friend vec<typename std::result_of<F&&(T&&, T&&)>::type, N> apply(F&& f, const T& V1, const vec<T, N>& V2);
template <typename F, typename U> friend vec<typename std::result_of<F&&(T&&, U&&)>::type, N> apply(F&& f, const vec<T, N>& V1, const vec<U, N>& V2);
template <typename F, typename U> friend vec<typename std::result_of<F&&(T&&, U&&)>::type, N> apply(F&& f, const vec<T, N>& V1, const U& V2);
template <typename F, typename U> friend vec<typename std::result_of<F&&(U&&, T&&)>::type, N> apply(F&& f, const vec<U, N>& V1, const vec<T, N>& V2);
template <typename F, typename U> friend vec<typename std::result_of<F&&(U&&, T&&)>::type, N> apply(F&& f, const U& V1, const vec<T, N>& V2);

```

note that only one of the arguments is required to be a vector any scalars would be broadcasted to the length of the vector.

The idea is that `apply(pow, /*vec<float,N>*/V, /*int*/n) -> {pow(V.v[i],n)...}` where `i -> 0 ... N` rather than `apply(pow, /*vec<float,N>*/V, /*int*/n) -> apply(pow, /*vec<float,N>*/V, /*vec<int,N>*/tmp{/*int*/n}) {pow(V.v[i],tmp.v[i])...}`

So I would like to be able to write something like the following (which isn't valid C++, but it should give an idea of what I want to achieve)

```
template <typename F, typename ...Args> friend vec<typename std::result_of<pow(Args&&...)>::type, N> apply(F&& f, const vec<Args, N>&||scalar<Args>::type... args) {
    vec<typename std::result_of<pow(Args&&...)>::type, N> r;
    for (int i= 0; i < N; i++) { r = f((is_vec<Args>?args.v[i]:args)...); }
    return r;
}

```

EDIT:

Based on Frank's comments I'm looking for something along the lines of

```
template<typename F, typename ...Args, size_t N>
vec<typename std::enable_if<sum<is_vec<Args,N>...>::value > 0, std::result_of<F&&(base_type<Args>::type&&...)>::type>::type, N>
(F&& f, Args&&...args) {
    vec<typename std::result_of<F&&(base_type<Args>::type&&...)>::type, N> result;
    for(std::size_t i = 0 ; i < N ; ++i) { result.v[i] = f(extract_v(std::forward<Args>(args),i)...); }
    return result;
}

```

however I'm unsure if this version could even compile as it may be too ambiguous to be able to detriment the value of `N`.