There is the following template function:
template<class func, class ...Args> auto func_wrapper_to_bool(func &&_Fn, Args &&... args) { if constexpr (std::is_member_function_pointer<func>::value) return func_wrapper_to_bool(std::mem_fn(std::forward<func>(_Fn)), std::forward<Args>(args)...); else { if constexpr (std::is_same<decltype(_Fn(std::forward<Args>(args)...)), bool>::value) return [&]()->bool {return _Fn(std::forward<Args>(args)...); }; else return [&]()->bool {_Fn(std::forward<Args>(args)...); return true; }; } } In my code, it is required to wrap any function that returns a non-bool function that returns a bool
I have a class
class Test { public: void switcher(int i) { std::cout << i << std::endl; std::cout << "Cool!!!" << std::endl; } }; In the main function, I call the function as follows:
int main() { Test ts; auto mem_fn = func_wrapper_to_bool(std::mem_fn(&Test::switcher), ts, 1); mem_fn(); auto not_mem_fn = func_wrapper_to_bool(&Test::switcher,ts,2); not_mem_fn(); } When compiling, the release version of the program works fine, and when compiling, the debug version crashes when the operator is called () with not_mem_fn. What can it be connected with?