Modified std :: invoke / std :: apply, using called as emptiness * - maybe?

In C ++ 17 we have std::invoke:

template<class F, class... ArgTypes>
std::result_of_t<F&&(ArgTypes&&...)> invoke(F&& f, ArgTypes&&... args);

(and in C ++ 11 it was already std::experimental::applysimilar, but with a tuple). Now I want to implement:

template<typename T, typename... ArgTypes>
T invoke(void* f, ArgTypes&&... args);

The difference from std::invokethat is that f is passed through the void pointer and without a template parameter for its type. However, a type can be inferred by a human reader, provided that it fis a pointer to a regular autonomous function, and I can do this:

template<typename T, typename... ArgTypes>
T my_invoke(void* f, ArgTypes&&... args)
{
        using type_unerased_function = T (*)(ArgTypes...);
        return reinterpret_cast<type_unerased_function>(f)(args...);
}

which seems to work. However, it std::invokesupports member functions, objects with, operator()and possibly other creatures (and std::applysupports more than simple function pointers). Is it possible to continue the expansion to support most / everything that does std::invoked?

:

  • constexpr , . - constexpr , .
  • , /& & .
+4
1

, , , - ( C-style).

, .

void f(short);

0, 0 int&&, void void(*)(int). .

, int zero=0;, zero , void void(*)(int&). (go go undefined), segfault (, , , ).

, , . , , .

. . - , , void*, , .


. , . , , , .

, .

, , arg1, arg2, arg3. :

std::function<void(arg1, arg2, arg3)>

, :

std::function<void(arg1,arg2,arg3)> f = my_invokable;

std::function std::invoke , () - ( this).


, . , - , : " , ", - . , , , .

, , , .

+3

All Articles