I am creating wrapper functions, that modify existing functions (targets). The targets are determined at runtime as pointers without type information (
Код: Выделить всё
void*
The basic scheme is like this:
Код: Выделить всё
bool wrap(void* f, void** t) { *t = magic(); // target determined at runtime as void* return true; } // define new wrapping function and storage for target int(*foo_target)(int); int foo(int data) { return foo_target(data) + 10; } auto res = wrap(reinterpret_cast(&foo), reinterpret_cast(&foo_target));
Код: Выделить всё
wrap
Код: Выделить всё
foo
Код: Выделить всё
foo_target
This works, but requires ugly type casts and I have to keep the signatures of
Код: Выделить всё
foo_target
Код: Выделить всё
foo
Код: Выделить всё
template struct wrap { F* target; wrap(F&& f) { target = reinterpret_cast(magic()); } }; static auto foo = wrap( [](int data) -> int // int //
Источник: [url]https://stackoverflow.com/questions/78128208/workaround-for-use-of-variable-before-deduction-of-auto[/url]