lambda_cast.h 651 B

12345678910111213141516171819202122232425262728
  1. //
  2. // lambda_cast.h
  3. // tax-calculator
  4. //
  5. // Created by Sam Jaffe on 10/8/20.
  6. //
  7. // Credit given to Nikos Athanasiou for this solution to the
  8. // problem of getting the argument types of a lambda.
  9. // https://stackoverflow.com/questions/13358672/
  10. //
  11. #pragma once
  12. #include <functional>
  13. namespace lambdas {
  14. template <typename T> struct memfun_type { using type = void; };
  15. template <typename Ret, typename Class, typename... Args>
  16. struct memfun_type<Ret (Class::*)(Args...) const> {
  17. using type = std::function<Ret(Args...)>;
  18. };
  19. template <typename F>
  20. typename memfun_type<decltype(&F::operator())>::type FFL(F const & func) {
  21. return func;
  22. }
  23. }