1
#include <iostream>
#include <string>

struct foo
{
    void operator()( const int&  ) { }
    void operator()( const float& ) { }
    void operator()( const std::string& ) { }
};


template<typename... Types>
void bar_recursive()
{
    std::cout << "Iterating over overloads";
}

template<typename Fn>
void bar( Fn&& fn )
{
    // Somehow i want to take first argument types of callable operators and pass them to bar_recursive function
    bar_recursive< FirstArgumentTypesOfOverloadedCallableOperators... >(  );
}

int main(int argc, char *argv[])
{

    // I want bar() function to call bar_recursive< int , float , std::string >()
    bar( foo {} );

    return 0;
}

Those overloaded function call operators don't have arbitrary number of arguments. They all will have exactly one parameter.

Is it possible to deduce those types ?

calynr
  • 1,264
  • 1
  • 11
  • 23
  • 1
    "Is it possible to deduce those types ?" - No, as far I know. – max66 Nov 23 '19 at 19:39
  • I don't think it is even possible to determine the number of overloads (beyond 1 vs 2+) – walnut Nov 23 '19 at 19:40
  • 1
    If it were possible, what would have determined the order of these types? – Evg Nov 23 '19 at 21:15
  • it is not important the order for my case and yes there are lots of questions makes us think :) – calynr Nov 23 '19 at 22:57
  • Nearly certain there's no way to do this in C++17 or C++20. You would need some sort of "reflection" feature. – aschepler Nov 23 '19 at 23:52
  • it seems so, it is possible to take parameter type when there is one call operator but mb this problem will be solved when we have static reflection as you have said – calynr Nov 23 '19 at 23:59

0 Answers0