fork download
  1. // error handling could be improved too
  2.  
  3. template <typename T>
  4. using ToPointer = typename std::add_pointer<typename std::remove_reference<Fun>::type>::type;
  5.  
  6. template <typename Fun>
  7. BOOL CALLBACK AdaptEnumWindowsProc(HWND hwnd, LPARAM lParam) {
  8. Fun& fun = *reinterpret_cast<ToPointer<Fun>>(lparam); // what's the correct cast?
  9. return fun(hwnd);
  10. }
  11.  
  12. template <typename Fun>
  13. BOOL BetterEnumWindows(Fun&& fun) {
  14. return ::EnumWindows(&AdaptEnumWindowsProc<Fun>, reinterpret_cast<LPARAM>(&fun));
  15. }
  16.  
  17.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty