Insane template metaprogramming madness Given any callable, deduces the first parameter in the parameter list of the function. Be ware, not for light hearted.

template &lt;typename ... Args&gt;
struct pick_first;

template &lt;typename T, typename ... Args&gt;
struct pick_first&lt;T, Args ...&gt;
{
    using type = T;
};

template &lt;typename ... Args&gt;
using pick_first_t = typename pick_first&lt;Args...&gt;::type;

template &lt;typename Callable&gt;
struct deduce_first_parameter
{
private:
    template &lt;typename Func, template &lt;typename ...&gt; typename Operation&gt;
    struct extract_function;

    template &lt;typename R, typename ... Args, template &lt;typename ...&gt; typename Operation&gt;
    struct extract_function&lt;R(Args...), Operation&gt;
    {
        using type = typename Operation&lt;Args...&gt;::type;
    };

    template &lt;typename C, typename R, typename ... Args, template &lt;typename ...&gt; typename Operation&gt;
    struct extract_function&lt;R (C::*)(Args...), Operation&gt;
    {
        using type = typename Operation&lt;Args...&gt;::type;
    };

    template &lt;typename Func, template &lt;typename ...&gt; typename Operation&gt;
    using extract_function_t = typename extract_function&lt;Func, Operation&gt;::type;

public:
    using type = extract_function_t&lt;decltype(&amp;Callable::operator()), pick_first&gt;;
};

template &lt;typename R, typename ... InputArgs&gt;
struct deduce_first_parameter&lt;R(InputArgs...)&gt;
{
    using type = pick_first_t&lt;InputArgs...&gt;;
};


Some tests:

#include &lt;vector&gt;
#include &lt;map&gt;

struct dummy
{
    void operator()(std::vector&lt;int&gt;&amp;) {}
    using correct_answer = std::vector&lt;int&gt;&amp;;
};

struct not_so_dummy
{
    using correct_answer = const std::vector&lt;std::map&lt;int, char&gt;&gt;&amp;;
    void operator()(const std::vector&lt;std::map&lt;int, char&gt;&gt;&amp;) {}

};

void f(char, int);

int main()
{
    static_assert(std::is_same&lt;deduce_first_parameter&lt;decltype(f)&gt;::type, char&gt;::value);
    static_assert(std::is_same&lt;deduce_first_parameter&lt;dummy&gt;::type, dummy::correct_answer &gt;::value);
    static_assert(std::is_same&lt;deduce_first_parameter&lt;not_so_dummy&gt;::type, not_so_dummy::correct_answer&gt;::value);
}


After about two weeks of intense Java, I started missing C++. Especially templates.

Motivation:

I'm writing generic sliding window, which is complete, but I don't want to show it yet (I figured that it is possible to do stunning things with it). To supplement it, I need preprocessing iterator, which applies a user supplied functor before assigning to underlying iterator. To make the preprocessing iterator easy to use I need to deduce the first parameter's type to put into std::iterator&lt;&gt; (I know its deprecated, but some compilers still use it to detect iterators), because binding users to what underlying iterator can accept is awkward.

How to compile:

I'm afraid not that many compilers can handle this. I've tested it on clang++-3.9. There might be some warnings, they should be due to using C++17 feature to make template template parameters declared by typename possible (good luck on understanding this sentence).

I'm interested in any critique, but especially about reducing instantiation depth and count. Also fitting statements in one readable line would be great.
You can figure out the first parameter of a non-overloaded function pointer pretty easily; I'm not sure but your code looks more complicated than it ought to be.

Unfortunately, your code completely falls down in the presence of overloads and/or templates. Here's the error message:

prog.cc:36:46: error: reference to overloaded function could not be resolved; did you mean to call it?
    using type = extract_function_t&lt;decltype(&amp;Callable::operator()), pick_first&gt;;
                                             ^~~~~~~~~~~~~~~~~~~~~


and here are some types that trigger it:

struct oops1 {
    void operator()(int);
    void operator()(double);
};

struct oops2 {
    void operator()(int);
    void operator()(int) const;
};

void oops3(int);
void oops3(double);

struct oops4
{
    using correct_answer = const std::vector&lt;std::map&lt;int, char&gt;&gt;&amp;;
    template&lt;class T, std::enable_if_t&lt;std::is_same_v&lt;T, const std::vector&lt;std::map&lt;int, char&gt;&gt;&gt;, int&gt; = 0&gt;
        void operator()(T&amp;) {}
};


And here's another error message that I get:

prog.cc:11:1: error: implicit instantiation of undefined template 'pick_first&lt;&gt;'
using pick_first_t = typename pick_first&lt;Args...&gt;::type;
^


with this input:

void oops5(void);




If I were tackling this problem, I would first ask myself what "the type of the first parameter" even means in C++, given that we have function overloading and templates. But then I might try to detect the appropriate type by messing around with

struct ConvertibleToAnything {
    template&lt;class T&gt; operator T() const;
};


and then inspecting f(ConvertibleToAnything{}) and trying to figure out which operator T was getting instantiated.

In the cases where overloading and/or templates rendered the question meaningless, I would try to at least give a nice static_assert error message, if not actually produce a tag type so that is_same_v&lt;deduce_first_parameter_t&lt;oops1&gt;, signature_is_ambiguous_t&gt;.